Bom dia a todos
Eu fiz o teste anterior e funcionou e agora que eu estou fazendo o método naoDeveriaEfetuarLoginComDadosInvalidos()
, ele sempre dá false o método mesmo sendo verdadeiro:
Assertions.assertTrue(browser.getCurrentUrl().equals("http://localhost:8080/login?error"));
Assertions.assertTrue(browser.getPageSource().contains("Usuário e senha inválidos."));
}
E a mensagem de erro que aparece no meu console é:
1676565567464 geckodriver INFO Listening on 127.0.0.1:11234
1676565567841 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-no-remote" "-profile" "C:\\Users\\User\\AppData\\Local\\Temp\\rust_mozprofileSbEPw9"
console.warn: services.settings: Ignoring preference override of remote settings server
console.warn: services.settings: Allow by setting MOZ_REMOTE_SETTINGS_DEVTOOLS=1 in the environment
1676565568496 Marionette INFO Marionette enabled
Dynamically enable window occlusion 0
1676565568509 Marionette INFO Listening on port 55501
Read port: 55501
1676565568868 RemoteAgent WARN TLS certificate errors will be ignored for this session
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at C:\\Users\\User\\AppData\\Local\\Temp\\rust_mozprofileSbEPw9\\search.json.mozlz4", (void 0)))
fev. 16, 2023 1:39:32 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
console.error: ({})
console.warn: LoginRecipes: "Falling back to a synchronous message for: http://localhost:8080."
console.warn: LoginRecipes: "Falling back to a synchronous message for: http://localhost:8080."
org.opentest4j.AssertionFailedError:
Expected :true
Actual :false
<Click to see difference>
at br.com.alura.leilao.login.LoginTest.naoDeveriaEfetuarLoginComDadosInvalidos(LoginTest.java:40)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Qual seria o erro que eu estou fazendo? código completo:
import io.github.bonigarcia.wdm.WebDriverManager;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
public class LoginTest {
@Test
public void deveriaEfetuarLoginComDadosValidos(){
WebDriverManager.firefoxdriver().setup();
WebDriver browser;
System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Geckodriver\\geckodriver.exe");
browser =new FirefoxDriver();
browser.navigate().to("http://localhost:8080/login");
browser.findElement(By.id("username")).sendKeys("fulano");
browser.findElement(By.id("password")).sendKeys("pass");
browser.findElement(By.id("login-form")).submit();
Assertions.assertFalse(browser.getCurrentUrl().equals("http://localhost:8080/leiloes"));
browser.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
Assertions.assertEquals("fulano", browser.findElement(By.id("usuario-logado")).getText());
browser.quit();
}
@Test
public void naoDeveriaEfetuarLoginComDadosInvalidos(){
WebDriverManager.firefoxdriver().setup();
WebDriver browser;
System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Geckodriver\\geckodriver.exe");
browser =new FirefoxDriver();
browser.navigate().to("http://localhost:8080/login");
browser.findElement(By.id("username")).sendKeys("ful");
browser.findElement(By.id("password")).sendKeys("passdfdf");
browser.findElement(By.id("login-form")).submit();
browser.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
Assertions.assertTrue(browser.getCurrentUrl().equals("http://localhost:8080/login?error"));
Assertions.assertTrue(browser.getPageSource().contains("Usuário e senha inválidos."));
Assertions.assertThrows(NoSuchElementException.class,()-> browser.findElement(By.id("usuario-logado")));
browser.quit();
}
}