Após fazer as modificações para usar as notations de Before e After comecei a ter esses problemas
java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.WebDriver.findElement(org.openqa.selenium.By)" because "this.browser" is null
segue meu código dessa classe.
public class LoginTest {
private static final String URL_LOGIN = "http://localhost:8080/login";
private WebDriver browser;
@BeforeAll
public static void beforeAll() {
System.setProperty("webdriver.chrome.driver", "usr//local//bin//chromedriver");
}
@BeforeEach
public void beforeEach(){
this.browser = new ChromeDriver();
browser.navigate().to(URL_LOGIN);
}
@AfterEach
public void afterEach(){
this.browser.quit();
}
@Test
public void deveriaEfetuarLoginComDadosValidos() {
browser.findElement(By.id("username")).sendKeys("fulano");
browser.findElement(By.id("password")).sendKeys("pass");
browser.findElement(By.id("login-form")).submit();
Assert.assertFalse(browser.getCurrentUrl().equals(URL_LOGIN));
Assert.assertEquals("fulano", browser.findElement(By.id("usuario-logado")).getText());
}
@Test
public void naoDeveriaLogarComDadosInvalidos() {
browser.findElement(By.id("username")).sendKeys("invalido");
browser.findElement(By.id("password")).sendKeys("123123");
browser.findElement(By.id("login-form")).submit();
Assert.assertTrue(browser.getCurrentUrl().equals("http://localhost:8080/login?error"));
Assert.assertTrue(browser.getPageSource().contains("Usuário e senha inválidos."));
}
@Test
public void naoDeveriaAcessarPaginaRestritaSemEstarLogado() {
this.browser.navigate().to("http://localhost:8080/leiloes/2");
Assert.assertTrue(browser.getCurrentUrl().equals("http://localhost:8080/login"));
}
}