Olá,
O test não executa por conta deste erro, consegue me ajudar?
java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.WebDriver.findElement(org.openqa.selenium.By)" because "this.browser" is null at leilão.login.TestLogin2.naoDeveriaLogarComDadosInvalidos(TestLogin2.java:49)
public class TestLogin2 {
private static final String URL_LOGIN = "http://localhost:8080/login";
private WebDriver browser;
@BeforeAll
public static void beforeAll() {
System.setProperty("Webdriver.chrome.driver", "drivers/chromedrive");
}
@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("12345");
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."));
Assert.assertThrows(NoSuchElementException.class, () -> browser.findElement(By.id("usuario-logado")));
}
}