vendredi 10 mars 2017

How do I Set-up and Tear-down variables (and driver) around my JUnit tests?

I'd like to run two similar Junit/Selenium tests of this form:

@Test
public void findMyLinkTest() {
        running(testServer(1234, fakeApplication(inMemoryDatabase())), HTMLUNIT, browser -> {
            browser.goTo("http://localhost:1234");
            WebDriver driver = new ChromeDriver();
            driver.get("http://localhost:1234");
            List<WebElement> myLinks = driver.findElements(By.xpath("blahblahblah"));
            assertTrue(myLinks.size()==1);
            driver.close();
        });
}

But @Before I'd like to

  • change database variables (that feed into my application) to a test value
  • set up driver for both tests

and @After

  • reset the database variables

  • initiate driver.close()

My Before and After methods don't seem to recognise variables in other blocks (@After thinks driver was never instantiated for example).

Aucun commentaire:

Enregistrer un commentaire