Compare commits
21 Commits
3bd53a06f6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
818ea0622f | ||
|
|
797fa4b66f | ||
|
|
399ecaff28 | ||
|
|
68eae36331 | ||
|
|
379246891e | ||
|
|
05e2bd88d2 | ||
|
|
d39e439da8 | ||
|
|
73c7b7a45b | ||
|
|
822b916a23 | ||
|
|
2ea0dc239b | ||
|
|
aa622511f4 | ||
|
|
a1f79f41c6 | ||
|
|
3cd765934d | ||
|
|
da053e3e0f | ||
|
|
2f2225c2ff | ||
|
|
1a63263274 | ||
|
|
9da46f7517 | ||
|
|
ee05f412a7 | ||
|
|
ce815cc883 | ||
|
|
a3fcfadf38 | ||
|
|
5a8c6dc7c7 |
63
.gitignore
vendored
63
.gitignore
vendored
@@ -11,6 +11,45 @@
|
|||||||
.idea/**/tasks.xml
|
.idea/**/tasks.xml
|
||||||
.idea/dictionaries
|
.idea/dictionaries
|
||||||
|
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/macos
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=macos
|
||||||
|
|
||||||
|
### macOS ###
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
### macOS Patch ###
|
||||||
|
# iCloud generated files
|
||||||
|
*.icloud
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/macos
|
||||||
|
|
||||||
|
|
||||||
# Sensitive or high-churn files:
|
# Sensitive or high-churn files:
|
||||||
.idea/**/dataSources/
|
.idea/**/dataSources/
|
||||||
.idea/**/dataSources.ids
|
.idea/**/dataSources.ids
|
||||||
@@ -20,6 +59,30 @@
|
|||||||
.idea/**/dynamic.xml
|
.idea/**/dynamic.xml
|
||||||
.idea/**/uiDesigner.xml
|
.idea/**/uiDesigner.xml
|
||||||
|
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode
|
||||||
|
|
||||||
|
### VisualStudioCode ###
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
!.vscode/*.code-snippets
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
|
||||||
|
# Built Visual Studio Code Extensions
|
||||||
|
*.vsix
|
||||||
|
|
||||||
|
### VisualStudioCode Patch ###
|
||||||
|
# Ignore all local history of files
|
||||||
|
.history
|
||||||
|
.ionide
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode
|
||||||
|
|
||||||
# Gradle:
|
# Gradle:
|
||||||
.idea/**/gradle.xml
|
.idea/**/gradle.xml
|
||||||
.idea/**/libraries
|
.idea/**/libraries
|
||||||
|
|||||||
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"java.compile.nullAnalysis.mode": "automatic",
|
||||||
|
"java.configuration.updateBuildConfiguration": "interactive"
|
||||||
|
}
|
||||||
14
README.md
14
README.md
@@ -8,17 +8,25 @@ Código del curso de Selenium WebDriver de [Agile611](https://www.agile611.com)
|
|||||||
3. [Maven](https://maven.apache.org/download.cgi)
|
3. [Maven](https://maven.apache.org/download.cgi)
|
||||||
4. [Firefox](https://www.mozilla.org/en-US/firefox/new/) instalado
|
4. [Firefox](https://www.mozilla.org/en-US/firefox/new/) instalado
|
||||||
5. [Chrome](https://www.google.com/chrome/) instalado
|
5. [Chrome](https://www.google.com/chrome/) instalado
|
||||||
6. [Intellij Idea](https://www.jetbrains.com/idea/) o el IDE de Java que más os guste
|
6. [Visual Studio Code](https://code.visualstudio.com/) o el IDE de Java que más os guste
|
||||||
|
|
||||||
|
|
||||||
Puedes encontrar el [curso completo aquí](https://www.agile611.com/cursos/agile/curso-online-selenium-webdriver-version-java/)
|
Puedes encontrar el [curso completo aquí](https://www.agile611.com/cursos/agile/curso-online-selenium-webdriver-version-java/)
|
||||||
|
|
||||||
|
## Cómo ejecutar
|
||||||
|
|
||||||
|
1. Clona el repositorio
|
||||||
|
2. Ejecuta `mvn clean test` para correr los tests
|
||||||
|
3. Los tests usan Firefox y Chrome, asegúrate de que los drivers estén en el PATH o en src/main/resources
|
||||||
|
|
||||||
## Soporte
|
## Soporte
|
||||||
|
|
||||||
Este tutorial es de dominio público y lo ha realizado [Agile611](https://www.agile611.com) under WTFPL.
|
Este tutorial es de dominio público y lo ha realizado [Agile611](https://www.agile611.com) under CC-SA.
|
||||||
|
|
||||||
[](http://www.wtfpl.net/)
|
[](https://creativecommons.org/licenses/by-sa/4.0/)
|
||||||
|
|
||||||
Este README lo ha hecho [Guillem Hernández Sola](https://www.linkedin.com/in/guillemhs/) y también es de dominio público.
|
Este README lo ha hecho [Guillem Hernández Sola](https://www.linkedin.com/in/guillemhs/) y también es de dominio público.
|
||||||
|
|
||||||
Podéis contactar a [Agile611](https://www.agile611.com) por [aquí](https://www.agile611.com/formulario-de-contacto/) para más detalles.
|
Podéis contactar a [Agile611](https://www.agile611.com) por [aquí](https://www.agile611.com/formulario-de-contacto/) para más detalles.
|
||||||
|
|
||||||
|
[](http://www.agile611.com/)
|
||||||
|
|||||||
@@ -1,43 +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" />
|
|
||||||
<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>
|
|
||||||
24
pom.xml
24
pom.xml
@@ -4,13 +4,13 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.agile611.trainings.webdriver</groupId>
|
<groupId>com.agile611.trainings.webdriver</groupId>
|
||||||
<artifactId>cursoSeleniumWebdriver</artifactId>
|
<artifactId>cursoSeleniumWebdriver</artifactId>
|
||||||
<version>19.08.15</version>
|
<version>26.04.23</version>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.19.1</version>
|
<version>3.1.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<suiteXmlFiles>
|
<suiteXmlFiles>
|
||||||
<suiteXmlFile>src/main/resources/suite.xml</suiteXmlFile>
|
<suiteXmlFile>src/main/resources/suite.xml</suiteXmlFile>
|
||||||
@@ -20,9 +20,10 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.11.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>8</source>
|
<source>25</source>
|
||||||
<target>8</target>
|
<target>25</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
@@ -37,27 +38,32 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.testng</groupId>
|
<groupId>org.testng</groupId>
|
||||||
<artifactId>testng</artifactId>
|
<artifactId>testng</artifactId>
|
||||||
<version>6.9.9</version>
|
<version>7.10.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
<groupId>org.seleniumhq.selenium</groupId>
|
||||||
<artifactId>selenium-java</artifactId>
|
<artifactId>selenium-java</artifactId>
|
||||||
<version>3.141.59</version>
|
<version>4.43.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
<groupId>org.seleniumhq.selenium</groupId>
|
||||||
<artifactId>selenium-firefox-driver</artifactId>
|
<artifactId>selenium-firefox-driver</artifactId>
|
||||||
<version>3.141.59</version>
|
<version>4.43.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
<groupId>org.seleniumhq.selenium</groupId>
|
||||||
<artifactId>selenium-chrome-driver</artifactId>
|
<artifactId>selenium-chrome-driver</artifactId>
|
||||||
<version>3.141.59</version>
|
<version>4.43.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest-core</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.lightbody.bmp</groupId>
|
<groupId>net.lightbody.bmp</groupId>
|
||||||
<artifactId>browsermob-core</artifactId>
|
<artifactId>browsermob-core</artifactId>
|
||||||
<version>2.1.5</version>
|
<version>2.1.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
BIN
src/.DS_Store
vendored
BIN
src/.DS_Store
vendored
Binary file not shown.
BIN
src/main/.DS_Store
vendored
BIN
src/main/.DS_Store
vendored
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 279 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,10 +0,0 @@
|
|||||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
|
||||||
<suite name="StartUsingWebDriver test examples"
|
|
||||||
allow-return-values="true" verbose="1"
|
|
||||||
parallel="tests">
|
|
||||||
<test name="all" parallel="classes" thread-count="4" time-out="240000">
|
|
||||||
<packages>
|
|
||||||
<package name="com.agile611.testng.webdriver.*"/>
|
|
||||||
</packages>
|
|
||||||
</test>
|
|
||||||
</suite>
|
|
||||||
@@ -6,11 +6,13 @@ import org.openqa.selenium.support.ui.ExpectedConditions;
|
|||||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
public class AlertsTest extends BaseTest {
|
public class AlertsTest extends BaseTest {
|
||||||
|
|
||||||
public void acceptAlert() {
|
public void acceptAlert() {
|
||||||
try {
|
try {
|
||||||
WebDriverWait wait = new WebDriverWait(driver, 2);
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
|
||||||
wait.until(ExpectedConditions.alertIsPresent());
|
wait.until(ExpectedConditions.alertIsPresent());
|
||||||
Alert alert = driver.switchTo().alert();
|
Alert alert = driver.switchTo().alert();
|
||||||
alert.accept();
|
alert.accept();
|
||||||
@@ -21,7 +23,7 @@ public class AlertsTest extends BaseTest {
|
|||||||
|
|
||||||
public void dismissAlert() {
|
public void dismissAlert() {
|
||||||
try {
|
try {
|
||||||
WebDriverWait wait = new WebDriverWait(driver, 2);
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
|
||||||
wait.until(ExpectedConditions.alertIsPresent());
|
wait.until(ExpectedConditions.alertIsPresent());
|
||||||
Alert alert = driver.switchTo().alert();
|
Alert alert = driver.switchTo().alert();
|
||||||
alert.dismiss();
|
alert.dismiss();
|
||||||
@@ -32,7 +34,7 @@ public class AlertsTest extends BaseTest {
|
|||||||
|
|
||||||
public void promptAlert() {
|
public void promptAlert() {
|
||||||
try {
|
try {
|
||||||
WebDriverWait wait = new WebDriverWait(driver, 2);
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
|
||||||
wait.until(ExpectedConditions.alertIsPresent());
|
wait.until(ExpectedConditions.alertIsPresent());
|
||||||
Alert alert = driver.switchTo().alert();
|
Alert alert = driver.switchTo().alert();
|
||||||
alert.sendKeys("Hola hola super hola");
|
alert.sendKeys("Hola hola super hola");
|
||||||
|
|||||||
@@ -1,28 +1,27 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
import java.net.URL;
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class BaseRemoteWebDriverTest {
|
public class BaseRemoteWebDriverTest {
|
||||||
public RemoteWebDriver driver;
|
public RemoteWebDriver driver;
|
||||||
@BeforeClass(alwaysRun = true) //Inicialización del navegador
|
@BeforeClass(alwaysRun = true) //Inicialización del navegador
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
DesiredCapabilities capabilities;
|
|
||||||
String browser = System.getProperty("browser");
|
String browser = System.getProperty("browser");
|
||||||
if (browser != null && browser.equalsIgnoreCase("chrome")) {
|
if (browser != null && browser.equalsIgnoreCase("chrome")) {
|
||||||
capabilities = DesiredCapabilities.chrome();
|
ChromeOptions options = new ChromeOptions();
|
||||||
|
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4444/wd/hub"), options);
|
||||||
} else {
|
} else {
|
||||||
capabilities = DesiredCapabilities.firefox();
|
FirefoxOptions options = new FirefoxOptions();
|
||||||
|
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4444/wd/hub"), options);
|
||||||
}
|
}
|
||||||
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4444/wd/hub"), capabilities);
|
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
|
||||||
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass(alwaysRun = true) //El cierre del navegador
|
@AfterClass(alwaysRun = true) //El cierre del navegador
|
||||||
|
|||||||
@@ -1,39 +1,45 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
import java.net.URL;
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
|
import org.openqa.selenium.edge.EdgeOptions;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||||
|
import org.openqa.selenium.ie.InternetExplorerOptions;
|
||||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||||
|
import org.openqa.selenium.safari.SafariOptions;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class BaseSaucelabsTest {
|
public class BaseSaucelabsTest {
|
||||||
public RemoteWebDriver driver;
|
public RemoteWebDriver driver;
|
||||||
@BeforeClass(alwaysRun = true) //Inicialización del navegador
|
@BeforeClass(alwaysRun = true) //Inicialización del navegador
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
DesiredCapabilities capabilities;
|
|
||||||
String browser = System.getProperty("browser");
|
String browser = System.getProperty("browser");
|
||||||
if (browser != null && browser.equalsIgnoreCase("chrome")) {
|
if (browser != null && browser.equalsIgnoreCase("chrome")) {
|
||||||
capabilities = DesiredCapabilities.chrome();
|
ChromeOptions options = new ChromeOptions();
|
||||||
|
driver = new RemoteWebDriver(new URL("http://selgp:ee557a77-606f-451d-9c8b-a4bb3ef03c90@ondemand.saucelabs.com:80/wd/hub"), options);
|
||||||
}
|
}
|
||||||
else if(browser != null && browser.equalsIgnoreCase("safari")) {
|
else if(browser != null && browser.equalsIgnoreCase("safari")) {
|
||||||
capabilities = DesiredCapabilities.safari();
|
SafariOptions options = new SafariOptions();
|
||||||
|
driver = new RemoteWebDriver(new URL("http://selgp:ee557a77-606f-451d-9c8b-a4bb3ef03c90@ondemand.saucelabs.com:80/wd/hub"), options);
|
||||||
}
|
}
|
||||||
else if(browser != null && browser.equalsIgnoreCase("ie")) {
|
else if(browser != null && browser.equalsIgnoreCase("ie")) {
|
||||||
capabilities = DesiredCapabilities.internetExplorer();
|
InternetExplorerOptions options = new InternetExplorerOptions();
|
||||||
|
driver = new RemoteWebDriver(new URL("http://selgp:ee557a77-606f-451d-9c8b-a4bb3ef03c90@ondemand.saucelabs.com:80/wd/hub"), options);
|
||||||
}
|
}
|
||||||
else if(browser != null && browser.equalsIgnoreCase("edge")) {
|
else if(browser != null && browser.equalsIgnoreCase("edge")) {
|
||||||
capabilities = DesiredCapabilities.edge();
|
EdgeOptions options = new EdgeOptions();
|
||||||
capabilities.setCapability("platform", "Windows 10");
|
options.setCapability("platform", "Windows 10");
|
||||||
capabilities.setCapability("version", "15.15063");
|
options.setCapability("version", "15.15063");
|
||||||
|
driver = new RemoteWebDriver(new URL("http://selgp:ee557a77-606f-451d-9c8b-a4bb3ef03c90@ondemand.saucelabs.com:80/wd/hub"), options);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
capabilities = DesiredCapabilities.firefox();
|
FirefoxOptions options = new FirefoxOptions();
|
||||||
|
driver = new RemoteWebDriver(new URL("http://selgp:ee557a77-606f-451d-9c8b-a4bb3ef03c90@ondemand.saucelabs.com:80/wd/hub"), options);
|
||||||
}
|
}
|
||||||
driver = new RemoteWebDriver(new URL("http://selgp:ee557a77-606f-451d-9c8b-a4bb3ef03c90@ondemand.saucelabs.com:80/wd/hub"), capabilities);
|
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
|
||||||
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass(alwaysRun = true) //El cierre del navegador
|
@AfterClass(alwaysRun = true) //El cierre del navegador
|
||||||
|
|||||||
@@ -1,39 +1,37 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
import org.openqa.selenium.JavascriptExecutor;
|
import org.openqa.selenium.JavascriptExecutor;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.chrome.ChromeDriver;
|
import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
|
import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static org.testng.Assert.fail;
|
|
||||||
|
|
||||||
public class BaseTest {
|
public class BaseTest {
|
||||||
public WebDriver driver;
|
public WebDriver driver;
|
||||||
public static JavascriptExecutor jse;
|
public static JavascriptExecutor jse;
|
||||||
|
|
||||||
@BeforeClass(alwaysRun = true) //Inicialización del navegador
|
@BeforeClass(alwaysRun = true) //Inicialización del navegador
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
DesiredCapabilities capabilities;
|
|
||||||
String browser = System.getProperty("browser");
|
String browser = System.getProperty("browser");
|
||||||
if (browser != null && browser.equalsIgnoreCase("firefox")) {
|
if (browser != null && browser.equalsIgnoreCase("firefox")) {
|
||||||
capabilities = DesiredCapabilities.firefox();
|
FirefoxOptions options = new FirefoxOptions();
|
||||||
System.setProperty("webdriver.gecko.driver",
|
System.setProperty("webdriver.gecko.driver",
|
||||||
"src" + File.separator + "main"
|
"src" + File.separator + "test"
|
||||||
+ File.separator + "resources"
|
+ File.separator + "resources"
|
||||||
+ File.separator + "geckodriver-macos");
|
+ File.separator + "geckodriver-macos");
|
||||||
driver = new FirefoxDriver(capabilities);
|
driver = new FirefoxDriver(options);
|
||||||
} else {
|
} else {
|
||||||
capabilities = DesiredCapabilities.chrome();
|
ChromeOptions options = new ChromeOptions();
|
||||||
System.setProperty("webdriver.chrome.driver", "src" + File.separator + "main" + File.separator + "resources" + File.separator + "chromedriver-macos");
|
System.setProperty("webdriver.chrome.driver", "src" + File.separator + "test" + File.separator + "resources" + File.separator + "chromedriver-macos");
|
||||||
driver = new ChromeDriver(capabilities);
|
driver = new ChromeDriver(options);
|
||||||
}
|
}
|
||||||
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
|
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
|
||||||
jse = (JavascriptExecutor) driver;
|
jse = (JavascriptExecutor) driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,4 +39,4 @@ public class BaseTest {
|
|||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
driver.quit();
|
driver.quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,5 @@ public class BasicAuth extends BaseTest {
|
|||||||
public void testApp() throws InterruptedException {
|
public void testApp() throws InterruptedException {
|
||||||
driver.navigate().to("https://admin:admin@the-internet.herokuapp.com/basic_auth");
|
driver.navigate().to("https://admin:admin@the-internet.herokuapp.com/basic_auth");
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,67 +3,87 @@ package com.agile611.testng.webdriver;
|
|||||||
import net.lightbody.bmp.BrowserMobProxy;
|
import net.lightbody.bmp.BrowserMobProxy;
|
||||||
import net.lightbody.bmp.BrowserMobProxyServer;
|
import net.lightbody.bmp.BrowserMobProxyServer;
|
||||||
import net.lightbody.bmp.client.ClientUtil;
|
import net.lightbody.bmp.client.ClientUtil;
|
||||||
|
import net.lightbody.bmp.core.har.Har;
|
||||||
import net.lightbody.bmp.core.har.HarEntry;
|
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.Proxy;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
import org.openqa.selenium.remote.CapabilityType;
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.AfterMethod;
|
import org.testng.annotations.AfterMethod;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
public class BrokenImages {
|
public class BrokenImages {
|
||||||
WebDriver driver;
|
WebDriver driver;
|
||||||
BrowserMobProxy proxy;
|
BrowserMobProxy proxy;
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
// 1. Iniciar el servidor Proxy localmente
|
||||||
proxy = new BrowserMobProxyServer();
|
proxy = new BrowserMobProxyServer();
|
||||||
proxy.start(0);
|
proxy.start(0); // El puerto 0 le dice que busque cualquier puerto libre
|
||||||
|
|
||||||
|
// 2. Crear el objeto Proxy de Selenium a partir del BrowserMob
|
||||||
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
|
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
|
||||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
|
||||||
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
|
// 3. Inyectar el proxy en las opciones de Firefox
|
||||||
|
FirefoxOptions options = new FirefoxOptions();
|
||||||
|
options.setProxy(seleniumProxy);
|
||||||
|
|
||||||
|
// Nota: Si usas Selenium 4.6+, esta línea ya no es necesaria gracias a Selenium Manager
|
||||||
System.setProperty("webdriver.gecko.driver",
|
System.setProperty("webdriver.gecko.driver",
|
||||||
"src" + File.separator + "main"
|
"src" + File.separator + "test"
|
||||||
+ File.separator + "resources"
|
+ File.separator + "resources"
|
||||||
+ File.separator + "geckodriver-macos");
|
+ File.separator + "geckodriver-macos");
|
||||||
driver = new FirefoxDriver(capabilities);
|
|
||||||
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
|
driver = new FirefoxDriver(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterMethod
|
@AfterMethod
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
proxy.stop();
|
// Es crucial apagar ambos servicios para no dejar procesos huérfanos
|
||||||
driver.quit();
|
if (driver != null) {
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
if (proxy != null) {
|
||||||
|
proxy.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allImagesLoaded() {
|
public void allImagesLoaded() {
|
||||||
proxy.newHar();
|
// 4. Iniciar la captura de un nuevo archivo HAR
|
||||||
|
proxy.newHar("captura_imagenes");
|
||||||
|
|
||||||
|
// 5. Navegar a la página (el proxy registrará todo el tráfico)
|
||||||
driver.navigate().to("http://the-internet.herokuapp.com/broken_images");
|
driver.navigate().to("http://the-internet.herokuapp.com/broken_images");
|
||||||
List<WebElement> images = driver.findElements(By.tagName("img"));
|
|
||||||
List brokenImages = new ArrayList();
|
// 6. Extraer el HAR generado
|
||||||
List<HarEntry> harEntries = proxy.getHar().getLog().getEntries();
|
Har har = proxy.getHar();
|
||||||
for (int entry = 0; entry < harEntries.size(); entry++) {
|
|
||||||
for (int image = 0; image < images.size(); image++) {
|
// 7. Analizar las entradas de red
|
||||||
if (harEntries.get(entry).getRequest().getUrl().equals(
|
boolean hasBrokenImages = false;
|
||||||
images.get(image).getAttribute("src"))
|
List<HarEntry> entries = har.getLog().getEntries();
|
||||||
& harEntries.get(entry).getResponse().getStatus() == 404)
|
|
||||||
brokenImages.add(images.get(image).getAttribute("src"));
|
for (HarEntry entry : entries) {
|
||||||
|
String url = entry.getRequest().getUrl();
|
||||||
|
int statusCode = entry.getResponse().getStatus();
|
||||||
|
|
||||||
|
// Filtramos para evaluar solo los recursos que son imágenes
|
||||||
|
if (url.endsWith(".jpg") || url.endsWith(".png") || url.endsWith(".gif")) {
|
||||||
|
if (statusCode == 404) {
|
||||||
|
System.err.println("❌ Imagen rota detectada (404): " + url);
|
||||||
|
hasBrokenImages = true;
|
||||||
|
} else {
|
||||||
|
System.out.println("✅ Imagen cargada correctamente (" + statusCode + "): " + url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List emptyCollection = new ArrayList();
|
// 8. El test fallará si al menos una imagen devolvió 404
|
||||||
assertThat(brokenImages, is(emptyCollection));
|
Assert.assertFalse(hasBrokenImages, "Se encontraron imágenes con error 404 en la página.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ChallengingDomTest extends BaseTest {
|
public class ChallengingDomTest extends BaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ package com.agile611.testng.webdriver;
|
|||||||
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.assertNull;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class CheckBoxesTest extends BaseTest {
|
public class CheckBoxesTest extends BaseTest {
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ public class DisappearingElementsTest extends BaseTest {
|
|||||||
public void testApp() throws InterruptedException {
|
public void testApp() throws InterruptedException {
|
||||||
driver.navigate().to("https://the-internet.herokuapp.com/disappearing_elements");
|
driver.navigate().to("https://the-internet.herokuapp.com/disappearing_elements");
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
System.out.println("Iteración: " + (i + 1));
|
||||||
WebElement elementsDelMenu =
|
WebElement elementsDelMenu =
|
||||||
driver.findElement(
|
driver.findElement(
|
||||||
By.xpath(".//*[@id='content']/div/ul/li[last()]"));
|
By.xpath(".//*[@id='content']/div/ul/li[last()]"));
|
||||||
|
|||||||
@@ -1,59 +1,64 @@
|
|||||||
package com.agile611.testng.webdriver;
|
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.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.hamcrest.core.Is.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.core.IsNot.not;
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
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.interactions.Actions;
|
||||||
|
import org.testng.annotations.AfterMethod;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class DownloadTest extends BaseTest {
|
public class DownloadTest extends BaseTest {
|
||||||
File folder;
|
File folder;
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
folder = new File("src" + File.separator + "main" + File.separator + "resources" + File.separator + UUID.randomUUID().toString());
|
folder = new File("src" + File.separator + "test" + 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();
|
String downloadFilepath = folder.getAbsolutePath();
|
||||||
|
|
||||||
|
//Chrome
|
||||||
|
System.setProperty("webdriver.chrome.driver", "src" + File.separator + "test" + File.separator + "resources" + File.separator + "chromedriver-macos");
|
||||||
|
|
||||||
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
|
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
|
||||||
chromePrefs.put("profile.default_content_settings.popups", 0);
|
chromePrefs.put("profile.default_content_settings.popups", 0);
|
||||||
chromePrefs.put("download.default_directory", downloadFilepath);
|
chromePrefs.put("download.default_directory", downloadFilepath);
|
||||||
ChromeOptions options = new ChromeOptions();
|
ChromeOptions options = new ChromeOptions();
|
||||||
options.setExperimentalOption("prefs", chromePrefs);
|
options.setExperimentalOption("prefs", chromePrefs);
|
||||||
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
|
options.setAcceptInsecureCerts(true);
|
||||||
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
|
//options.addArguments("--headless");
|
||||||
driver = new ChromeDriver(capabilities);
|
driver = new ChromeDriver(options);
|
||||||
|
|
||||||
//Firefox
|
//Firefox
|
||||||
/*DesiredCapabilities capabilities = DesiredCapabilities.firefox();
|
// 1. Configurar el perfil de Firefox
|
||||||
|
/*FirefoxProfile profile = new FirefoxProfile();
|
||||||
System.setProperty("webdriver.gecko.driver",
|
System.setProperty("webdriver.gecko.driver",
|
||||||
"src" + File.separator + "main"
|
"src" + File.separator + "test"
|
||||||
+ File.separator + "resources"
|
+ File.separator + "resources"
|
||||||
+ File.separator + "geckodriver-macos");
|
+ 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.neverAsk.saveToDisk", "application/octet-stream;application/csv;text/csv;application/vnd.ms-excel;");
|
||||||
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
|
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
|
||||||
profile.setPreference("browser.download.manager.showWhenStarting", false);
|
profile.setPreference("browser.download.manager.showWhenStarting", false);
|
||||||
profile.setPreference("browser.download.folderList", 2);
|
profile.setPreference("browser.download.folderList", 2);
|
||||||
profile.setPreference("browser.download.dir", folder.getAbsolutePath());
|
profile.setPreference("browser.download.dir", downloadFilepath);
|
||||||
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
|
|
||||||
driver = new FirefoxDriver(capabilities);*/
|
// 2. Usar FirefoxOptions en lugar de DesiredCapabilities
|
||||||
|
FirefoxOptions options = new FirefoxOptions();
|
||||||
|
options.setProfile(profile);
|
||||||
|
|
||||||
|
// Opcional: Si necesitas ejecutarlo en modo incógnito o sin interfaz gráfica (headless)
|
||||||
|
//options.addArguments("-headless");
|
||||||
|
|
||||||
|
// 3. Inicializar el driver
|
||||||
|
// NOTA: Ya no necesitas System.setProperty para el geckodriver.
|
||||||
|
driver = new FirefoxDriver(options);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterMethod
|
@AfterMethod
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.JavascriptExecutor;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class DragAndDropJavascriptTest extends BaseTest {
|
||||||
|
@Test
|
||||||
|
public void testAppConJS() throws InterruptedException {
|
||||||
|
driver.navigate().to("https://the-internet.herokuapp.com/drag_and_drop");
|
||||||
|
Thread.sleep(2000);
|
||||||
|
|
||||||
|
WebElement columnA = driver.findElement(By.id("column-a"));
|
||||||
|
WebElement columnB = driver.findElement(By.id("column-b"));
|
||||||
|
|
||||||
|
// Script JS que simula los eventos HTML5 drag & drop correctamente
|
||||||
|
String script =
|
||||||
|
"function simulateDragDrop(sourceNode, destinationNode) {" +
|
||||||
|
" var EVENT_TYPES = ['dragstart','dragenter','dragover','drop','dragend'];" +
|
||||||
|
" function createEvent(eventType) {" +
|
||||||
|
" var event = document.createEvent('CustomEvent');" +
|
||||||
|
" event.initCustomEvent(eventType, true, true, null);" +
|
||||||
|
" event.dataTransfer = { data: {}, setData: function(type, val) { this.data[type]=val; }, getData: function(type) { return this.data[type]; } };" +
|
||||||
|
" return event;" +
|
||||||
|
" }" +
|
||||||
|
" var dragEvent = createEvent('dragstart');" +
|
||||||
|
" sourceNode.dispatchEvent(dragEvent);" +
|
||||||
|
" destinationNode.dispatchEvent(createEvent('dragenter'));" +
|
||||||
|
" destinationNode.dispatchEvent(createEvent('dragover'));" +
|
||||||
|
" var dropEvent = createEvent('drop');" +
|
||||||
|
" dropEvent.dataTransfer = dragEvent.dataTransfer;" +
|
||||||
|
" destinationNode.dispatchEvent(dropEvent);" +
|
||||||
|
" sourceNode.dispatchEvent(createEvent('dragend'));" +
|
||||||
|
"}" +
|
||||||
|
"simulateDragDrop(arguments[0], arguments[1]);";
|
||||||
|
|
||||||
|
((JavascriptExecutor) driver).executeScript(script, columnA, columnB);
|
||||||
|
Thread.sleep(2000);
|
||||||
|
|
||||||
|
// Verificar el intercambio
|
||||||
|
assertEquals(driver.findElement(By.cssSelector("#column-a header")).getText(), "B");
|
||||||
|
assertEquals(driver.findElement(By.cssSelector("#column-b header")).getText(), "A");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,36 +3,32 @@ package com.agile611.testng.webdriver;
|
|||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.interactions.Actions;
|
import org.openqa.selenium.interactions.Actions;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class DragAndDropTest extends BaseTest {
|
public class DragAndDropTest extends BaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApp() throws InterruptedException {
|
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"));
|
|
||||||
|
|
||||||
|
driver.navigate().to("https://the-internet.herokuapp.com/drag_and_drop");
|
||||||
|
Thread.sleep(2000);
|
||||||
|
|
||||||
|
// Localizar los dos elementos con sus IDs reales
|
||||||
|
WebElement columnA = driver.findElement(By.id("column-a"));
|
||||||
|
WebElement columnB = driver.findElement(By.id("column-b"));
|
||||||
|
|
||||||
|
// Verificar estado inicial: A está a la izquierda, B a la derecha
|
||||||
|
assertEquals(columnA.findElement(By.tagName("header")).getText(), "A");
|
||||||
|
assertEquals(columnB.findElement(By.tagName("header")).getText(), "B");
|
||||||
|
|
||||||
|
// Arrastrar A sobre B (intercambiar posiciones)
|
||||||
Actions dragAndDrop = new Actions(driver);
|
Actions dragAndDrop = new Actions(driver);
|
||||||
dragAndDrop.dragAndDrop(draggable1, droppable1).perform();
|
dragAndDrop.dragAndDrop(columnA, columnB).perform();
|
||||||
Thread.sleep(4000);
|
Thread.sleep(2000);
|
||||||
dragAndDrop.dragAndDrop(draggable2, droppable2).perform();
|
|
||||||
Thread.sleep(4000);
|
|
||||||
|
|
||||||
|
// Verificar que han intercambiado: ahora A está donde estaba B y viceversa
|
||||||
/*
|
assertEquals(columnA.findElement(By.tagName("header")).getText(), "B");
|
||||||
dragAndDrop
|
assertEquals(columnB.findElement(By.tagName("header")).getText(), "A");
|
||||||
.clickAndHold(draggable2)
|
|
||||||
.moveToElement(droppable1)
|
|
||||||
.release().build().perform();
|
|
||||||
Thread.sleep(4000);
|
|
||||||
dragAndDrop
|
|
||||||
.clickAndHold(draggable2)
|
|
||||||
.moveToElement(droppable2)
|
|
||||||
.release().build().perform();
|
|
||||||
Thread.sleep(4000);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DropdownTest extends BaseTest {
|
public class DropdownTest extends BaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -14,11 +15,13 @@ public class DropdownTest extends BaseTest {
|
|||||||
.navigate().to("https://the-internet.herokuapp.com/dropdown");
|
.navigate().to("https://the-internet.herokuapp.com/dropdown");
|
||||||
List<WebElement> options =
|
List<WebElement> options =
|
||||||
driver.findElements(By.xpath(".//*[@id='dropdown']/option"));
|
driver.findElements(By.xpath(".//*[@id='dropdown']/option"));
|
||||||
|
|
||||||
for (int i = 1; i < options.size(); i++) {
|
for (int i = 1; i < options.size(); i++) {
|
||||||
WebElement option =
|
WebElement option =
|
||||||
driver.findElement(
|
driver.findElement(
|
||||||
By.xpath(".//*[@id='dropdown']/option[" + (i + 1) + "]"));
|
By.xpath(".//*[@id='dropdown']/option[" + (i + 1) + "]"));
|
||||||
option.click();
|
option.click();
|
||||||
|
assertTrue(option.isSelected());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.agile611.testng.webdriver.pages.ResultsPage;
|
||||||
|
import com.agile611.testng.webdriver.pages.SearchPage;
|
||||||
|
|
||||||
|
public class DuckDuckGoPagesTest extends BaseTest {
|
||||||
|
@Test
|
||||||
|
public void testUntitledTestCase() throws Exception {
|
||||||
|
SearchPage searchPage = new SearchPage(driver);
|
||||||
|
searchPage.searchKeyword("pizza hawaiana");
|
||||||
|
ResultsPage resultsPage = new ResultsPage(driver);
|
||||||
|
assertTrue(resultsPage.isResultsPagePresent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,18 +1,27 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
import com.agile611.testng.webdriver.pages.ResultsPage;
|
import org.openqa.selenium.WebElement;
|
||||||
import com.agile611.testng.webdriver.pages.SearchPage;
|
import org.openqa.selenium.support.FindBy;
|
||||||
import org.testng.annotations.*;
|
import org.openqa.selenium.support.PageFactory;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.testng.Assert.*;
|
public class DuckDuckGoTest extends BaseTest {
|
||||||
|
@FindBy(id = "searchbox_input")
|
||||||
|
public WebElement searchBox;
|
||||||
|
|
||||||
public class DuckDuckGoTest extends BaseSaucelabsTest {
|
@FindBy(className = "react-results--main")
|
||||||
@Test //El propio test que hemos exportado de Katalon IDE
|
public WebElement resultsList;
|
||||||
public void testUntitledTestCase() throws Exception {
|
|
||||||
SearchPage searchPage = new SearchPage(driver);
|
@Test
|
||||||
searchPage.searchKeyword("pizza hawaiana");
|
public void testSearch() throws Exception {
|
||||||
ResultsPage resultsPage = new ResultsPage(driver);
|
PageFactory.initElements(driver, this);
|
||||||
assertTrue(resultsPage.isResultsPagePresent());
|
driver.get("https://duckduckgo.com/");
|
||||||
|
Thread.sleep(2000);
|
||||||
|
searchBox.sendKeys("pizza hawaiana");
|
||||||
|
searchBox.submit();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
assertTrue(resultsList.isDisplayed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class DynamicContentTest extends BaseTest {
|
|||||||
By.xpath(".//*[@id='content']/div[3]/div[2]"));
|
By.xpath(".//*[@id='content']/div[3]/div[2]"));
|
||||||
String urlImatge1 = imatge1.getAttribute("src");
|
String urlImatge1 = imatge1.getAttribute("src");
|
||||||
String texttotal1 = text1.getText();
|
String texttotal1 = text1.getText();
|
||||||
driver.navigate().refresh();
|
driver.navigate().refresh(); //Regenero el DOM completo
|
||||||
imatge1 =
|
imatge1 =
|
||||||
driver.findElement(
|
driver.findElement(
|
||||||
By.xpath(".//*[@id='content']/div[3]/div[1]/img"));
|
By.xpath(".//*[@id='content']/div[3]/div[1]/img"));
|
||||||
|
|||||||
@@ -6,25 +6,25 @@ import org.openqa.selenium.WebElement;
|
|||||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
public class DynamicControlsTest extends BaseTest {
|
public class DynamicControlsTest extends BaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void titleTest() {
|
public void titleTest() throws InterruptedException {
|
||||||
driver.navigate().to("http://the-internet.herokuapp.com/dynamic_controls");
|
driver.navigate().to("http://the-internet.herokuapp.com/dynamic_controls");
|
||||||
WebElement checkbox = driver.findElement(By.id("checkbox"));
|
WebElement checkbox = driver.findElement(By.id("checkbox"));
|
||||||
assertTrue(checkbox.isDisplayed());
|
assertTrue(checkbox.isDisplayed());
|
||||||
checkbox.click();
|
checkbox.click();
|
||||||
WebElement removeBtn = driver.findElement(By.xpath("//*[@id='checkbox-example']/button"));
|
WebElement removeBtn = driver.findElement(By.xpath("//*[@id='checkbox-example']/button"));
|
||||||
removeBtn.click();
|
removeBtn.click();
|
||||||
List<WebElement> loading = driver.findElements(By.xpath("//*[@id='loading']/img"));
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
|
||||||
WebDriverWait wait = new WebDriverWait(driver, 20);
|
|
||||||
wait.until(ExpectedConditions.or(
|
wait.until(ExpectedConditions.or(
|
||||||
ExpectedConditions.presenceOfElementLocated(By.id("loading")),
|
ExpectedConditions.presenceOfElementLocated(By.id("loading")),
|
||||||
ExpectedConditions.presenceOfElementLocated(By.id("message"))));
|
ExpectedConditions.presenceOfElementLocated(By.id("message"))));
|
||||||
|
WebElement message = driver.findElement(By.id("message"));
|
||||||
|
assertTrue(message.isDisplayed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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 static org.testng.Assert.assertTrue;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class HoversImprovedTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hoversTest() throws InterruptedException {
|
||||||
|
driver.get("http://the-internet.herokuapp.com/hovers");
|
||||||
|
// Find and hover over desired element
|
||||||
|
List<WebElement> avatars = driver.findElements(By.xpath("//*[@id=\'content\']/div/div"));
|
||||||
|
|
||||||
|
for(int i= 1; i <= avatars.size(); i++){
|
||||||
|
WebElement avatar = driver.findElement(By.xpath("//*[@id=\'content\']/div/div["+i+"]/img"));
|
||||||
|
Actions builder = new Actions(driver);
|
||||||
|
builder.moveToElement(avatar).build().perform();
|
||||||
|
// Wait until the hover appears
|
||||||
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
|
||||||
|
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\'content\']/div/div["+i+"]/div/h5")));
|
||||||
|
// Assert that the hover displayed
|
||||||
|
assertTrue(driver.findElement(By.xpath("//*[@id=\'content\']/div/div["+i+"]/div/h5")).isDisplayed());
|
||||||
|
assertTrue(driver.findElement(By.xpath("//*[@id=\'content\']/div/div["+i+"]/div/h5")).getText().contains("name: user"+i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.interactions.Actions;
|
import org.openqa.selenium.interactions.Actions;
|
||||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
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;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class HoversTest extends BaseTest {
|
public class HoversTest extends BaseTest {
|
||||||
|
|
||||||
@@ -23,7 +22,7 @@ public class HoversTest extends BaseTest {
|
|||||||
builder.moveToElement(avatar).build().perform();
|
builder.moveToElement(avatar).build().perform();
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
// Wait until the hover appears
|
// Wait until the hover appears
|
||||||
WebDriverWait wait = new WebDriverWait(driver, 5);
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
|
||||||
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("figcaption")));
|
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("figcaption")));
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
// Assert that the hover displayed
|
// Assert that the hover displayed
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public class InfiniteScrollTest extends BaseTest {
|
|||||||
public void infiniteScrollTest() throws InterruptedException {
|
public void infiniteScrollTest() throws InterruptedException {
|
||||||
driver.navigate().to("http://the-internet.herokuapp.com/infinite_scroll");
|
driver.navigate().to("http://the-internet.herokuapp.com/infinite_scroll");
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
|
System.out.println("Iteración: " + (i + 1));
|
||||||
jse.executeScript("window.scrollTo(0, document.body.scrollHeight);");
|
jse.executeScript("window.scrollTo(0, document.body.scrollHeight);");
|
||||||
Thread.sleep(2500);
|
Thread.sleep(2500);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.agile611.testng.webdriver;
|
|||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class InterrogationTest extends BaseSaucelabsTest {
|
public class InterrogationTest extends BaseTest {
|
||||||
@Test //Opciones de Navegación
|
@Test //Opciones de Navegación
|
||||||
public void testNavigation() throws Exception {
|
public void testNavigation() throws Exception {
|
||||||
driver.get("https://www.duckduckgo.com/"); //Navegar hasta duckduckgo
|
driver.get("https://www.duckduckgo.com/"); //Navegar hasta duckduckgo
|
||||||
|
|||||||
@@ -2,23 +2,25 @@ package com.agile611.testng.webdriver;
|
|||||||
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.Keys;
|
import org.openqa.selenium.Keys;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.interactions.Actions;
|
import org.openqa.selenium.interactions.Actions;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
import org.testng.annotations.Test;
|
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 {
|
public class KeyboardKeysTest extends BaseTest {
|
||||||
@Test
|
@Test
|
||||||
public void KeyboardKeysExample() throws InterruptedException {
|
public void KeyboardKeysExample() throws InterruptedException {
|
||||||
driver.get("http://the-internet.herokuapp.com/key_presses");
|
driver.get("http://the-internet.herokuapp.com/key_presses");
|
||||||
Actions builder = new Actions(driver);
|
Actions builder = new Actions(driver);
|
||||||
builder.sendKeys(Keys.SPACE).build().perform();
|
builder.sendKeys(Keys.SPACE).build().perform();
|
||||||
Thread.sleep(2000);
|
|
||||||
assertTrue(driver.findElement(By.id("result")).getText().equalsIgnoreCase("You entered: SPACE"));
|
assertTrue(driver.findElement(By.id("result")).getText().equalsIgnoreCase("You entered: SPACE"));
|
||||||
builder.sendKeys(Keys.LEFT).build().perform();
|
builder.sendKeys(Keys.LEFT).build().perform();
|
||||||
Thread.sleep(2000);
|
|
||||||
assertTrue(driver.findElement(By.id("result")).getText().equalsIgnoreCase("You entered: LEFT"));
|
assertTrue(driver.findElement(By.id("result")).getText().equalsIgnoreCase("You entered: LEFT"));
|
||||||
|
|
||||||
|
WebElement textBox = driver.findElement(By.id("target"));
|
||||||
|
textBox.click();
|
||||||
|
textBox.sendKeys("Hello World");
|
||||||
|
textBox.sendKeys(Keys.ESCAPE);
|
||||||
|
assertTrue(driver.findElement(By.id("result")).getText().equalsIgnoreCase("You entered: ESCAPE"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
13
src/test/java/com/agile611/testng/webdriver/LoginTest.java
Normal file
13
src/test/java/com/agile611/testng/webdriver/LoginTest.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class LoginTest extends BaseRemoteWebDriverTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApp() throws InterruptedException {
|
||||||
|
driver.navigate().to("https://www.duckduckgo.com");
|
||||||
|
Thread.sleep(5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,22 +1,33 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.interactions.Actions;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class ManipulationTest extends BaseSaucelabsTest {
|
public class ManipulationTest extends BaseTest {
|
||||||
@Test //Opciones de Navegación
|
@Test //Opciones de Navegación
|
||||||
public void testNavigation() throws Exception {
|
public void testNavigation() throws Exception {
|
||||||
driver.get("https://www.duckduckgo.com/"); //Navegar hasta duckduckgo
|
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("searchbox_input")).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("searchbox_input")).sendKeys("pizza hawaiana"); //Escribir en el text box
|
||||||
driver.findElement(By.id("search_form_homepage")).submit(); //Submit, darle al enter.
|
driver.findElement(By.id("searchbox_input")).submit(); //Submit, darle al enter.
|
||||||
Thread.sleep(2000); //Espera forzada
|
Thread.sleep(2000); //Espera forzada
|
||||||
|
WebElement resultsList = driver.findElement(By.className("react-results--main")); //Comprobar que el resultado se muestra
|
||||||
|
assertTrue(resultsList.isDisplayed());
|
||||||
|
|
||||||
|
|
||||||
driver.get("https://www.duckduckgo.com/"); //Navegar hasta duckduckgo
|
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("searchbox_input")).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("searchbox_input")).sendKeys("tortellini al pesto");
|
||||||
driver.findElement(By.id("search_button_homepage")).click(); //click a la lupa.
|
|
||||||
Thread.sleep(2000); //Espera forzada
|
Thread.sleep(2000); //Espera forzada
|
||||||
|
Actions builder = new Actions(driver);
|
||||||
|
WebElement searchButton = driver.findElement(By.xpath(".//button[@data-mode=\'search\']")); //Click en el text box, no hace nada pero es para mostrar la diferencia entre submit y click.
|
||||||
|
builder.moveToElement(searchButton).click().build().perform(); //Click en el botón de búsqueda, esto es diferente a submit, ya que submit solo funciona con formularios, mientras que click funciona con cualquier elemento.
|
||||||
|
Thread.sleep(2000); //Espera forzada
|
||||||
|
resultsList = driver.findElement(By.className("react-results--main")); //Comprobar que el resultado se muestra
|
||||||
|
assertTrue(resultsList.isDisplayed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
117
src/test/java/com/agile611/testng/webdriver/MarcaHARTest.java
Normal file
117
src/test/java/com/agile611/testng/webdriver/MarcaHARTest.java
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
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.Har;
|
||||||
|
import net.lightbody.bmp.core.har.HarEntry;
|
||||||
|
import net.lightbody.bmp.core.har.HarNameValuePair;
|
||||||
|
import net.lightbody.bmp.core.har.HarRequest;
|
||||||
|
import net.lightbody.bmp.core.har.HarResponse;
|
||||||
|
|
||||||
|
import org.openqa.selenium.Proxy;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||||
|
import org.testng.annotations.AfterMethod;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MarcaHARTest {
|
||||||
|
WebDriver driver;
|
||||||
|
BrowserMobProxy proxy;
|
||||||
|
|
||||||
|
@BeforeMethod
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
// 1. Iniciar el servidor Proxy localmente
|
||||||
|
proxy = new BrowserMobProxyServer();
|
||||||
|
proxy.start(0); // El puerto 0 le dice que busque cualquier puerto libre
|
||||||
|
|
||||||
|
// 2. Crear el objeto Proxy de Selenium a partir del BrowserMob
|
||||||
|
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
|
||||||
|
|
||||||
|
// 3. Inyectar el proxy en las opciones de Firefox
|
||||||
|
FirefoxOptions options = new FirefoxOptions();
|
||||||
|
options.setProxy(seleniumProxy);
|
||||||
|
|
||||||
|
// Nota: Si usas Selenium 4.6+, esta línea ya no es necesaria gracias a Selenium Manager
|
||||||
|
System.setProperty("webdriver.gecko.driver",
|
||||||
|
"src" + File.separator + "test"
|
||||||
|
+ File.separator + "resources"
|
||||||
|
+ File.separator + "geckodriver-macos");
|
||||||
|
|
||||||
|
driver = new FirefoxDriver(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterMethod
|
||||||
|
public void tearDown() {
|
||||||
|
// Es crucial apagar ambos servicios para no dejar procesos huérfanos
|
||||||
|
if (driver != null) {
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
if (proxy != null) {
|
||||||
|
proxy.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void allImagesLoaded() throws InterruptedException {
|
||||||
|
// 4. Iniciar la captura de un nuevo archivo HAR
|
||||||
|
proxy.newHar("captura_imagenes");
|
||||||
|
|
||||||
|
// 5. Navegar a la página (el proxy registrará todo el tráfico)
|
||||||
|
driver.navigate().to("http://www.marca.com");
|
||||||
|
|
||||||
|
// 6. Extraer el HAR generado
|
||||||
|
Har har = proxy.getHar();
|
||||||
|
|
||||||
|
// 7. Analizar las entradas de red
|
||||||
|
List<HarEntry> entries = har.getLog().getEntries();
|
||||||
|
Thread.sleep(15000);
|
||||||
|
|
||||||
|
for (HarEntry entry : entries) {
|
||||||
|
HarRequest request = entry.getRequest();
|
||||||
|
HarResponse response = entry.getResponse();
|
||||||
|
|
||||||
|
System.out.println("==================================================");
|
||||||
|
System.out.println("🌐 URL: " + request.getUrl());
|
||||||
|
System.out.println("▶️ Método HTTP: " + request.getMethod());
|
||||||
|
System.out.println("◀️ Código de Estado: " + response.getStatus() + " " + response.getStatusText());
|
||||||
|
System.out.println("⏱️ Tiempo Total: " + entry.getTime() + " ms");
|
||||||
|
|
||||||
|
// 1. Extraer Cabeceras de la Petición (Request Headers)
|
||||||
|
System.out.println("\n📦 CABECERAS DE PETICIÓN:");
|
||||||
|
for (HarNameValuePair header : request.getHeaders()) {
|
||||||
|
System.out.println(" - " + header.getName() + ": " + header.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Extraer Cabeceras de la Respuesta (Response Headers)
|
||||||
|
System.out.println("\n📥 CABECERAS DE RESPUESTA:");
|
||||||
|
for (HarNameValuePair header : response.getHeaders()) {
|
||||||
|
System.out.println(" - " + header.getName() + ": " + header.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Extraer Información del Contenido
|
||||||
|
System.out.println("\n📄 DETALLES DEL CONTENIDO:");
|
||||||
|
System.out.println(" - Tipo MIME: " + response.getContent().getMimeType());
|
||||||
|
System.out.println(" - Tamaño del cuerpo: " + response.getContent().getSize() + " bytes");
|
||||||
|
|
||||||
|
// Opcional: Imprimir el texto de la respuesta (Cuidado, puede ser muy largo para HTML/JS)
|
||||||
|
// if (response.getContent().getText() != null) {
|
||||||
|
// System.out.println(" - Contenido: " + response.getContent().getText().substring(0, Math.min(response.getContent().getText().length(), 100)) + "...");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 4. Extraer Tiempos de Red (Timings)
|
||||||
|
System.out.println("\n⏳ DESGLOSE DE TIEMPOS:");
|
||||||
|
System.out.println(" - Bloqueado (Blocked): " + entry.getTimings().getBlocked() + " ms");
|
||||||
|
System.out.println(" - Resolución DNS: " + entry.getTimings().getDns() + " ms");
|
||||||
|
System.out.println(" - Conexión: " + entry.getTimings().getConnect() + " ms");
|
||||||
|
System.out.println(" - Espera al servidor (TTFB): " + entry.getTimings().getWait() + " ms");
|
||||||
|
System.out.println(" - Descarga de datos (Receive): " + entry.getTimings().getReceive() + " ms");
|
||||||
|
System.out.println("==================================================\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,54 +1,84 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
import java.time.Duration;
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
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 MultipleWindowsTest extends BaseTest {
|
public class MultipleWindowsTest extends BaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multipleWindows() {
|
public void multipleWindows() throws InterruptedException {
|
||||||
driver.get("http://the-internet.herokuapp.com/windows");
|
driver.get("http://the-internet.herokuapp.com/windows");
|
||||||
driver.findElement(By.cssSelector(".example a")).click();
|
|
||||||
Object[] allWindows = driver.getWindowHandles().toArray();
|
String originalWindow = driver.getWindowHandle();
|
||||||
driver.switchTo().window(allWindows[0].toString());
|
|
||||||
assertThat(driver.getTitle(), is(not("New Window")));
|
driver.findElement(By.xpath("//a[@href=\'/windows/new\']")).click();
|
||||||
driver.switchTo().window(allWindows[1].toString());
|
|
||||||
assertThat(driver.getTitle(), is("New Window"));
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
|
||||||
|
Thread.sleep(3000); // Temas del Firefox
|
||||||
|
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
|
||||||
|
// numberOfWindowsToBe de Firefox no se interpreta bien, por eso el sleep
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
String newWindow = "";
|
||||||
|
for (String handle : driver.getWindowHandles()) {
|
||||||
|
if (!handle.equals(originalWindow)) {
|
||||||
|
newWindow = handle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verificar ventana original
|
||||||
|
driver.switchTo().window(originalWindow);
|
||||||
|
assertThat(driver.getTitle(), is(not(equalTo("New Window"))));
|
||||||
|
|
||||||
|
// Verificar nueva ventana
|
||||||
|
driver.switchTo().window(newWindow);
|
||||||
|
assertThat(driver.getTitle(), is(equalTo("New Window")));
|
||||||
|
|
||||||
|
// ✅ Cerrar la ventana nueva y volver a la original
|
||||||
|
driver.close();
|
||||||
|
driver.switchTo().window(originalWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(dependsOnMethods = "multipleWindows")
|
||||||
public void multipleWindowsRedux() {
|
public void multipleWindowsRedux() throws InterruptedException {
|
||||||
driver.get("http://the-internet.herokuapp.com/windows");
|
driver.get("http://the-internet.herokuapp.com/windows");
|
||||||
|
|
||||||
// Get initial window handle
|
|
||||||
String firstWindow = driver.getWindowHandle();
|
String firstWindow = driver.getWindowHandle();
|
||||||
// Create a newWindow variable
|
|
||||||
String newWindow = "";
|
String newWindow = "";
|
||||||
// Trigger new window to open
|
|
||||||
driver.findElement(By.cssSelector(".example a")).click();
|
driver.findElement(By.cssSelector(".example a")).click();
|
||||||
// Grab all window handles
|
|
||||||
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
|
||||||
|
Thread.sleep(3000); // Temas de tiempos del Firefox
|
||||||
|
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
|
||||||
|
// numberOfWindowsToBe de Firefox no se interpreta bien, por eso el sleep
|
||||||
|
|
||||||
Set<String> allWindows = driver.getWindowHandles();
|
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) {
|
for (String window : allWindows) {
|
||||||
if (!window.equals(firstWindow)) {
|
if (!window.equals(firstWindow)) {
|
||||||
newWindow = window;
|
newWindow = window;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to the first window & verify
|
|
||||||
driver.switchTo().window(firstWindow);
|
driver.switchTo().window(firstWindow);
|
||||||
assertThat(driver.getTitle(), is(not(equalTo("New Window"))));
|
assertThat(driver.getTitle(), is(not(equalTo("New Window"))));
|
||||||
|
|
||||||
// Switch to the new window & verify
|
|
||||||
driver.switchTo().window(newWindow);
|
driver.switchTo().window(newWindow);
|
||||||
assertThat(driver.getTitle(), is(equalTo("New Window")));
|
assertThat(driver.getTitle(), is(equalTo("New Window")));
|
||||||
}
|
|
||||||
|
|
||||||
}
|
// ✅ Cerrar la ventana nueva y volver a la original
|
||||||
|
driver.close();
|
||||||
|
driver.switchTo().window(firstWindow);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class NavigationTest extends BaseSaucelabsTest {
|
public class NavigationTest extends BaseTest {
|
||||||
@Test //Opciones de Navegación
|
@Test //Opciones de Navegación
|
||||||
public void testNavigation() throws Exception {
|
public void testNavigation() throws Exception {
|
||||||
driver.get("https://www.duckduckgo.com/"); //Navegar hasta duckduckgo
|
driver.get("https://www.duckduckgo.com/"); //Navegar hasta duckduckgo
|
||||||
@@ -19,6 +18,4 @@ public class NavigationTest extends BaseSaucelabsTest {
|
|||||||
driver.navigate().refresh(); //Refrescar Yahoo
|
driver.navigate().refresh(); //Refrescar Yahoo
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,78 +1,170 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
import org.openqa.selenium.Proxy;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
import org.openqa.selenium.remote.CapabilityType;
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.AfterMethod;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.openqa.selenium.Proxy;
|
||||||
|
|
||||||
import net.lightbody.bmp.BrowserMobProxy;
|
import net.lightbody.bmp.BrowserMobProxy;
|
||||||
import net.lightbody.bmp.BrowserMobProxyServer;
|
import net.lightbody.bmp.BrowserMobProxyServer;
|
||||||
import net.lightbody.bmp.client.ClientUtil;
|
import net.lightbody.bmp.client.ClientUtil;
|
||||||
import net.lightbody.bmp.core.har.Har;
|
import net.lightbody.bmp.core.har.Har;
|
||||||
import net.lightbody.bmp.proxy.CaptureType;
|
import net.lightbody.bmp.core.har.HarEntry;
|
||||||
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 {
|
public class StatusCodesTest {
|
||||||
WebDriver driver;
|
WebDriver driver;
|
||||||
BrowserMobProxy proxy;
|
BrowserMobProxy proxy;
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
|
// 1. Iniciar el servidor Proxy localmente
|
||||||
proxy = new BrowserMobProxyServer();
|
proxy = new BrowserMobProxyServer();
|
||||||
proxy.start(0);
|
proxy.start(0); // El puerto 0 le dice que busque cualquier puerto libre
|
||||||
|
|
||||||
|
// 2. Crear el objeto Proxy de Selenium a partir del BrowserMob
|
||||||
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
|
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
|
||||||
DesiredCapabilities capabilities = new DesiredCapabilities();
|
|
||||||
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
|
// 3. Inyectar el proxy en las opciones de Firefox
|
||||||
|
FirefoxOptions options = new FirefoxOptions();
|
||||||
|
options.setProxy(seleniumProxy);
|
||||||
|
|
||||||
|
// Nota: Si usas Selenium 4.6+, esta línea ya no es necesaria gracias a Selenium Manager
|
||||||
System.setProperty("webdriver.gecko.driver",
|
System.setProperty("webdriver.gecko.driver",
|
||||||
"src" + File.separator + "main"
|
"src" + File.separator + "test"
|
||||||
+ File.separator + "resources"
|
+ File.separator + "resources"
|
||||||
+ File.separator + "geckodriver-macos");
|
+ File.separator + "geckodriver-macos");
|
||||||
driver = new FirefoxDriver(capabilities);
|
|
||||||
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
|
driver = new FirefoxDriver(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterMethod
|
@AfterMethod
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
proxy.stop();
|
// Es crucial apagar ambos servicios para no dejar procesos huérfanos
|
||||||
driver.quit();
|
if (driver != null) {
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
if (proxy != null) {
|
||||||
|
proxy.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ResourceNotFound404() {
|
public void ResourceNotFound404() {
|
||||||
proxy.newHar();
|
// 4. Iniciar la captura de un nuevo archivo HAR
|
||||||
|
proxy.newHar("captura_404");
|
||||||
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/404");
|
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/404");
|
||||||
|
|
||||||
|
// 6. Extraer el HAR generado
|
||||||
Har har = proxy.getHar();
|
Har har = proxy.getHar();
|
||||||
assertThat(har.getLog().getEntries().get(0).getResponse().getStatus(), is(404));
|
|
||||||
|
// 7. Analizar las entradas de red
|
||||||
|
boolean hasError404 = false;
|
||||||
|
List<HarEntry> entries = har.getLog().getEntries();
|
||||||
|
|
||||||
|
for (HarEntry entry : entries) {
|
||||||
|
String url = entry.getRequest().getUrl();
|
||||||
|
int statusCode = entry.getResponse().getStatus();
|
||||||
|
|
||||||
|
// Filtramos para evaluar solo los recursos que son imágenes
|
||||||
|
if (statusCode == 404) {
|
||||||
|
System.err.println("❌ 404 Detectado: " + url);
|
||||||
|
hasError404 = true;
|
||||||
|
} else {
|
||||||
|
System.out.println("✅ Recurso cargado correctamente (" + statusCode + "): " + url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 8. El test fallará si al menos una imagen devolvió 404
|
||||||
|
Assert.assertTrue(hasError404, "Se encontraron recursos con error 404 en la página.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ResourceFound200() {
|
public void ResourceFound200() {
|
||||||
proxy.newHar();
|
// 4. Iniciar la captura de un nuevo archivo HAR
|
||||||
|
proxy.newHar("captura_200");
|
||||||
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/200");
|
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/200");
|
||||||
|
|
||||||
|
// 6. Extraer el HAR generado
|
||||||
Har har = proxy.getHar();
|
Har har = proxy.getHar();
|
||||||
assertThat(har.getLog().getEntries().get(0).getResponse().getStatus(), is(200));
|
|
||||||
|
// 7. Analizar las entradas de red
|
||||||
|
boolean hasError200 = false;
|
||||||
|
List<HarEntry> entries = har.getLog().getEntries();
|
||||||
|
|
||||||
|
for (HarEntry entry : entries) {
|
||||||
|
String url = entry.getRequest().getUrl();
|
||||||
|
int statusCode = entry.getResponse().getStatus();
|
||||||
|
|
||||||
|
// Filtramos para evaluar solo los recursos que son imágenes
|
||||||
|
if (statusCode == 200) {
|
||||||
|
System.err.println("✅ 200 Detectado: " + url);
|
||||||
|
hasError200 = true;
|
||||||
|
} else {
|
||||||
|
System.out.println("❌ Recurso NO cargado correctamente (" + statusCode + "): " + url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Assert.assertTrue(hasError200, "Se encontraron recursos con 200 en la página.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ResourceRedirect301() {
|
public void ResourceRedirect301() {
|
||||||
proxy.newHar();
|
// 4. Iniciar la captura de un nuevo archivo HAR
|
||||||
|
proxy.newHar("captura_301");
|
||||||
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/301");
|
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/301");
|
||||||
|
|
||||||
|
// 6. Extraer el HAR generado
|
||||||
Har har = proxy.getHar();
|
Har har = proxy.getHar();
|
||||||
assertThat(har.getLog().getEntries().get(0).getResponse().getStatus(), is(301));
|
|
||||||
|
// 7. Analizar las entradas de red
|
||||||
|
boolean hasError301 = false;
|
||||||
|
List<HarEntry> entries = har.getLog().getEntries();
|
||||||
|
|
||||||
|
for (HarEntry entry : entries) {
|
||||||
|
String url = entry.getRequest().getUrl();
|
||||||
|
int statusCode = entry.getResponse().getStatus();
|
||||||
|
|
||||||
|
// Filtramos para evaluar solo los recursos que son imágenes
|
||||||
|
if (statusCode == 301) {
|
||||||
|
System.err.println("✅ 301 Detectado: " + url);
|
||||||
|
hasError301 = true;
|
||||||
|
} else {
|
||||||
|
System.out.println("❌ Recurso NO cargado correctamente (" + statusCode + "): " + url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Assert.assertTrue(hasError301, "Se encontraron recursos con 301 en la página.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ResourceError500() {
|
public void ResourceError500() {
|
||||||
proxy.newHar();
|
// 4. Iniciar la captura de un nuevo archivo HAR
|
||||||
|
proxy.newHar("captura_500");
|
||||||
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/500");
|
driver.navigate().to("http://the-internet.herokuapp.com/status_codes/500");
|
||||||
|
|
||||||
|
// 6. Extraer el HAR generado
|
||||||
Har har = proxy.getHar();
|
Har har = proxy.getHar();
|
||||||
assertThat(har.getLog().getEntries().get(0).getResponse().getStatus(), is(500));
|
|
||||||
|
// 7. Analizar las entradas de red
|
||||||
|
boolean hasError500 = false;
|
||||||
|
List<HarEntry> entries = har.getLog().getEntries();
|
||||||
|
|
||||||
|
for (HarEntry entry : entries) {
|
||||||
|
String url = entry.getRequest().getUrl();
|
||||||
|
int statusCode = entry.getResponse().getStatus();
|
||||||
|
|
||||||
|
// Filtramos para evaluar solo los recursos que son imágenes
|
||||||
|
if (statusCode == 500) {
|
||||||
|
System.err.println("✅ 500 Detectado: " + url);
|
||||||
|
hasError500 = true;
|
||||||
|
} else {
|
||||||
|
System.out.println("❌ Recurso NO cargado correctamente (" + statusCode + "): " + url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Assert.assertTrue(hasError500, "Se encontraron recursos con 500 en la página.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
import com.agile611.testng.webdriver.BaseTest;
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package com.agile611.testng.webdriver;
|
package com.agile611.testng.webdriver;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import static org.testng.AssertJUnit.assertTrue;
|
import static org.testng.AssertJUnit.assertTrue;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class UploadTest extends BaseTest {
|
public class UploadTest extends BaseTest {
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ public class UploadTest extends BaseTest {
|
|||||||
WebElement buttonUpload = driver.findElement(By.id("file-submit"));
|
WebElement buttonUpload = driver.findElement(By.id("file-submit"));
|
||||||
buttonUpload.click();
|
buttonUpload.click();
|
||||||
WebElement uploadedFiles = driver.findElement(By.id("uploaded-files"));
|
WebElement uploadedFiles = driver.findElement(By.id("uploaded-files"));
|
||||||
WebDriverWait wait = new WebDriverWait(driver, 20);
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
|
||||||
wait.until(ExpectedConditions.visibilityOf(uploadedFiles));
|
wait.until(ExpectedConditions.visibilityOf(uploadedFiles));
|
||||||
assertTrue(uploadedFiles.isDisplayed());
|
assertTrue(uploadedFiles.isDisplayed());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class ResultsPage {
|
|||||||
|
|
||||||
private WebDriver driver;
|
private WebDriver driver;
|
||||||
|
|
||||||
@FindBy(id = "links_wrapper")
|
@FindBy(className = "react-results--main")
|
||||||
public WebElement resultsList;
|
public WebElement resultsList;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,9 @@ public class SearchPage {
|
|||||||
|
|
||||||
private WebDriver driver;
|
private WebDriver driver;
|
||||||
|
|
||||||
@FindBy(id = "search_form_input_homepage")
|
@FindBy(id = "searchbox_input")
|
||||||
public WebElement searchBox;
|
public WebElement searchBox;
|
||||||
|
|
||||||
|
|
||||||
@FindBy(id = "search_button_homepage")
|
|
||||||
public WebElement searchButton;
|
|
||||||
|
|
||||||
|
|
||||||
public SearchPage(WebDriver driver) {
|
public SearchPage(WebDriver driver) {
|
||||||
PageFactory.initElements(driver, this);
|
PageFactory.initElements(driver, this);
|
||||||
driver.get("https://duckduckgo.com/");
|
driver.get("https://duckduckgo.com/");
|
||||||
@@ -25,6 +20,6 @@ public class SearchPage {
|
|||||||
public void searchKeyword(String keyword) {
|
public void searchKeyword(String keyword) {
|
||||||
searchBox.clear();
|
searchBox.clear();
|
||||||
searchBox.sendKeys(keyword);
|
searchBox.sendKeys(keyword);
|
||||||
searchButton.click();
|
searchBox.submit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
BIN
src/test/resources/chromedriver.exe
Normal file → Executable file
BIN
src/test/resources/chromedriver.exe
Normal file → Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
src/test/resources/geckodriver.exe
Executable file → Normal file
BIN
src/test/resources/geckodriver.exe
Executable file → Normal file
Binary file not shown.
Reference in New Issue
Block a user