Last active
June 6, 2016 23:57
-
-
Save eliasnogueira/d0907daca6d177501231f777f9338edb to your computer and use it in GitHub Desktop.
Exemplo de código Java com WebDriver referente ao post de "Passos para aprender Automação Web - Parte 2"
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
public class LinksAutomacao { | |
// Atributo que guarda a url que sera acessada | |
private final static String URL = "http://www.qualister.com.br/cursos"; | |
@Test | |
public void test() { | |
WebDriver driver = new FirefoxDriver(); | |
driver.get(URL); | |
List<WebElement> links = obtemLinks(driver); | |
listaCursosAutomacao(links); | |
listaCursosPerformance(links); | |
driver.quit(); | |
} | |
// Metodo que retorna uma lista de elementos web que sao links na pagina | |
public List<WebElement> obtemLinks(WebDriver driver) { | |
return driver.findElements(By.cssSelector("a")); | |
} | |
/* | |
* Metodo que lista os cursos de automacao | |
* Ha a utilizacao de uma condicional (if) para verificar qual links tem o texto Automacao | |
*/ | |
public void listaCursosAutomacao(List<WebElement> links) { | |
for (WebElement link : links) { | |
if (link.getText().contains("Automação")) { | |
System.out.println(link.getText()); | |
} | |
} | |
} | |
/* | |
* Metodo que lista os cursos de automacao | |
* Ha a utilizacao de uma condicional (if) para verificar qual links tem o texto Performance | |
*/ | |
public void listaCursosPerformance(List<WebElement> links) { | |
for (WebElement link : links) { | |
if (link.getText().contains("Performance")) { | |
System.out.println(link.getText()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment