diff --git a/src/test/java/cap_09/CadastroFacebookPage.java b/src/test/java/cap_09/CadastroFacebookPage.java new file mode 100644 index 0000000..b358d55 --- /dev/null +++ b/src/test/java/cap_09/CadastroFacebookPage.java @@ -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 wait = new FluentWait(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(); + } +} \ No newline at end of file diff --git a/src/test/java/cap_09/ExemploEsperaPersonalizada.java b/src/test/java/cap_09/ExemploEsperaPersonalizada.java new file mode 100644 index 0000000..52c4d40 --- /dev/null +++ b/src/test/java/cap_09/ExemploEsperaPersonalizada.java @@ -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() { + public Boolean apply(WebDriver driver) { + String value = element.getAttribute("value"); + + if(!value.equals("")) { + return true; + } + return false; + } + }); + } +} diff --git a/target/test-classes/cap_09/CadastroFacebookPage.class b/target/test-classes/cap_09/CadastroFacebookPage.class new file mode 100644 index 0000000..1ec169c Binary files /dev/null and b/target/test-classes/cap_09/CadastroFacebookPage.class differ diff --git a/target/test-classes/cap_09/ExemploEsperaPersonalizada$1.class b/target/test-classes/cap_09/ExemploEsperaPersonalizada$1.class new file mode 100644 index 0000000..352ece5 Binary files /dev/null and b/target/test-classes/cap_09/ExemploEsperaPersonalizada$1.class differ diff --git a/target/test-classes/cap_09/ExemploEsperaPersonalizada.class b/target/test-classes/cap_09/ExemploEsperaPersonalizada.class new file mode 100644 index 0000000..42a76ce Binary files /dev/null and b/target/test-classes/cap_09/ExemploEsperaPersonalizada.class differ