Skip to end of metadata
Go to start of metadata

Use a JUnit rule.

Note that this code assumes your WebDriver can take a screenshot, which isn't true of all implementations...

Labels:
  1. Jan 04, 2012

    Anonymous

    Thanks for sharing. Since I am setting driver in setUp() method, I have an empty constructor and added:

    public void setBrowser(WebDriver driver) {
            this.driver = driver; }

    In setUp():

    @Before
        public void setUp() throws Exception {
            driver = Utils.initTestAndBrowser();
            takeScreenshot.setBrowser(driver);
        }
    1. Jan 04, 2012

      Glad to be of use.

      It looks like you are statically setting up test data and other state (including the webdriver instance) - in general its best to avoid all static state in tests, as you can lose track of what state gets created where, and so your test can end up being very non-obvious in the state it actually needs.

      Additionally, i would always suggest to to not have no-arg constructors for classes, as this can mean that your objects are set up in an inconsistent (or not ready to work) state. Imagine -  if you forgot to call the setter, then later on your class would fail with an NPE, and it wouldn't be obvious where the bug was. (It could be you didn't call the setter, that you called it with null, or you called it multiple times, and the last time was null)In this case if you had an empty constructor, then you would need to add two setters....and then have two methods you need to call all the time.

      Unfortunately, spring encourages this and so lots of people have got into the habit.

      Although a webdriver is something that you don't want to create and destroy for every test, you might find it useful to hide this behind some other abstraction.

      James

       

      1. Feb 09, 2012

        Anonymous

        yHTu0G , [url=http://gxfeqcwnhwgc.com/]gxfeqcwnhwgc[/url], [link=http://xtykeoqdhqgt.com/]xtykeoqdhqgt[/link], http://louuxuylgbrm.com/
      2. Feb 09, 2012

        Anonymous

        bGIIKw , [url=http://mokhnrfvbfqk.com/]mokhnrfvbfqk[/url], [link=http://xchwpjawluth.com/]xchwpjawluth[/link], http://zgcmmpirqihq.com/
      3. Feb 09, 2012

        Anonymous

        xTyZ6S , [url=http://exjvrasyidly.com/]exjvrasyidly[/url], [link=http://jqvbycljwbnv.com/]jqvbycljwbnv[/link], http://sslevgqwvxpw.com/
      4. Feb 10, 2012

        Anonymous

        25Yzjr , [url=http://orenlzktotxc.com/]orenlzktotxc[/url], [link=http://mnnqpimcdild.com/]mnnqpimcdild[/link], http://ngtzevcycbym.com/
    2. Feb 10, 2012

      Anonymous

  2. Feb 08, 2012

    Anonymous

  3. Feb 09, 2012

    Anonymous

    8Htqda , [url=http://gdaltoyiaguv.com/]gdaltoyiaguv[/url], [link=http://tdrtnzockwdi.com/]tdrtnzockwdi[/link], http://qzytzazqkvgy.com/
  4. Feb 09, 2012

    Anonymous

    XmxDLm , [url=http://iquqdbxpckqa.com/]iquqdbxpckqa[/url], [link=http://ukqsoiadqpzp.com/]ukqsoiadqpzp[/link], http://muunowwtzfto.com/
  5. Feb 09, 2012

    Anonymous

    q7p4me , [url=http://wymfakrtfxuc.com/]wymfakrtfxuc[/url], [link=http://txssmfihitlw.com/]txssmfihitlw[/link], http://uzwihemmxndi.com/