/** * {@inheritDoc} */ @Override public WebDriver getWebDriverInstance() { WebDriver retVal = getWebDriver(); if (null == retVal || !(((EventFiringWebDriver)retVal).getWrappedDriver() instanceof RemoteWebDriver)) { try { RemoteWebDriver remoteVal = new RemoteWebDriver(new URL(url), caps.get()); remoteVal.setFileDetector(new LocalFileDetector()); retVal = remoteVal; } catch (MalformedURLException e) { //TODO add handling for bad url e.printStackTrace(); } setWebDriver(retVal); } return retVal; }
@Override @Monitor @RetryFailure(retryCount=3) @JSHandle public WebDriverController uploadFile(Object locator, String path) { LocalFileDetector detector = new LocalFileDetector(); File localFile = detector.getLocalFile(path); ((RemoteWebElement)waitController().waitForElementPresence(locator)).setFileDetector(detector); waitController().waitForElementPresence(locator).sendKeys(localFile.getAbsolutePath()); return this; }
@Override public void postConstruct(D webDriver) { if (webDriver instanceof RemoteWebDriver) { try { ((RemoteWebDriver) webDriver).setFileDetector(new LocalFileDetector()); } catch (WebDriverException e) { String message = e.getMessage(); if (message != null && !message.contains(NO_FILE_DETECTOR_NEEDED)) { throw e; } } } }
/** * When send keys is being executed in a input file=type {@link LocalFileDetector} must be configured for remote drivers. Additionally, * the file path is expanded to be absolute * * @param driver used to run commands * @param element receiving keys * @param value to be set to input file type * @return value expanded to absolute path if for input file type. */ private String cleanValueToSend(WebDriver driver, WebElement element, String value) { if (!StringUtils.equals(element.getAttribute(SeleniumFixture.INPUT_TYPE_ATTRIBUTE), SeleniumFixture.INPUT_TYPE_FILE_VALUE)) { return this.fitnesseMarkup.clean(value); } // set file detector for remote web elements. Local FirefoxDriver uses RemoteWebElement and if (element instanceof RemoteWebElement && !ClassUtils.isAssignable(driver.getClass(), FirefoxDriver.class)) { ((RemoteWebElement) element).setFileDetector(new LocalFileDetector()); } return this.fitnesseMarkup.cleanFile(value).getAbsolutePath(); }
private static WebDriver getSeleniumGridRemoteDriver() throws MalformedURLException { final DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setBrowserName(System.getProperty("selenium.grid.browser", "firefox")); desiredCapabilities.setVersion(System.getProperty("selenium.grid.version", "")); desiredCapabilities.setPlatform(Platform.ANY); final URL url = new URL("http", System.getProperty("selenium.grid"), Integer.valueOf(System.getProperty( "selenium.grid.port", "4444")), "/wd/hub"); final RemoteWebDriver remoteWebDriver = new RemoteWebDriver(url, desiredCapabilities); remoteWebDriver.setFileDetector(new LocalFileDetector()); return new Augmenter().augment(remoteWebDriver); }
@Override public WebDriver getWebDriver(SupportedBrowser browserType) { RemoteWebDriver remoteDriver = new RemoteWebDriver(gridHubURL, desiredCapabilities, browserType.toCapabilities()); remoteDriver.setFileDetector(new LocalFileDetector()); return remoteDriver; }
@Override public T createDriver() { T remoteWebDriver = constr.apply(url, capabilities); FileDetector fd = remoteWebDriver.getFileDetector(); if (fd == null || fd instanceof UselessFileDetector) { remoteWebDriver.setFileDetector(new LocalFileDetector()); } Environment.getInstance().setSymbol(REMOTE_URL_KEY, url.toString()); return remoteWebDriver; }
@Bean public WebDriver webDriver() { PhantomJsDriverManager.getInstance().version("2.1.1").arch64().setup(); final PhantomJSDriver phantomJSDriver = new PhantomJSDriver(); phantomJSDriver.setFileDetector(new LocalFileDetector()); return phantomJSDriver; }
public WebDriver create(WebDriverProperties webDriverProperties) throws IOException { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(webDriverProperties.getDesiredCapabilities()); desiredCapabilities.merge(browserSpecificCapabilities(webDriverProperties)); WebDriver webDriver = null; if (webDriverProperties.getUrl() != null) { RemoteWebDriver remoteDriver = new RemoteWebDriver(webDriverProperties.getUrl(), desiredCapabilities); remoteDriver.setFileDetector(new LocalFileDetector()); webDriver = remoteDriver; } else { String browserName = desiredCapabilities == null ? null : desiredCapabilities.getBrowserName(); if (Strings.isNullOrEmpty(browserName)) browserName = BrowserType.CHROME; webDriver = WebDriverType.typeFor(browserName).create(this, desiredCapabilities); } WindowProperties window = webDriverProperties.getWindow(); if (window != null) { DimensionProperties size = window.getSize(); PointProperties position = window.getPosition(); if (size != null) webDriver.manage().window().setSize(new Dimension(size.getWidth(), size.getHeight())); if (position != null) webDriver.manage().window().setPosition(new Point(position.getX(), position.getY())); if (window.isMaximized()) { webDriver.manage().window().maximize(); } } webDriver = webDriver instanceof TakesScreenshot ? webDriver : new Augmenter().augment(webDriver); for (WebDriverTransformer transformer : driverServices.getWebDriverTranformers()) webDriver = transformer.transform(webDriver); return webDriverProperties.isStateful() ? new StatefulWebDriver(webDriver) : webDriver; }
@Override public WebDriver createDriver(URL remoteUrl) throws IOException { if (isRemoteDriver()) { RemoteWebDriver driver = new RemoteWebDriver(remoteUrl, DesiredCapabilities.htmlUnit()); driver.setFileDetector(new LocalFileDetector()); return driver; } else { return createDriver(); } }
@Override public WebDriver createDriver(URL remoteUrl) throws IOException { FirefoxOptions options = getFirefoxOptions(); if (isRemoteDriver()) { RemoteWebDriver driver = new RemoteWebDriver(remoteUrl, options); driver.setFileDetector(new LocalFileDetector()); return driver; } else { return new FirefoxDriver(options); } }
@Override public WebDriver createDriver(URL remoteUrl) throws IOException { ChromeOptions options = getChromeOptions(); if (isRemoteDriver()) { RemoteWebDriver driver = new RemoteWebDriver(remoteUrl, options); driver.setFileDetector(new LocalFileDetector()); return driver; } else { return new ChromeDriver(options); } }
@Override public WebDriver createDriver(URL remoteUrl) throws IOException { InternetExplorerOptions capabilities = getOptions(); if (isRemoteDriver()) { RemoteWebDriver driver = new RemoteWebDriver(remoteUrl, capabilities); driver.setFileDetector(new LocalFileDetector()); return driver; } else { return new InternetExplorerDriver(capabilities); } }
/** * Helper method to launch remote web driver. * * At times there are issues with starting the remote web driver. For firefox, * problems with locking port 7054 can arise. * * See the Selenium <a * href="https://code.google.com/p/selenium/issues/detail?id=4790">bug</a> for * more info * * A special case needs to be performed for the Android browser, since it can not be cast to {@link RemoteWebDriver} * * @param capabilities web driver capabilities. * @return {@link WebDriver} instance of the remote web driver * */ protected WebDriver initRemoteWebDriver(DesiredCapabilities capabilities) { URL remoteUrl = getRemoteSeleniumUrl(); LOG.debug("Remote Selenium URL: {}", remoteUrl.toString()); WebDriver driver = null; boolean isAndroid = false; int tries = 1; if(capabilities.getCapability(CapabilityType.BROWSER_NAME).equals(ANDROID_BROWSER_NAME)) { isAndroid = true; } while (driver == null) { LOG.debug("Try {} {}", tries, capabilities.toString()); try { if(isAndroid) { driver = new AndroidDriver(remoteUrl, capabilities); } else { driver = new RemoteWebDriver(remoteUrl, capabilities); } } catch (WebDriverException e) { LOG.error("Remote WebDriver was unable to start! " + e.getMessage(), e); if (tries >= Integer.getInteger(REMOTE_WEBDRIVER_RETRY_ATTEMPTS, 10)) { throw e; } sleep(Integer.getInteger(REMOTE_WEBDRIVER_RETRY_PAUSE_MILLIS, 5000) * tries); tries++; driver = null; } } if(!isAndroid) { // allow screenshots to be taken driver = new Augmenter().augment(driver); } // Allow files from the host to be uploaded to a remote browser ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector()); return driver; }
public static WebDriver getWebDriver(URL remoteUrl, DesiredCapabilities capabilities) throws IOException { driver = new RemoteWebDriver(remoteUrl, capabilities); ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector()); init(driver); return driver; }