Skip to content

Commit

Permalink
inclui cap 09
Browse files Browse the repository at this point in the history
  • Loading branch information
peixoto committed Jul 2, 2018
1 parent 78e85a4 commit 8a54f9f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/test/java/cap_09/CadastroFacebookPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cap_09;
import java.time.Duration;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

public class CadastroFacebookPage {

WebDriver driver;

public CadastroFacebookPage(WebDriver driver) {
this.driver = driver;
}

public CadastroFacebookPage preencheNome(String nome) {
driver.findElement(By.name("firstname")).sendKeys(nome);
return this;
}

public CadastroFacebookPage preencheSobrenome(String sobrenome) {
driver.findElement(By.name("lastname")).sendKeys(sobrenome);
return this;
}


// Com espera
public CadastroFacebookPage preencheUsuario(String usu) {
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement usuario = wait.until(ExpectedConditions.elementToBeClickable(By.id("email")));

usuario.sendKeys(usu);
return this;
}

// Com espera - Fluent Wait
// Mudei o nome para preencheUsuarios para não dar problema com o anterior
public CadastroFacebookPage preencheUsuarios(String usu) {

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(10))
.pollingEvery(Duration.ofSeconds(10))
.ignoring(NoSuchElementException.class)
.ignoring(StaleElementReferenceException.class);
WebElement usuario = wait.until(ExpectedConditions.elementToBeClickable(By.id("email")));

usuario.sendKeys(usu);
return this;
}

public CadastroFacebookPage preencheSenha(String senha) {
driver.findElement(By.id("pass")).sendKeys(senha);
return this;
}

public void clicaBotaoEntrar() {
driver.findElement(By.id("u_0_2")).click();
}

public void logarComo(String user, String pass) {
preencheUsuario(user).preencheSenha(pass).clicaBotaoEntrar();
}
}
26 changes: 26 additions & 0 deletions src/test/java/cap_09/ExemploEsperaPersonalizada.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cap_09;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ExemploEsperaPersonalizada {

static WebDriver driver;

public static void aguardaAteQueValueMude(final WebElement element) {
WebDriverWait wait = new WebDriverWait(driver, 10);

wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
String value = element.getAttribute("value");

if(!value.equals("")) {
return true;
}
return false;
}
});
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 8a54f9f

Please sign in to comment.