RemoteWebDriver
This commit is contained in:
@@ -4,9 +4,9 @@ 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.remote.RemoteWebDriver;
|
||||
import org.openqa.selenium.safari.SafariOptions;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
@@ -16,16 +16,14 @@ public class BaseRemoteWebDriverTest {
|
||||
public void setUp() throws Exception {
|
||||
String browser = System.getProperty("browser");
|
||||
// Extraemos la URL para mantener el código DRY (Don't Repeat Yourself)
|
||||
URL gridUrl = new URL("http://0.0.0.0:4444/wd/hub");
|
||||
URL gridUrl = new URL("http://54.38.78.222:4444/wd/hub");
|
||||
|
||||
if (browser != null && browser.equalsIgnoreCase("chrome")) {
|
||||
ChromeOptions options = new ChromeOptions();
|
||||
driver = new RemoteWebDriver(gridUrl, options);
|
||||
|
||||
} else if (browser != null && browser.equalsIgnoreCase("safari")) {
|
||||
SafariOptions options = new SafariOptions();
|
||||
// Aquí podrías añadir configuraciones específicas si lo necesitas
|
||||
// options.setUseTechnologyPreview(true);
|
||||
} else if (browser != null && browser.equalsIgnoreCase("edge")) {
|
||||
EdgeOptions options = new EdgeOptions();
|
||||
driver = new RemoteWebDriver(gridUrl, options);
|
||||
|
||||
} else {
|
||||
@@ -33,7 +31,6 @@ public class BaseRemoteWebDriverTest {
|
||||
FirefoxOptions options = new FirefoxOptions();
|
||||
driver = new RemoteWebDriver(gridUrl, options);
|
||||
}
|
||||
|
||||
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.agile611.testng.webdriver;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
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 DuckDuckGoRemoteTest extends BaseRemoteWebDriverTest {
|
||||
@FindBy(id = "searchbox_input")
|
||||
public WebElement searchBox;
|
||||
|
||||
@FindBy(className = "react-results--main")
|
||||
public WebElement resultsList;
|
||||
|
||||
public void waitPageToLoad(RemoteWebDriver driver, long secondsTimeout, WebElement webElement){
|
||||
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(secondsTimeout));
|
||||
wait.until(ExpectedConditions.elementToBeClickable(webElement));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUntitledTestCase() throws Exception {
|
||||
driver.get("https://duckduckgo.com/");
|
||||
waitPageToLoad(driver, 10, searchBox);
|
||||
searchBox.sendKeys("pizza hawaiana");
|
||||
searchBox.submit();
|
||||
waitPageToLoad(driver, 10, resultsList);
|
||||
assertTrue(resultsList.isDisplayed());
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ services:
|
||||
- SE_EVENT_BUS_HOST=selenium-hub
|
||||
- SE_EVENT_BUS_PUBLISH_PORT=4442
|
||||
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
|
||||
- VNC_NO_PASSWORD=1
|
||||
restart: unless-stopped
|
||||
|
||||
firefox-node:
|
||||
@@ -30,6 +31,7 @@ services:
|
||||
- SE_EVENT_BUS_HOST=selenium-hub
|
||||
- SE_EVENT_BUS_PUBLISH_PORT=4442
|
||||
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
|
||||
- VNC_NO_PASSWORD=1
|
||||
restart: unless-stopped
|
||||
|
||||
edge-node:
|
||||
@@ -42,4 +44,5 @@ services:
|
||||
- SE_EVENT_BUS_HOST=selenium-hub
|
||||
- SE_EVENT_BUS_PUBLISH_PORT=4442
|
||||
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
|
||||
- VNC_NO_PASSWORD=1
|
||||
restart: unless-stopped
|
||||
|
||||
Reference in New Issue
Block a user