use of org.openqa.selenium.remote.RemoteWebDriver in project selenium_java by sergueik.
the class BaseTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
// BasicConfigurator.configure();
if (hubUrl == null || hubUrl.trim().isEmpty()) {
// if no hubUrl specified, run the tests on localhost
if (browser == null || browser.trim().isEmpty()) {
// if no browser specified, use IE
driver = new InternetExplorerDriver();
} else {
if (browser.trim().equalsIgnoreCase("firefox")) {
driver = new FirefoxDriver();
} else if (browser.trim().equalsIgnoreCase("chrome")) {
driver = new ChromeDriver();
} else {
driver = new InternetExplorerDriver();
}
}
} else {
DesiredCapabilities capability = new DesiredCapabilities();
capability.setBrowserName(browser);
driver = new RemoteWebDriver(new URL(hubUrl), capability);
}
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
use of org.openqa.selenium.remote.RemoteWebDriver in project selenium_java by sergueik.
the class AppTest method setupBeforeSuite.
@BeforeSuite(alwaysRun = true)
public void setupBeforeSuite(ITestContext context) throws InterruptedException, MalformedURLException {
selenium_host = context.getCurrentXmlTest().getParameter("selenium.host");
selenium_port = context.getCurrentXmlTest().getParameter("selenium.port");
selenium_browser = context.getCurrentXmlTest().getParameter("selenium.browser");
selenium_run = context.getCurrentXmlTest().getParameter("selenium.run");
// Remote Configuration
if (selenium_browser.compareToIgnoreCase("remote") == 0) {
String hub = "http://" + selenium_host + ":" + selenium_port + "/wd/hub";
LoggingPreferences logging_preferences = new LoggingPreferences();
logging_preferences.enable(LogType.BROWSER, Level.ALL);
logging_preferences.enable(LogType.CLIENT, Level.INFO);
logging_preferences.enable(LogType.SERVER, Level.INFO);
if (selenium_browser.compareToIgnoreCase("chrome") == 0) {
DesiredCapabilities capabilities = new DesiredCapabilities("chrome", "", Platform.ANY);
capabilities.setBrowserName("chrome");
capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
try {
driver = new RemoteWebDriver(new URL("http://" + selenium_host + ":" + selenium_port + "/wd/hub"), capabilities);
} catch (MalformedURLException ex) {
}
} else {
DesiredCapabilities capabilities = new DesiredCapabilities("firefox", "", Platform.ANY);
capabilities.setBrowserName("firefox");
FirefoxProfile profile = new ProfilesIni().getProfile("default");
capabilities.setCapability("firefox_profile", profile);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
try {
driver = new RemoteWebDriver(new URL("http://" + selenium_host + ":" + selenium_port + "/wd/hub"), capabilities);
} catch (MalformedURLException ex) {
}
}
} else // standalone
{
if (selenium_browser.compareToIgnoreCase("chrome") == 0) {
System.setProperty("webdriver.chrome.driver", "c:/java/selenium/chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
LoggingPreferences logging_preferences = new LoggingPreferences();
logging_preferences.enable(LogType.BROWSER, Level.ALL);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
/*
prefs.js:user_pref("extensions.logging.enabled", true);
user.js:user_pref("extensions.logging.enabled", true);
*/
driver = new ChromeDriver(capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} else {
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
LoggingPreferences logging_preferences = new LoggingPreferences();
logging_preferences.enable(LogType.BROWSER, Level.ALL);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
driver = new FirefoxDriver(capabilities);
}
}
try {
driver.manage().window().setSize(new Dimension(600, 800));
driver.manage().timeouts().pageLoadTimeout(50, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
use of org.openqa.selenium.remote.RemoteWebDriver in project zalenium by zalando.
the class ParallelIT method startWebDriverAndGetBaseUrl.
@BeforeMethod(alwaysRun = true)
public void startWebDriverAndGetBaseUrl(Method method, Object[] testArgs) throws MalformedURLException {
String zaleniumUrl = String.format("http://%s:%s/wd/hub", ZALENIUM_HOST, ZALENIUM_PORT);
String browserType = testArgs[0].toString();
Platform platform = (Platform) testArgs[1];
boolean localTesting = false;
if (testArgs.length > 2) {
localTesting = testArgs[2] != null && (boolean) testArgs[2];
}
LOGGER.info("STARTING {} on {} - {}, using {}", method.getName(), browserType, platform.name(), zaleniumUrl);
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(CapabilityType.BROWSER_NAME, browserType);
desiredCapabilities.setCapability(CapabilityType.PLATFORM_NAME, platform);
desiredCapabilities.setCapability("name", method.getName());
if (localTesting) {
desiredCapabilities.setCapability("tunnel", "true");
desiredCapabilities.setCapability("browserstack.local", "true");
desiredCapabilities.setCapability("browserstack.localIdentifier", "zalenium");
desiredCapabilities.setCapability("tunnelIdentifier", "zalenium");
}
try {
webDriver.set(new RemoteWebDriver(new URL(zaleniumUrl), desiredCapabilities));
} catch (Exception e) {
LOGGER.warn("FAILED {} on {} - {}", method.getName(), browserType, platform.name());
throw e;
}
}
use of org.openqa.selenium.remote.RemoteWebDriver in project scout.rt by eclipse.
the class SeleniumDriver method setUpDriver.
public static WebDriver setUpDriver() {
// web-driver executable
String webdriverChromeDriver = System.getProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY);
if (StringUtility.isNullOrEmpty(webdriverChromeDriver)) {
webdriverChromeDriver = OS.isFamilyWindows() ? "/seleniumDrivers/chromedriver.exe" : "/seleniumDrivers/chromedriver";
}
File chromeDriver = new File(webdriverChromeDriver);
if (!chromeDriver.exists()) {
System.out.println("Chrome driver executable not found at path: " + chromeDriver);
URL webdriverChromeDriverResource = SeleniumDriver.class.getResource(webdriverChromeDriver);
if (webdriverChromeDriverResource != null) {
chromeDriver = new File(webdriverChromeDriverResource.getFile());
webdriverChromeDriver = chromeDriver.getAbsolutePath();
}
}
if (!StringUtility.matches(webdriverChromeDriver, ".+\\.exe", Pattern.CASE_INSENSITIVE) && chromeDriver.exists() && !chromeDriver.canExecute()) {
chromeDriver.setExecutable(true);
}
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, webdriverChromeDriver);
logProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, webdriverChromeDriver);
// log-file for web-driver
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File logFile = new File(tmpDir, "webdriver.log");
String logFilePath = logFile.getAbsolutePath();
System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, logFilePath);
logProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, logFilePath);
// set web-driver in verbose mode
System.setProperty(ChromeDriverService.CHROME_DRIVER_VERBOSE_LOG_PROPERTY, "true");
logProperty(ChromeDriverService.CHROME_DRIVER_VERBOSE_LOG_PROPERTY, "true");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
// Prepare options
ChromeOptions options = new ChromeOptions();
String chromeBinary = System.getProperty("chrome.binary");
logProperty("chrome.binary", chromeBinary);
if (StringUtility.hasText(chromeBinary)) {
options.setBinary(chromeBinary);
}
options.addArguments("--lang=en");
options.addArguments("--verbose");
options.addArguments("--disable-infobars");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
// Set logging preferences (see BrowserLogRule)
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
// TODO [7.0] BSH Remove workaround, when Chrome bug is fixed
// <WORKAROUND> https://bugs.chromium.org/p/chromedriver/issues/detail?id=1552
Map<String, String> env = new HashMap<>();
env.put("LANG", "en_US.UTF-8");
System.out.println("Using custom environment variables for driver: " + new JSONObject(env).toString(2));
RemoteWebDriver driver = new ChromeDriver(new ChromeDriverService.Builder().usingAnyFreePort().withEnvironment(// <--
env).build(), capabilities);
// RemoteWebDriver driver = new ChromeDriver(options)
// </WORKAROUND>
driver.manage().timeouts().setScriptTimeout(10000, TimeUnit.SECONDS);
// Set window size roughly to the minimal supported screen size
// (1280x1024 minus some borders for browser toolbar and windows taskbar)
// Add extra 50 pixel height, because of yellow bar "Chrome is being controlled..." which comes up since v 65.0.3325
// even tough the disable-infobars property is set - doesn't work anymore :-(
driver.manage().window().setPosition(new Point(0, 0));
driver.manage().window().setSize(new Dimension(1200, 900 + 50));
Capabilities caps = driver.getCapabilities();
System.out.println("Selenium driver configured with driver=" + driver.getClass().getName() + " browser.name=" + caps.getBrowserName() + " browser.version=" + caps.getVersion());
return driver;
}
use of org.openqa.selenium.remote.RemoteWebDriver in project ephemerals by LivePersonInc.
the class SeleniumEphemeral method createObject.
@Override
protected RemoteWebDriver createObject(DeploymentEndpoints endpoints) {
URL remoteWebDriverUrl = null;
for (DeploymentEndpoints.Endpoint endpoint : endpoints.list()) {
if (endpoint.getName().equals("selenium-server")) {
String host = endpoint.getHost();
int port = endpoint.getPort();
try {
remoteWebDriverUrl = new URL(String.format("http://%s:%s/%s", host, port, SERVER_PATH));
logger.info("RemoteWebDriver URL {}", remoteWebDriverUrl);
} catch (MalformedURLException e) {
return null;
}
}
}
return new RemoteWebDriver(remoteWebDriverUrl, desiredCapabilities);
}
Aggregations