List of usage examples for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver
public RemoteWebDriver(URL remoteAddress, Capabilities capabilities)
From source file:org.cybercat.automation.browsers.RemoteServerProvider.java
License:Apache License
public Browser createRemoteWebDriver(Browsers browserType) throws PageObjectException { DesiredCapabilities capabilities = createDesiredCapabilities(browserType); try {/*from ww w .j a v a 2s. c o m*/ RemoteWebDriver driver = new RemoteWebDriver( new URL("http://" + configProperties.getProperty(SELENIUM_HOST) + ":" + configProperties.getProperty(SELENIUM_PORT) + "/wd/hub"), capabilities); return new Browser(driver, browserType, true); } catch (MalformedURLException e) { throw new PageObjectException(e); } }
From source file:org.eclipse.che.selenium.core.SeleniumWebDriver.java
License:Open Source License
private RemoteWebDriver doCreateDriver(URL webDriverUrl) { DesiredCapabilities capability;// ww w.j a v a 2s . c om switch (browser) { case GOOGLE_CHROME: LoggingPreferences loggingPreferences = new LoggingPreferences(); loggingPreferences.enable(LogType.PERFORMANCE, Level.ALL); loggingPreferences.enable(LogType.BROWSER, Level.ALL); ChromeOptions options = new ChromeOptions(); options.addArguments("--no-sandbox"); options.addArguments("--dns-prefetch-disable"); options.addArguments("--ignore-certificate-errors"); // set parameters required for automatic download capability Map<String, Object> chromePrefs = new HashMap<>(); chromePrefs.put("download.default_directory", downloadDir); chromePrefs.put("download.prompt_for_download", false); chromePrefs.put("download.directory_upgrade", true); chromePrefs.put("safebrowsing.enabled", true); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("plugins.plugins_disabled", "['Chrome PDF Viewer']"); options.setExperimentalOption("prefs", chromePrefs); capability = DesiredCapabilities.chrome(); capability.setCapability(ChromeOptions.CAPABILITY, options); capability.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences); capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); break; default: capability = DesiredCapabilities.firefox(); capability.setCapability("dom.max_script_run_time", 240); capability.setCapability("dom.max_chrome_script_run_time", 240); } RemoteWebDriver driver = new RemoteWebDriver(webDriverUrl, capability); if (driver.getErrorHandler().isIncludeServerErrors() && driver.getCapabilities().getCapability("message") != null) { String errorMessage = format("Web driver creation error occurred: %s", driver.getCapabilities().getCapability("message")); LOG.error(errorMessage); throw new RuntimeException(errorMessage); } driver.manage().window().setSize(new Dimension(1920, 1080)); return driver; }
From source file:org.eclipse.packagedrone.testing.server.TestSuite.java
License:Open Source License
protected static RemoteWebDriver createSauce(final Platform os, final String browser, final String version) throws MalformedURLException { final DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setBrowserName(browser); if (version != null) { capabilities.setVersion(version); }//ww w. j a va 2 s. c o m capabilities.setCapability(CapabilityType.PLATFORM, os); capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true); capabilities.setCapability("name", "Eclipse Package Drone Main Test"); if (System.getenv("TRAVIS_JOB_NUMBER") != null) { capabilities.setCapability("tunnel-identifier", System.getenv("TRAVIS_JOB_NUMBER")); capabilities.setCapability("build", System.getenv("TRAVIS_BUILD_NUMBER")); capabilities.setCapability("tags", new String[] { "CI" }); } final RemoteWebDriver driver = new RemoteWebDriver( new URL(String.format("http://%s:%s@%s/wd/hub", SAUCE_USER_NAME, SAUCE_ACCESS_KEY, SAUCE_URL)), capabilities); driver.setFileDetector(new LocalFileDetector()); return driver; }
From source file:org.eclipse.scout.rt.testing.ui.rap.RapMock.java
License:Open Source License
@Override public void beforeTest() { if (m_service != null) { if (useChrome) { DesiredCapabilities chrome = DesiredCapabilities.chrome(); m_driver = new RemoteWebDriver(m_service.getUrl(), chrome); }/*from w w w . jav a2 s .c om*/ } else { if (useFirefox) { System.setProperty("webdriver.firefox.bin", "C:/FirefoxPortableTest_11/App/Firefox/firefox.exe"); FirefoxProfile firefoxProfile = new FirefoxProfile(); if (useFirebug) { try { firefoxProfile.addExtension(new File("E:/Downloads/java/firebug-1.9.2-fx.xpi")); firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.9.2"); // Avoid startup screen firefoxProfile.addExtension(new File("E:/Downloads/java/firepath-0.9.7-fx.xpi")); } catch (IOException e) { throw new IllegalStateException("Could not add/find firefox extensions.", e); } } m_driver = new FirefoxDriver(firefoxProfile); // m_driver = new FirefoxDriver(new FirefoxProfile(new File("C:/Temp/webdriver-profile"))); } } if (m_driver == null) { throw new NullPointerException("no driver instantiated!"); } m_bot = new RAPSelenium(m_driver, "http://localhost:8081"); m_actionBuilder = new Actions(m_bot.getWrappedDriver()); m_bot.open("http://localhost:8081/rap"); m_bot.waitForElementPresent("w2"); }
From source file:org.emonocot.portal.driver.WebDriverFacade.java
License:Open Source License
/** * * @return the webdriver/*from www . j a v a2 s. co m*/ * @throws IOException if there is a problem loading the * properties file */ private WebDriver createWebDriver() throws IOException { Resource propertiesFile = new ClassPathResource("META-INF/spring/application.properties"); Properties properties = new Properties(); properties.load(propertiesFile.getInputStream()); String webdriverMode = properties.getProperty("selenium.webdriver.mode", "local"); String driverName = properties.getProperty("selenium.webdriver.impl", "org.openqa.selenium.firefox.FirefoxDriver"); WebDriverBrowserType browser = WebDriverBrowserType.fromString(driverName); String display = properties.getProperty("selenium.display.port", ":0"); if (webdriverMode.equals("local")) { switch (browser) { case CHROME: String chromeLocation = properties.getProperty("selenium.webdriver.chromedriver.location"); Map<String, String> environment = new HashMap<String, String>(); environment.put("DISPLAY", display); ChromeDriverService chromeService = new ChromeDriverService.Builder() .usingDriverExecutable(new File(chromeLocation)).usingAnyFreePort() .withEnvironment(environment).build(); chromeService.start(); return new RemoteWebDriver(chromeService.getUrl(), DesiredCapabilities.chrome()); case SAFARI: return new SafariDriver(); case INTERNET_EXPLORER: String internetExplorerLocation = properties.getProperty("selenium.webdriver.ie.location"); InternetExplorerDriverService ieService = InternetExplorerDriverService.createDefaultService(); ieService.start(); return new RemoteWebDriver(ieService.getUrl(), DesiredCapabilities.internetExplorer()); case FIREFOX: default: FirefoxBinary firefoxBinary = new FirefoxBinary(); firefoxBinary.setEnvironmentProperty("DISPLAY", display); ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile profile = allProfiles.getProfile("default"); return new FirefoxDriver(firefoxBinary, profile); } } else { DesiredCapabilities capabilities = new DesiredCapabilities(); switch (browser) { case CHROME: capabilities = DesiredCapabilities.chrome(); break; case INTERNET_EXPLORER: capabilities = DesiredCapabilities.internetExplorer(); break; case SAFARI: capabilities = DesiredCapabilities.safari(); break; case FIREFOX: default: capabilities = DesiredCapabilities.firefox(); } String platformName = properties.getProperty("selenium.webdriver.platformName", "LINUX"); WebDriverPlatformType platform = WebDriverPlatformType.valueOf(platformName); switch (platform) { case MAC: capabilities.setPlatform(Platform.MAC); break; case WINDOWS: capabilities.setPlatform(Platform.WINDOWS); break; case LINUX: default: capabilities.setPlatform(Platform.LINUX); } return new RemoteWebDriver(new URL("http://build.e-monocot.org:4444/wd/hub"), capabilities); } }
From source file:org.encuestame.selenium.EnmeInitialPageTestIT.java
License:Apache License
/** * * @throws Exception// w w w . j a v a2 s .com */ @Before public void setUp() throws Exception { final URL url = new URL("http://127.0.0.1:4444/wd/hub/"); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setBrowserName("chrome"); desiredCapabilities.setJavascriptEnabled(Boolean.TRUE); driver = new RemoteWebDriver(url, desiredCapabilities); baseUrl = "http://localhost:8080/encuestame/home"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }
From source file:org.example.webapp.integration.ITConfig.java
License:Apache License
@Bean public WebDriver webDriver() throws MalformedURLException { return new RemoteWebDriver(getRemoteUrl(), getDesiredCapabilities()); }
From source file:org.finra.jtaf.ewd.impl.DefaultSessionFactory.java
License:Apache License
@Override public WebDriver createInnerDriver(Map<String, String> options, DesiredCapabilities capabilities) throws Exception { ClientProperties properties = new ClientProperties(options.get("client")); WebDriver wd = null;/*from www . ja v a2s . c om*/ DesiredCapabilities desiredCapabilities = new DesiredCapabilities(capabilities); String browser = properties.getBrowser(); if (properties.isUseGrid()) { RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(properties.getGridUrl()), capabilities); remoteWebDriver.setFileDetector(new LocalFileDetector()); wd = remoteWebDriver; } else { if (browser == null || browser.equals("")) { throw new RuntimeException( "Browser cannot be null. Please set 'browser' in client properties. Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit."); } else if (browser.equalsIgnoreCase("ie") || browser.equalsIgnoreCase("iexplore") || browser.equalsIgnoreCase("*iexplore")) { String webdriverIEDriver = properties.getWebDriverIEDriver(); if (webdriverIEDriver != null) { System.setProperty("webdriver.ie.driver", webdriverIEDriver); } String browserVersion = properties.getBrowserVersion(); if (browserVersion == null || browserVersion.equals("")) { throw new RuntimeException( "When using IE as the browser, please set 'browser.version' in client properties"); } else { if (browserVersion.startsWith("9")) { desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); desiredCapabilities.setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); wd = new InternetExplorerDriver(desiredCapabilities); } else { wd = new InternetExplorerDriver(desiredCapabilities); } } } else if ((browser.equalsIgnoreCase("firefox") || browser.equalsIgnoreCase("*firefox"))) { final String ffProfileFolder = properties.getFirefoxProfileFolder(); final String ffProfileFile = properties.getFirefoxProfileFile(); final String path = properties.getBinaryPath(); if (path != null) { FirefoxBinary fireFox = getFFBinary(path); FirefoxProfile ffp = null; if (ffProfileFolder != null) { ffp = new FirefoxProfile(new File(ffProfileFolder)); } else { ffp = new FirefoxProfile(); } if (ffProfileFile != null) { addPreferences(ffp, ffProfileFile); } addPreferences(ffp); List<String> ffExtensions = properties.getFirefoxExtensions(); if (ffExtensions != null && ffExtensions.size() > 0) { addExtensionsToFirefoxProfile(ffp, ffExtensions); } wd = new FirefoxDriver(fireFox, ffp, desiredCapabilities); } else { wd = new FirefoxDriver(desiredCapabilities); } } else if (browser.equalsIgnoreCase("chrome")) { String webdriverChromeDriver = properties.getWebDriverChromeDriver(); if (webdriverChromeDriver != null) { System.setProperty("webdriver.chrome.driver", webdriverChromeDriver); } wd = new ChromeDriver(desiredCapabilities); } else if (browser.equalsIgnoreCase("safari")) { wd = new SafariDriver(desiredCapabilities); } else if (browser.equalsIgnoreCase("htmlunit")) { wd = new HtmlUnitDriver(desiredCapabilities); ((HtmlUnitDriver) wd).setJavascriptEnabled(true); } else { throw new Exception("Unsupported browser type: " + browser + ". Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit."); } // move browser windows to specific position. It's useful for // debugging... final int browserInitPositionX = properties.getBrowserInitPositionX(); final int browserInitPositionY = properties.getBrowserInitPositionY(); if (browserInitPositionX != 0 || browserInitPositionY != 0) { wd.manage().window().setSize(new Dimension(1280, 1024)); wd.manage().window().setPosition(new Point(browserInitPositionX, browserInitPositionY)); } } return wd; }
From source file:org.fitting.selenium.BrowserConnector.java
License:Apache License
/** * Create a new Browser instance./*from ww w .ja va 2s. c o m*/ * * @param capabilities The desired browser capabilities. * @param url The URL to connect to. */ protected BrowserConnector(DesiredCapabilities capabilities, URL url) { webDriver = new RemoteWebDriver(url, capabilities); javascriptEnabled = capabilities.isJavascriptEnabled(); }
From source file:org.fluentlenium.integration.localtest.SauceLabsFluentCase.java
License:Apache License
@Override public WebDriver getDefaultDriver() { DesiredCapabilities capabilities = new DesiredCapabilities("firefox", "3.6.", Platform.WINDOWS); capabilities.setCapability("name", "Test of FluentLenium"); try {/*w ww . ja va2 s . c o m*/ return new RemoteWebDriver(new URL( "http://fluentlenium:8906940f-5638-4c29-beb6-c331df039f48@ondemand.saucelabs.com:80/wd/hub"), capabilities); } catch (MalformedURLException e) { return null; } }