Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Erro ao executar o teste

Ao executar o teste, está apresentando o erro:

org.openqa.selenium.NoSuchElementException: Cannot locate element with text: Paulo Henrique
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'LSAITO', ip: '192.168.56.1', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '13.0.2'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.Select.selectByVisibleText(Select.java:147)
    at br.com.caelum.teste.NovoLeilaoPage.preenche(NovoLeilaoPage.java:24)
    at br.com.caelum.teste.CriadorDeCenarios.umLeilao(CriadorDeCenarios.java:23)
    at br.com.caelum.teste.LanceSystemTest.inicializa(LanceSystemTest.java:30)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.RunBefores.invokeMethod(RunBefores.java:33)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:43)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
    at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
    at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:82)
    at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:73)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:141)
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
2 respostas

Segue as classes criadas e utilizadas:

public class LanceSystemTest {

//private FirefoxDriver driver;
private WebDriver driver;
private LeiloesPage leiloes;
private DetalhesDoLeilaoPage lances;
//private CriadorDeCenarios criadorDeCenarios;

@Before
public void inicializa() {
    System.setProperty("webdriver.gecko.driver","E:\\Curso Automação de Testes\\Curso 04 - Selenium\\geckodriver.exe");
    driver = new FirefoxDriver();
    leiloes = new LeiloesPage(driver);
    driver.get("http://localhost:8080/apenas-teste/limpa");

    //cenario padrao
    lances = new DetalhesDoLeilaoPage(driver);

        new CriadorDeCenarios(driver)
        .umUsuario("Paulo Henrique", "paulo@henrique.com")
        .umUsuario("Jose Alberto", "jose@alberto.com")
        .umLeilao("Paulo Henrique", "Geladeira", 100, false);
}

@Test
public void deveFazerUmLance() {

    DetalhesDoLeilaoPage lances = leiloes.detalhes(1);

    lances.lance("José Eduardo", 150);

    assertTrue(lances.existeLance("José Eduardo", 150));

}    

}


class DetalhesDoLeilaoPage {

private WebDriver driver;

public DetalhesDoLeilaoPage(WebDriver driver) {
    this.driver = driver;    
}
public void lance(String usuario, double valor) {
    WebElement txtValor = driver.findElement(By.name("lance.valor"));
    Select cbUsuario = new Select(driver.findElement(By.name("lance.usuario.id")));
    //WebElement combo = driver.findElement(By.name("lance.usuario.id"));
    //Select cbUsuario = new Select(combo);

    cbUsuario.selectByVisibleText(usuario);
    txtValor.sendKeys(String.valueOf(valor));

    driver.findElement(By.id("btnDarLance")).click();

}
public boolean existeLance(String usuario, double valor) {

    Boolean temUsuario = 
            new WebDriverWait(driver, 15)
                .until(ExpectedConditions
                    .textToBePresentInElementLocated(By.id("lancesDados"), usuario));

    if(temUsuario) return driver.getPageSource().contains(String.valueOf(valor));

    return false;

}

}


class LeiloesPage {

private WebDriver driver;

public LeiloesPage(WebDriver driver) {
    this.driver = driver;

}

public void visita() {
    driver.get("http://localhost:8080/leiloes");
}
public NovoLeilaoPage novo() {
    driver.findElement(By.linkText("Novo Leilão")).click();
    return new NovoLeilaoPage(driver);
}

public boolean existe(String produto, double valor, String usuario, boolean usado) {
    return driver.getPageSource().contains(produto)&&
            driver.getPageSource().contains(String.valueOf(valor)) &&
            driver.getPageSource().contains(usado ? "Sim" : "Não");
            }

public DetalhesDoLeilaoPage detalhes(int posicao) {
    List<WebElement> elementos = driver.findElements(By.linkText("exibir"));
    elementos.get(posicao).click();

    return new DetalhesDoLeilaoPage(driver);
}

}

solução!

O erro:

Driver info: driver.version: unknown

geralmente é por conta da aplicação não estar conseguindo achar o driver do browser.

Sobre essa configuração:

System.setProperty("webdriver.gecko.driver","E:\\Curso Automação de Testes\\Curso 04 - Selenium\\geckodriver.exe");

Tenta deixar o geckodriver.exe em um path sem espaços em branco nas pastas e sem acentuação, por exemplo: "E:\curso\selenium\geckodriver.exe"