use of org.openqa.selenium.remote.RemoteWebDriver in project testcontainers-java by testcontainers.
the class BaseWebDriverContainerTest method doSimpleExplore.
protected static void doSimpleExplore(BrowserWebDriverContainer rule) {
RemoteWebDriver driver = setupDriverFromRule(rule);
driver.get("http://en.wikipedia.org/wiki/Randomness");
// Oh! The irony!
assertTrue("Randomness' description has the word 'pattern'", driver.findElementByPartialLinkText("pattern").isDisplayed());
}
use of org.openqa.selenium.remote.RemoteWebDriver in project testcontainers-java by testcontainers.
the class BaseWebDriverContainerTest method doSimpleWebdriverTest.
protected void doSimpleWebdriverTest(BrowserWebDriverContainer rule) {
RemoteWebDriver driver = setupDriverFromRule(rule);
System.out.println("Selenium remote URL is: " + rule.getSeleniumAddress());
System.out.println("VNC URL is: " + rule.getVncAddress());
// Runtime.getRuntime().exec("open " + rule.getVncUrl(driver)); // For debugging, on a Mac
driver.get("http://www.google.com");
driver.findElement(By.name("q")).sendKeys("testcontainers");
driver.findElement(By.name("q")).submit();
assertEquals("the word 'testcontainers' appears in the search box", "testcontainers", driver.findElement(By.name("q")).getAttribute("value"));
}
use of org.openqa.selenium.remote.RemoteWebDriver in project cerberus-source by cerberustesting.
the class SeleniumServerService method getIPOfNode.
private static void getIPOfNode(TestCaseExecution tCExecution) {
try {
Session session = tCExecution.getSession();
HttpCommandExecutor ce = (HttpCommandExecutor) ((RemoteWebDriver) session.getDriver()).getCommandExecutor();
SessionId sessionId = ((RemoteWebDriver) session.getDriver()).getSessionId();
String hostName = ce.getAddressOfRemoteServer().getHost();
int port = ce.getAddressOfRemoteServer().getPort();
HttpHost host = new HttpHost(hostName, port);
HttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
URL sessionURL = new URL(SeleniumServerService.getBaseUrl(session.getHost(), session.getPort()) + "/grid/api/testsession?session=" + sessionId);
BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm());
HttpResponse response = client.execute(host, r);
if (!response.getStatusLine().toString().contains("403") && !response.getEntity().getContentType().getValue().contains("text/html")) {
InputStream contents = response.getEntity().getContent();
StringWriter writer = new StringWriter();
IOUtils.copy(contents, writer, "UTF8");
JSONObject object = new JSONObject(writer.toString());
URL myURL = new URL(object.getString("proxyId"));
if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {
tCExecution.setIp(myURL.getHost());
tCExecution.setPort(String.valueOf(myURL.getPort()));
}
}
} catch (IOException ex) {
LOG.error(ex.toString());
} catch (JSONException ex) {
LOG.error(ex.toString());
}
}
use of org.openqa.selenium.remote.RemoteWebDriver in project opentest by mcdcorp.
the class SeleniumHelper method createDriver.
private static WebDriver createDriver() {
WebDriver webDriver = null;
DesiredCapabilities caps;
setSystemProperties();
if (config.hasProperty("selenium.seleniumServerUrl")) {
String seleniumServerUrl = config.getString("selenium.seleniumServerUrl");
Logger.info(String.format("Using remote Selenium server %s", seleniumServerUrl));
try {
caps = new DesiredCapabilities();
injectCapsFromConfig(caps);
webDriver = new RemoteWebDriver(new URL(seleniumServerUrl), caps);
} catch (Exception ex) {
throw new RuntimeException(String.format("Falied to connect to Selenium server %s", seleniumServerUrl), ex);
}
} else {
Logger.info("Using local Selenium server");
String browserName = config.getString("selenium.desiredCapabilities.browserName").toLowerCase();
switch(browserName) {
case "chrome":
setDriverExecutable(config.getString("selenium.chromeDriverExePath", null), "chrome");
caps = getCapsForBrowser("chrome");
injectCapsFromConfig(caps);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.merge(caps);
webDriver = new ChromeDriver(chromeOptions);
break;
case "edge":
setDriverExecutable(config.getString("selenium.edgeDriverExePath", null), "edge");
caps = getCapsForBrowser("edge");
injectCapsFromConfig(caps);
webDriver = new EdgeDriver(caps);
break;
case "firefox":
setDriverExecutable(config.getString("selenium.firefoxDriverExePath", null), "firefox");
caps = getCapsForBrowser("firefox");
injectCapsFromConfig(caps);
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.merge(caps);
webDriver = new FirefoxDriver(firefoxOptions);
break;
case "internet explorer":
setDriverExecutable(config.getString("selenium.ieDriverExePath", null), "internet explorer");
caps = getCapsForBrowser("internet explorer");
// Avoid the browser zoom level error
caps.setCapability("ignoreZoomSetting", true);
injectCapsFromConfig(caps);
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.merge(caps);
webDriver = new InternetExplorerDriver(ieOptions);
break;
case "opera":
setDriverExecutable(config.getString("selenium.operaDriverExePath", null), "opera");
caps = getCapsForBrowser("opera");
injectCapsFromConfig(caps);
webDriver = new OperaDriver(caps);
break;
case "safari":
setDriverExecutable(config.getString("selenium.safariDriverExePath", null), "safari");
caps = getCapsForBrowser("safari");
injectCapsFromConfig(caps);
webDriver = new SafariDriver();
break;
default:
throw new RuntimeException(String.format("The \"selenium.browserName\" config property specifies a browser " + "that is invalid or not supported. The property value was \"%s\". " + "The valid values are: \"chrome\", \"edge\", \"firefox\", \"internet " + "explorer\" and \"safari\".", browserName));
}
}
webDriver.manage().timeouts().setScriptTimeout(config.getInteger("selenium.scriptTimeout", 20), TimeUnit.SECONDS);
webDriver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
Boolean maximizeWindow = config.getBoolean("selenium.maximizeWindow", true);
if (maximizeWindow) {
try {
webDriver.manage().window().maximize();
} catch (Exception ex) {
Logger.warning(String.format("Failed to maximize browser window"), ex);
}
}
return webDriver;
}
use of org.openqa.selenium.remote.RemoteWebDriver in project nutch by apache.
the class HttpWebClient method createFirefoxRemoteWebDriver.
public static RemoteWebDriver createFirefoxRemoteWebDriver(URL seleniumHubUrl, boolean enableHeadlessMode) {
FirefoxOptions firefoxOptions = new FirefoxOptions();
if (enableHeadlessMode) {
firefoxOptions.setHeadless(true);
}
RemoteWebDriver driver = new RemoteWebDriver(seleniumHubUrl, firefoxOptions);
return driver;
}
Aggregations