Added all examples
This commit is contained in:
@@ -1,44 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
|
||||||
<output url="file://$MODULE_DIR$/target/classes" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Maven: org.testng:testng:6.9.9" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.beust:jcommander:1.48" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.ant:ant:1.7.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.ant:ant-launcher:1.7.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.15" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.beanshell:bsh:2.0b4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-java:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-edge-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-ie-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-opera-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-remote-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.8.15" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.google.guava:guava:25.0-jre" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.checkerframework:checker-compat-qual:2.0.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.1.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.11.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-firefox-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:3.141.59" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
5
pom.xml
5
pom.xml
@@ -54,5 +54,10 @@
|
|||||||
<artifactId>selenium-chrome-driver</artifactId>
|
<artifactId>selenium-chrome-driver</artifactId>
|
||||||
<version>3.141.59</version>
|
<version>3.141.59</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.lightbody.bmp</groupId>
|
||||||
|
<artifactId>browsermob-core</artifactId>
|
||||||
|
<version>2.1.5</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
66
src/test/java/com/agile611/testng/webdriver/AlertsTest.java
Normal file
66
src/test/java/com/agile611/testng/webdriver/AlertsTest.java
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.Alert;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class AlertsTest extends BaseTest {
|
||||||
|
|
||||||
|
public void acceptAlert() {
|
||||||
|
try {
|
||||||
|
WebDriverWait wait = new WebDriverWait(driver, 2);
|
||||||
|
wait.until(ExpectedConditions.alertIsPresent());
|
||||||
|
Alert alert = driver.switchTo().alert();
|
||||||
|
alert.accept();
|
||||||
|
} catch (Exception e) {
|
||||||
|
//exception handling
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dismissAlert() {
|
||||||
|
try {
|
||||||
|
WebDriverWait wait = new WebDriverWait(driver, 2);
|
||||||
|
wait.until(ExpectedConditions.alertIsPresent());
|
||||||
|
Alert alert = driver.switchTo().alert();
|
||||||
|
alert.dismiss();
|
||||||
|
} catch (Exception e) {
|
||||||
|
//exception handling
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void promptAlert() {
|
||||||
|
try {
|
||||||
|
WebDriverWait wait = new WebDriverWait(driver, 2);
|
||||||
|
wait.until(ExpectedConditions.alertIsPresent());
|
||||||
|
Alert alert = driver.switchTo().alert();
|
||||||
|
alert.sendKeys("Hola hola super hola");
|
||||||
|
alert.accept();
|
||||||
|
} catch (Exception e) {
|
||||||
|
//exception handling
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() throws InterruptedException {
|
||||||
|
driver.navigate().to("https://the-internet.herokuapp.com/javascript_alerts");
|
||||||
|
driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[1]/button")).click();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
acceptAlert();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[2]/button")).click();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
acceptAlert();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[2]/button")).click();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
dismissAlert();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[3]/button")).click();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
promptAlert();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||||
|
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class BaseRemoteWebDriverTest {
|
||||||
|
public RemoteWebDriver driver;
|
||||||
|
@BeforeClass(alwaysRun = true) //Inicialización del navegador
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
DesiredCapabilities capabilities;
|
||||||
|
String browser = System.getProperty("browser");
|
||||||
|
if (browser != null && browser.equalsIgnoreCase("chrome")) {
|
||||||
|
capabilities = DesiredCapabilities.chrome();
|
||||||
|
} else {
|
||||||
|
capabilities = DesiredCapabilities.firefox();
|
||||||
|
}
|
||||||
|
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4444/wd/hub"), capabilities);
|
||||||
|
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass(alwaysRun = true) //El cierre del navegador
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||||
|
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class BaseSaucelabsTest {
|
||||||
|
public RemoteWebDriver driver;
|
||||||
|
@BeforeClass(alwaysRun = true) //Inicialización del navegador
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
DesiredCapabilities capabilities;
|
||||||
|
String browser = System.getProperty("browser");
|
||||||
|
if (browser != null && browser.equalsIgnoreCase("chrome")) {
|
||||||
|
capabilities = DesiredCapabilities.chrome();
|
||||||
|
}
|
||||||
|
else if(browser != null && browser.equalsIgnoreCase("safari")) {
|
||||||
|
capabilities = DesiredCapabilities.safari();
|
||||||
|
}
|
||||||
|
else if(browser != null && browser.equalsIgnoreCase("ie")) {
|
||||||
|
capabilities = DesiredCapabilities.internetExplorer();
|
||||||
|
}
|
||||||
|
else if(browser != null && browser.equalsIgnoreCase("edge")) {
|
||||||
|
capabilities = DesiredCapabilities.edge();
|
||||||
|
capabilities.setCapability("platform", "Windows 10");
|
||||||
|
capabilities.setCapability("version", "15.15063");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
capabilities = DesiredCapabilities.firefox();
|
||||||
|
}
|
||||||
|
driver = new RemoteWebDriver(new URL("http://selgp:ee557a77-606f-451d-9c8b-a4bb3ef03c90@ondemand.saucelabs.com:80/wd/hub"), capabilities);
|
||||||
|
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass(alwaysRun = true) //El cierre del navegador
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/test/java/com/agile611/testng/webdriver/BaseTest.java
Normal file
44
src/test/java/com/agile611/testng/webdriver/BaseTest.java
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.JavascriptExecutor;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
|
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.testng.Assert.fail;
|
||||||
|
|
||||||
|
public class BaseTest {
|
||||||
|
public WebDriver driver;
|
||||||
|
public static JavascriptExecutor jse;
|
||||||
|
|
||||||
|
@BeforeClass(alwaysRun = true) //Inicialización del navegador
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
DesiredCapabilities capabilities;
|
||||||
|
String browser = System.getProperty("browser");
|
||||||
|
if (browser != null && browser.equalsIgnoreCase("firefox")) {
|
||||||
|
capabilities = DesiredCapabilities.firefox();
|
||||||
|
System.setProperty("webdriver.gecko.driver",
|
||||||
|
"src" + File.separator + "main"
|
||||||
|
+ File.separator + "resources"
|
||||||
|
+ File.separator + "geckodriver-macos");
|
||||||
|
driver = new FirefoxDriver(capabilities);
|
||||||
|
} else {
|
||||||
|
capabilities = DesiredCapabilities.chrome();
|
||||||
|
System.setProperty("webdriver.chrome.driver", "src" + File.separator + "main" + File.separator + "resources" + File.separator + "chromedriver-macos");
|
||||||
|
driver = new ChromeDriver(capabilities);
|
||||||
|
}
|
||||||
|
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
||||||
|
jse = (JavascriptExecutor) driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass(alwaysRun = true) //El cierre del navegador
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/test/java/com/agile611/testng/webdriver/BasicAuth.java
Normal file
13
src/test/java/com/agile611/testng/webdriver/BasicAuth.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class BasicAuth extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() throws InterruptedException {
|
||||||
|
driver.navigate().to("https://admin:admin@the-internet.herokuapp.com/basic_auth");
|
||||||
|
Thread.sleep(5000);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import net.lightbody.bmp.BrowserMobProxy;
|
||||||
|
import net.lightbody.bmp.BrowserMobProxyServer;
|
||||||
|
import net.lightbody.bmp.client.ClientUtil;
|
||||||
|
import net.lightbody.bmp.core.har.HarEntry;
|
||||||
|
import net.lightbody.bmp.proxy.CaptureType;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.Proxy;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
|
import org.openqa.selenium.remote.CapabilityType;
|
||||||
|
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||||
|
import org.testng.annotations.AfterMethod;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
public class BrokenImages {
|
||||||
|
WebDriver driver;
|
||||||
|
BrowserMobProxy proxy;
|
||||||
|
|
||||||
|
@BeforeMethod
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
proxy = new BrowserMobProxyServer();
|
||||||
|
proxy.start(0);
|
||||||
|
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
|
||||||
|
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||||
|
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
|
||||||
|
System.setProperty("webdriver.gecko.driver",
|
||||||
|
"src" + File.separator + "main"
|
||||||
|
+ File.separator + "resources"
|
||||||
|
+ File.separator + "geckodriver-macos");
|
||||||
|
driver = new FirefoxDriver(capabilities);
|
||||||
|
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterMethod
|
||||||
|
public void tearDown() {
|
||||||
|
proxy.stop();
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void allImagesLoaded() {
|
||||||
|
proxy.newHar();
|
||||||
|
driver.navigate().to("http://the-internet.herokuapp.com/broken_images");
|
||||||
|
List<WebElement> images = driver.findElements(By.tagName("img"));
|
||||||
|
List brokenImages = new ArrayList();
|
||||||
|
List<HarEntry> harEntries = proxy.getHar().getLog().getEntries();
|
||||||
|
for (int entry = 0; entry < harEntries.size(); entry++) {
|
||||||
|
for (int image = 0; image < images.size(); image++) {
|
||||||
|
if (harEntries.get(entry).getRequest().getUrl().equals(
|
||||||
|
images.get(image).getAttribute("src"))
|
||||||
|
& harEntries.get(entry).getResponse().getStatus() == 404)
|
||||||
|
brokenImages.add(images.get(image).getAttribute("src"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List emptyCollection = new ArrayList();
|
||||||
|
assertThat(brokenImages, is(emptyCollection));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ChallengingDomTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() throws InterruptedException {
|
||||||
|
driver.navigate().to("https://the-internet.herokuapp.com/challenging_dom");
|
||||||
|
List<WebElement> botons =
|
||||||
|
driver.findElements(
|
||||||
|
By.xpath(".//div[@class='example']/div/div/div[1]/a"));
|
||||||
|
for (int i = 0; i < botons.size(); i++) {
|
||||||
|
WebElement botonDeTurno =
|
||||||
|
driver.findElement(
|
||||||
|
By.xpath(".//div[@class='example']/div/div/div[1]/a[" + (i + 1) + "]"));
|
||||||
|
botonDeTurno.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class CheckBoxesTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() throws InterruptedException {
|
||||||
|
//1 Navegar hasta la página
|
||||||
|
driver.navigate().to("https://the-internet.herokuapp.com/checkboxes");
|
||||||
|
//2 Mirar que el checkbox2 está marcado
|
||||||
|
WebElement checkbox2 =
|
||||||
|
driver.findElement(By.xpath(".//*[@id='checkboxes']/input[2]"));
|
||||||
|
assertTrue(checkbox2.getAttribute("checked").equals("true"));
|
||||||
|
//2.1 Mirar el checkbox1 que NO está marcado
|
||||||
|
WebElement checkbox1 =
|
||||||
|
driver.findElement(By.xpath(".//*[@id='checkboxes']/input[1]"));
|
||||||
|
assertNull(checkbox1.getAttribute("checked"));
|
||||||
|
//3 Marcar checkbox1
|
||||||
|
checkbox1.click();
|
||||||
|
//4 Mirar que ha quedado marcado
|
||||||
|
assertTrue(checkbox1.getAttribute("checked").equals("true"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class DisappearingElementsTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() throws InterruptedException {
|
||||||
|
driver.navigate().to("https://the-internet.herokuapp.com/disappearing_elements");
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
WebElement elementsDelMenu =
|
||||||
|
driver.findElement(
|
||||||
|
By.xpath(".//*[@id='content']/div/ul/li[last()]"));
|
||||||
|
elementsDelMenu.click();
|
||||||
|
driver.navigate().back();
|
||||||
|
driver.navigate().refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
|
import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxProfile;
|
||||||
|
import org.openqa.selenium.interactions.Actions;
|
||||||
|
import org.openqa.selenium.remote.CapabilityType;
|
||||||
|
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||||
|
import org.testng.annotations.AfterMethod;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
|
import static org.hamcrest.core.IsNot.not;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
public class DownloadTest extends BaseTest {
|
||||||
|
File folder;
|
||||||
|
|
||||||
|
@BeforeMethod
|
||||||
|
public void setUp() {
|
||||||
|
folder = new File("src" + File.separator + "main" + File.separator + "resources" + File.separator + UUID.randomUUID().toString());
|
||||||
|
//Chrome
|
||||||
|
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
|
||||||
|
System.setProperty("webdriver.chrome.driver", "src" + File.separator + "main" + File.separator + "resources" + File.separator + "chromedriver-macos");
|
||||||
|
String downloadFilepath = folder.getAbsolutePath();
|
||||||
|
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
|
||||||
|
chromePrefs.put("profile.default_content_settings.popups", 0);
|
||||||
|
chromePrefs.put("download.default_directory", downloadFilepath);
|
||||||
|
ChromeOptions options = new ChromeOptions();
|
||||||
|
options.setExperimentalOption("prefs", chromePrefs);
|
||||||
|
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
|
||||||
|
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
|
||||||
|
driver = new ChromeDriver(capabilities);
|
||||||
|
|
||||||
|
//Firefox
|
||||||
|
/*DesiredCapabilities capabilities = DesiredCapabilities.firefox();
|
||||||
|
System.setProperty("webdriver.gecko.driver",
|
||||||
|
"src" + File.separator + "main"
|
||||||
|
+ File.separator + "resources"
|
||||||
|
+ File.separator + "geckodriver-macos");
|
||||||
|
FirefoxProfile profile = new FirefoxProfile();
|
||||||
|
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream;application/csv;text/csv;application/vnd.ms-excel;");
|
||||||
|
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
|
||||||
|
profile.setPreference("browser.download.manager.showWhenStarting", false);
|
||||||
|
profile.setPreference("browser.download.folderList", 2);
|
||||||
|
profile.setPreference("browser.download.dir", folder.getAbsolutePath());
|
||||||
|
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
|
||||||
|
driver = new FirefoxDriver(capabilities);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterMethod
|
||||||
|
public void tearDown() {
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void download() throws Exception {
|
||||||
|
folder.mkdir();
|
||||||
|
driver.get("http://the-internet.herokuapp.com/download");
|
||||||
|
Thread.sleep(2000);
|
||||||
|
Actions actions = new Actions(driver);
|
||||||
|
WebElement link = driver.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/a[1]"));
|
||||||
|
actions.dragAndDrop(link, link).build().perform();
|
||||||
|
// Wait 2 seconds to download file
|
||||||
|
Thread.sleep(2000);
|
||||||
|
File[] listOfFiles = folder.listFiles();
|
||||||
|
// Make sure the directory is not empty
|
||||||
|
assertThat(listOfFiles.length, is(not(0)));
|
||||||
|
for (File file : listOfFiles) {
|
||||||
|
// Make sure the downloaded file(s) is(are) not empty
|
||||||
|
assertThat(file.length(), is(not((long) 0)));
|
||||||
|
}
|
||||||
|
String[] entries = folder.list();
|
||||||
|
for (String s : entries) {
|
||||||
|
File currentFile = new File(folder.getPath(), s);
|
||||||
|
currentFile.delete();
|
||||||
|
}
|
||||||
|
folder.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.interactions.Actions;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class DragAndDropTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() throws InterruptedException {
|
||||||
|
driver.navigate().to("http://compendiumdev.co.uk/selenium/testpages/gui_user_interactions.html");
|
||||||
|
WebElement draggable1 = driver.findElement(By.xpath(".//*[@class='draganddrops']/div/div[1]"));
|
||||||
|
WebElement draggable2 = driver.findElement(By.id("draggable2"));
|
||||||
|
WebElement droppable1 = driver.findElement(By.id("droppable1"));
|
||||||
|
WebElement droppable2 = driver.findElement(By.id("droppable2"));
|
||||||
|
|
||||||
|
Actions dragAndDrop = new Actions(driver);
|
||||||
|
dragAndDrop.dragAndDrop(draggable1, droppable1).perform();
|
||||||
|
Thread.sleep(4000);
|
||||||
|
dragAndDrop.dragAndDrop(draggable2, droppable2).perform();
|
||||||
|
Thread.sleep(4000);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
dragAndDrop
|
||||||
|
.clickAndHold(draggable2)
|
||||||
|
.moveToElement(droppable1)
|
||||||
|
.release().build().perform();
|
||||||
|
Thread.sleep(4000);
|
||||||
|
dragAndDrop
|
||||||
|
.clickAndHold(draggable2)
|
||||||
|
.moveToElement(droppable2)
|
||||||
|
.release().build().perform();
|
||||||
|
Thread.sleep(4000);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DropdownTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() throws InterruptedException {
|
||||||
|
driver
|
||||||
|
.navigate().to("https://the-internet.herokuapp.com/dropdown");
|
||||||
|
List<WebElement> options =
|
||||||
|
driver.findElements(By.xpath(".//*[@id='dropdown']/option"));
|
||||||
|
for (int i = 1; i < options.size(); i++) {
|
||||||
|
WebElement option =
|
||||||
|
driver.findElement(
|
||||||
|
By.xpath(".//*[@id='dropdown']/option[" + (i + 1) + "]"));
|
||||||
|
option.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,19 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import com.agile611.testng.webdriver.pages.ResultsPage;
|
||||||
|
import com.agile611.testng.webdriver.pages.SearchPage;
|
||||||
|
import org.testng.annotations.*;
|
||||||
|
|
||||||
|
import static org.testng.Assert.*;
|
||||||
|
|
||||||
|
public class DuckDuckGoTest extends BaseSaucelabsTest {
|
||||||
|
@Test //El propio test que hemos exportado de Katalon IDE
|
||||||
|
public void testUntitledTestCase() throws Exception {
|
||||||
|
SearchPage searchPage = new SearchPage(driver);
|
||||||
|
searchPage.searchKeyword("pizza hawaiana");
|
||||||
|
ResultsPage resultsPage = new ResultsPage(driver);
|
||||||
|
assertTrue(resultsPage.isResultsPagePresent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.testng.AssertJUnit.assertFalse;
|
||||||
|
|
||||||
|
public class DynamicContentTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() throws InterruptedException {
|
||||||
|
driver.navigate().to("https://the-internet.herokuapp.com/dynamic_content");
|
||||||
|
WebElement imatge1 =
|
||||||
|
driver.findElement(
|
||||||
|
By.xpath(".//*[@id='content']/div[3]/div[1]/img"));
|
||||||
|
WebElement text1 =
|
||||||
|
driver.findElement(
|
||||||
|
By.xpath(".//*[@id='content']/div[3]/div[2]"));
|
||||||
|
String urlImatge1 = imatge1.getAttribute("src");
|
||||||
|
String texttotal1 = text1.getText();
|
||||||
|
driver.navigate().refresh();
|
||||||
|
imatge1 =
|
||||||
|
driver.findElement(
|
||||||
|
By.xpath(".//*[@id='content']/div[3]/div[1]/img"));
|
||||||
|
text1 =
|
||||||
|
driver.findElement(
|
||||||
|
By.xpath(".//*[@id='content']/div[3]/div[2]"));
|
||||||
|
String urlImatge2 = imatge1.getAttribute("src");
|
||||||
|
String texttotal2 = text1.getText();
|
||||||
|
assertFalse(urlImatge1.equals(urlImatge2));
|
||||||
|
assertFalse(texttotal1.equals(texttotal2));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class DynamicControlsTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void titleTest() {
|
||||||
|
driver.navigate().to("http://the-internet.herokuapp.com/dynamic_controls");
|
||||||
|
WebElement checkbox = driver.findElement(By.id("checkbox"));
|
||||||
|
assertTrue(checkbox.isDisplayed());
|
||||||
|
checkbox.click();
|
||||||
|
WebElement removeBtn = driver.findElement(By.xpath("//*[@id='checkbox-example']/button"));
|
||||||
|
removeBtn.click();
|
||||||
|
List<WebElement> loading = driver.findElements(By.xpath("//*[@id='loading']/img"));
|
||||||
|
WebDriverWait wait = new WebDriverWait(driver, 20);
|
||||||
|
wait.until(ExpectedConditions.or(
|
||||||
|
ExpectedConditions.presenceOfElementLocated(By.id("loading")),
|
||||||
|
ExpectedConditions.presenceOfElementLocated(By.id("message"))));
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/test/java/com/agile611/testng/webdriver/HoversTest.java
Normal file
34
src/test/java/com/agile611/testng/webdriver/HoversTest.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.interactions.Actions;
|
||||||
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.is;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class HoversTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hoversTest() throws InterruptedException {
|
||||||
|
driver.get("http://the-internet.herokuapp.com/hovers");
|
||||||
|
Thread.sleep(3000);
|
||||||
|
// Find and hover over desired element
|
||||||
|
WebElement avatar = driver.findElement(By.className("figure"));
|
||||||
|
Actions builder = new Actions(driver);
|
||||||
|
builder.moveToElement(avatar).build().perform();
|
||||||
|
Thread.sleep(3000);
|
||||||
|
// Wait until the hover appears
|
||||||
|
WebDriverWait wait = new WebDriverWait(driver, 5);
|
||||||
|
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("figcaption")));
|
||||||
|
Thread.sleep(3000);
|
||||||
|
// Assert that the hover displayed
|
||||||
|
assertTrue(driver.findElement(By.className("figcaption")).isDisplayed());
|
||||||
|
Thread.sleep(3000);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class InfiniteScrollTest extends BaseTest {
|
||||||
|
@Test
|
||||||
|
public void infiniteScrollTest() throws InterruptedException {
|
||||||
|
driver.navigate().to("http://the-internet.herokuapp.com/infinite_scroll");
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
jse.executeScript("window.scrollTo(0, document.body.scrollHeight);");
|
||||||
|
Thread.sleep(2500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class InterrogationTest extends BaseSaucelabsTest {
|
||||||
|
@Test //Opciones de Navegación
|
||||||
|
public void testNavigation() throws Exception {
|
||||||
|
driver.get("https://www.duckduckgo.com/"); //Navegar hasta duckduckgo
|
||||||
|
System.out.println("---------------------");
|
||||||
|
System.out.println(driver.getPageSource());
|
||||||
|
System.out.println("---------------------");
|
||||||
|
System.out.println(driver.getTitle());
|
||||||
|
System.out.println("---------------------");
|
||||||
|
System.out.println(driver.getCurrentUrl());
|
||||||
|
System.out.println("---------------------");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.Keys;
|
||||||
|
import org.openqa.selenium.interactions.Actions;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.is;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class KeyboardKeysTest extends BaseTest {
|
||||||
|
@Test
|
||||||
|
public void KeyboardKeysExample() throws InterruptedException {
|
||||||
|
driver.get("http://the-internet.herokuapp.com/key_presses");
|
||||||
|
Actions builder = new Actions(driver);
|
||||||
|
builder.sendKeys(Keys.SPACE).build().perform();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
assertTrue(driver.findElement(By.id("result")).getText().equalsIgnoreCase("You entered: SPACE"));
|
||||||
|
builder.sendKeys(Keys.LEFT).build().perform();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
assertTrue(driver.findElement(By.id("result")).getText().equalsIgnoreCase("You entered: LEFT"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class LargeDeepDomTest extends BaseTest {
|
||||||
|
/**
|
||||||
|
* @param element element on the page that will be highlighted
|
||||||
|
* @param duration the time in second how much the element will be highlighted
|
||||||
|
*/
|
||||||
|
|
||||||
|
private void highlightElement(WebElement element, int duration) throws InterruptedException {
|
||||||
|
// Store original style so it can be reset later
|
||||||
|
String original_style = element.getAttribute("style");
|
||||||
|
|
||||||
|
// Style element with a red border
|
||||||
|
jse.executeScript(
|
||||||
|
"arguments[0].setAttribute(arguments[1], arguments[2])",
|
||||||
|
element,
|
||||||
|
"style",
|
||||||
|
"border: 2px solid red; border-style: dashed;");
|
||||||
|
|
||||||
|
// Keep element highlighted for a spell and then revert
|
||||||
|
if (duration > 0) {
|
||||||
|
Thread.sleep(duration * 1000);
|
||||||
|
jse.executeScript(
|
||||||
|
"arguments[0].setAttribute(arguments[1], arguments[2])",
|
||||||
|
element,
|
||||||
|
"style",
|
||||||
|
original_style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void highlightElementTest() throws InterruptedException {
|
||||||
|
driver.get("http://the-internet.herokuapp.com/large");
|
||||||
|
WebElement element = driver.findElement(By.id("sibling-2.3"));
|
||||||
|
highlightElement(element, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class ManipulationTest extends BaseSaucelabsTest {
|
||||||
|
@Test //Opciones de Navegación
|
||||||
|
public void testNavigation() throws Exception {
|
||||||
|
driver.get("https://www.duckduckgo.com/"); //Navegar hasta duckduckgo
|
||||||
|
driver.findElement(By.id("search_form_input_homepage")).clear(); //Limpiar el text box
|
||||||
|
driver.findElement(By.id("search_form_input_homepage")).sendKeys("pizza hawaiana"); //Escribir en el text box
|
||||||
|
driver.findElement(By.id("search_form_homepage")).submit(); //Submit, darle al enter.
|
||||||
|
Thread.sleep(2000); //Espera forzada
|
||||||
|
|
||||||
|
driver.get("https://www.duckduckgo.com/"); //Navegar hasta duckduckgo
|
||||||
|
driver.findElement(By.id("search_form_input_homepage")).clear(); //Limpiar el text box
|
||||||
|
driver.findElement(By.id("search_form_input_homepage")).sendKeys("tortellini al pesto"); //Escribir en el text box
|
||||||
|
driver.findElement(By.id("search_button_homepage")).click(); //click a la lupa.
|
||||||
|
Thread.sleep(2000); //Espera forzada
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
public class MultipleWindowsTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void multipleWindows() {
|
||||||
|
driver.get("http://the-internet.herokuapp.com/windows");
|
||||||
|
driver.findElement(By.cssSelector(".example a")).click();
|
||||||
|
Object[] allWindows = driver.getWindowHandles().toArray();
|
||||||
|
driver.switchTo().window(allWindows[0].toString());
|
||||||
|
assertThat(driver.getTitle(), is(not("New Window")));
|
||||||
|
driver.switchTo().window(allWindows[1].toString());
|
||||||
|
assertThat(driver.getTitle(), is("New Window"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void multipleWindowsRedux() {
|
||||||
|
driver.get("http://the-internet.herokuapp.com/windows");
|
||||||
|
|
||||||
|
// Get initial window handle
|
||||||
|
String firstWindow = driver.getWindowHandle();
|
||||||
|
// Create a newWindow variable
|
||||||
|
String newWindow = "";
|
||||||
|
// Trigger new window to open
|
||||||
|
driver.findElement(By.cssSelector(".example a")).click();
|
||||||
|
// Grab all window handles
|
||||||
|
Set<String> allWindows = driver.getWindowHandles();
|
||||||
|
|
||||||
|
// Iterate through window handles collection
|
||||||
|
// Find the new window handle, storing it in the newWindow variable
|
||||||
|
for (String window : allWindows) {
|
||||||
|
if (!window.equals(firstWindow)) {
|
||||||
|
newWindow = window;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch to the first window & verify
|
||||||
|
driver.switchTo().window(firstWindow);
|
||||||
|
assertThat(driver.getTitle(), is(not(equalTo("New Window"))));
|
||||||
|
|
||||||
|
// Switch to the new window & verify
|
||||||
|
driver.switchTo().window(newWindow);
|
||||||
|
assertThat(driver.getTitle(), is(equalTo("New Window")));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class NavigationTest extends BaseSaucelabsTest {
|
||||||
|
@Test //Opciones de Navegación
|
||||||
|
public void testNavigation() throws Exception {
|
||||||
|
driver.get("https://www.duckduckgo.com/"); //Navegar hasta duckduckgo
|
||||||
|
Thread.sleep(2000);
|
||||||
|
driver.navigate().to("https://www.google.com"); //Navegar hasta Google
|
||||||
|
Thread.sleep(2000);
|
||||||
|
driver.get("https://www.yahoo.com"); //Navegar hasta Yahoo
|
||||||
|
Thread.sleep(2000);
|
||||||
|
driver.navigate().back(); //Hacia atrás (Volver a Google)
|
||||||
|
Thread.sleep(2000);
|
||||||
|
driver.navigate().forward(); //Hacia adelante (Volver a Yahoo)
|
||||||
|
Thread.sleep(2000);
|
||||||
|
driver.navigate().refresh(); //Refrescar Yahoo
|
||||||
|
Thread.sleep(2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class NestedFramesTest extends BaseTest {
|
||||||
|
|
||||||
|
public void listIframesFromPage(WebDriver driver) {
|
||||||
|
final List<WebElement> iframes = driver.findElements(By.tagName("frame"));
|
||||||
|
for (WebElement iframe : iframes) {
|
||||||
|
System.out.println(iframe.getAttribute("id"));
|
||||||
|
System.out.println(iframe.getAttribute("name"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() {
|
||||||
|
driver.navigate().to("https://the-internet.herokuapp.com/nested_frames");
|
||||||
|
listIframesFromPage(driver);
|
||||||
|
driver.switchTo().frame("frame-bottom");
|
||||||
|
System.out.println(driver.findElement(By.xpath("html/body")).getText());
|
||||||
|
driver.switchTo().defaultContent();
|
||||||
|
driver.switchTo().frame("frame-top");
|
||||||
|
listIframesFromPage(driver);
|
||||||
|
driver.switchTo().frame("frame-middle");
|
||||||
|
System.out.println(driver.findElement(By.xpath("html/body")).getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.Proxy;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
|
import org.openqa.selenium.remote.CapabilityType;
|
||||||
|
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||||
|
import net.lightbody.bmp.BrowserMobProxy;
|
||||||
|
import net.lightbody.bmp.BrowserMobProxyServer;
|
||||||
|
import net.lightbody.bmp.client.ClientUtil;
|
||||||
|
import net.lightbody.bmp.core.har.Har;
|
||||||
|
import net.lightbody.bmp.proxy.CaptureType;
|
||||||
|
import org.testng.annotations.AfterMethod;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
public class StatusCodesTest {
|
||||||
|
WebDriver driver;
|
||||||
|
BrowserMobProxy proxy;
|
||||||
|
|
||||||
|
@BeforeMethod
|
||||||
|
public void setUp() {
|
||||||
|
proxy = new BrowserMobProxyServer();
|
||||||
|
proxy.start(0);
|
||||||
|
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
|
||||||
|
DesiredCapabilities capabilities = new DesiredCapabilities();
|
||||||
|
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
|
||||||
|
System.setProperty("webdriver.gecko.driver",
|
||||||
|
"src" + File.separator + "main"
|
||||||
|
+ File.separator + "resources"
|
||||||
|
+ File.separator + "geckodriver-macos");
|
||||||
|
driver = new FirefoxDriver(capabilities);
|
||||||
|
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterMethod
|
||||||
|
public void tearDown() {
|
||||||
|
proxy.stop();
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ResourceNotFound404() {
|
||||||
|
proxy.newHar();
|
||||||
|
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/404");
|
||||||
|
Har har = proxy.getHar();
|
||||||
|
assertThat(har.getLog().getEntries().get(0).getResponse().getStatus(), is(404));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ResourceFound200() {
|
||||||
|
proxy.newHar();
|
||||||
|
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/200");
|
||||||
|
Har har = proxy.getHar();
|
||||||
|
assertThat(har.getLog().getEntries().get(0).getResponse().getStatus(), is(200));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ResourceRedirect301() {
|
||||||
|
proxy.newHar();
|
||||||
|
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/301");
|
||||||
|
Har har = proxy.getHar();
|
||||||
|
assertThat(har.getLog().getEntries().get(0).getResponse().getStatus(), is(301));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ResourceError500() {
|
||||||
|
proxy.newHar();
|
||||||
|
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/500");
|
||||||
|
Har har = proxy.getHar();
|
||||||
|
assertThat(har.getLog().getEntries().get(0).getResponse().getStatus(), is(500));
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/test/java/com/agile611/testng/webdriver/TestABTest.java
Normal file
28
src/test/java/com/agile611/testng/webdriver/TestABTest.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import com.agile611.testng.webdriver.BaseTest;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class TestABTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() throws InterruptedException {
|
||||||
|
int counter1=0, counter2=0;
|
||||||
|
for(int i=0; i < 1000; i++){
|
||||||
|
driver.get("https://the-internet.herokuapp.com/abtest");
|
||||||
|
WebElement title =
|
||||||
|
driver.findElement(By.xpath(".//*[@id='content']/div/h3"));
|
||||||
|
if(title.getText().equals("A/B Test Variation 1")){
|
||||||
|
counter1++;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
counter2++;
|
||||||
|
}
|
||||||
|
driver.manage().deleteAllCookies();
|
||||||
|
}
|
||||||
|
System.out.println("He recibido la version 1 "+counter1);
|
||||||
|
System.out.println("He recibido la version 2 "+counter2);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/test/java/com/agile611/testng/webdriver/UploadTest.java
Normal file
30
src/test/java/com/agile611/testng/webdriver/UploadTest.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.testng.AssertJUnit.assertTrue;
|
||||||
|
|
||||||
|
public class UploadTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() throws InterruptedException {
|
||||||
|
driver.navigate().to("https://the-internet.herokuapp.com/upload");
|
||||||
|
WebElement fileUpload = driver.findElement(By.id("file-upload"));
|
||||||
|
File file = new File("src" + File.separator + "main"
|
||||||
|
+ File.separator + "resources" + File.separator + "2-logo-B_activa.png");
|
||||||
|
fileUpload.sendKeys(file.getAbsolutePath());
|
||||||
|
WebElement buttonUpload = driver.findElement(By.id("file-submit"));
|
||||||
|
buttonUpload.click();
|
||||||
|
WebElement uploadedFiles = driver.findElement(By.id("uploaded-files"));
|
||||||
|
WebDriverWait wait = new WebDriverWait(driver, 20);
|
||||||
|
wait.until(ExpectedConditions.visibilityOf(uploadedFiles));
|
||||||
|
assertTrue(uploadedFiles.isDisplayed());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.agile611.testng.webdriver.pages;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
import org.openqa.selenium.support.PageFactory;
|
||||||
|
|
||||||
|
public class ResultsPage {
|
||||||
|
|
||||||
|
private WebDriver driver;
|
||||||
|
|
||||||
|
@FindBy(id = "links_wrapper")
|
||||||
|
public WebElement resultsList;
|
||||||
|
|
||||||
|
|
||||||
|
public ResultsPage(WebDriver driver) {
|
||||||
|
PageFactory.initElements(driver, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isResultsPagePresent() {
|
||||||
|
return resultsList.isDisplayed();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.agile611.testng.webdriver.pages;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
import org.openqa.selenium.support.PageFactory;
|
||||||
|
|
||||||
|
public class SearchPage {
|
||||||
|
|
||||||
|
private WebDriver driver;
|
||||||
|
|
||||||
|
@FindBy(id = "search_form_input_homepage")
|
||||||
|
public WebElement searchBox;
|
||||||
|
|
||||||
|
|
||||||
|
@FindBy(id = "search_button_homepage")
|
||||||
|
public WebElement searchButton;
|
||||||
|
|
||||||
|
|
||||||
|
public SearchPage(WebDriver driver) {
|
||||||
|
PageFactory.initElements(driver, this);
|
||||||
|
driver.get("https://duckduckgo.com/");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void searchKeyword(String keyword) {
|
||||||
|
searchBox.clear();
|
||||||
|
searchBox.sendKeys(keyword);
|
||||||
|
searchButton.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user