-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
peixoto
committed
Jul 2, 2018
1 parent
78e85a4
commit 8a54f9f
Showing
5 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.