List of usage examples for org.openqa.selenium WebDriver manage
Options manage();
From source file:info.magnolia.integrationtests.uitest.AbstractMagnoliaUITest.java
License:Open Source License
/** * Wait until a specific WebElement is gone; * this method temporarily reduce implicit wait so that we exit right as soon as condition is successful. *///from w w w .ja v a 2 s . co m protected ExpectedCondition<Boolean> elementIsGone(final By locator) { return new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driver) { // drastically reduce driver timeout so that implicit wait doesn't get in the way driver.manage().timeouts().implicitlyWait(50, TimeUnit.MILLISECONDS); WebElement gone = null; try { // do not use getElements utils to avoid cascading another expected condition gone = driver.findElement(locator); } catch (NoSuchElementException e) { // expecting element not to be found } // restore driver timeout driver.manage().timeouts().implicitlyWait(DRIVER_WAIT_IN_SECONDS, TimeUnit.SECONDS); return gone == null; } }; }
From source file:io.github.blindio.prospero.core.browserdrivers.BrowserDriverFactory.java
License:Apache License
/** * builds a WebDriver object for the correct Browser based upon the property * 'browser'//from w w w . j a va 2 s . c om * * @param siteURL * @return */ private static WebDriver buildWebDriver() { WebDriver wd = null; Browser browser = getBrowserFromConfig(); // TODO: this needs a lot more work with Capabilities if (browser == Browser.FIREFOX) { wd = new FirefoxDriver(); } else if (browser == Browser.HTMLUNIT) { wd = new HtmlUnitDriver(true); } else if (browser == Browser.INTERNET_EXPLORER) { System.setProperty(IE_WEBDRIVER_SYS_OPTION, Config.getString(PropertiesConstants.DRIVER_LOCATION)); wd = new InternetExplorerDriver(); } else if (browser == Browser.CHROME) { System.setProperty(CHROME_WEBDRIVER_SYS_OPTION, Config.getString(PropertiesConstants.DRIVER_LOCATION)); wd = new ChromeDriver(); } else if (browser == Browser.ANDROID) { if (Config.containsKey(PropertiesConstants.REMOTE_WEBDRIVER_URL)) { try { wd = new RemoteWebDriver(new URL(Config.getString(PropertiesConstants.REMOTE_WEBDRIVER_URL)), DesiredCapabilities.android()); } catch (MalformedURLException mue) { throw new ProsperoParseException(mue); } } else { wd = new AndroidDriver(); } } else if (browser == Browser.IPHONE || browser == Browser.IPAD) { DesiredCapabilities dc; if (browser == Browser.IPHONE) { dc = DesiredCapabilities.iphone(); } else { dc = DesiredCapabilities.ipad(); } try { wd = new RemoteWebDriver( new URL(Config.getString(PropertiesConstants.REMOTE_WEBDRIVER_URL, DEFAULT_IWEBDRIVER_URL)), dc); } catch (MalformedURLException mue) { throw new ProsperoParseException(mue); } } else if (browser == Browser.GHOSTDRIVER) { // TODO // Find open socket // ServerSocket sock = new ServerSocket(0); // int openPort = sock.getLocalPort(); // sock.close(); // String phantomjsServerStartCmd = "phantomjs"; // Runtime.getRuntime().exec(); String phantomJSExecutable = PhantomJSInstaller.getPhantomJS(); DesiredCapabilities dCaps = new DesiredCapabilities(); dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomJSExecutable); dCaps.setJavascriptEnabled(true); dCaps.setCapability("takesScreenshot", false); wd = new PhantomJSDriver(dCaps); } if (browser.isWindowed() && Config.containsKey(PropertiesConstants.BROWSER_WIDTH) && Config.containsKey(PropertiesConstants.BROWSER_HEIGHT)) { wd.manage().window().setSize(getBrowserDimensions()); } return wd; }
From source file:io.github.bonigarcia.wdm.PhantomJsDriverManager.java
License:Open Source License
@Override public List<URL> getDrivers() throws Exception { String phantomjsDriverUrl = WdmConfig.getString("wdm.phantomjsDriverUrl"); log.debug("Reading {} to find out the latest version of PhantomJS driver", phantomjsDriverUrl); // Switch off HtmlUnit logging LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF); java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF); // Using HtmlUnitDriver to read package URL WebDriver driver = new HtmlUnitDriver(); driver.manage().timeouts().implicitlyWait(WdmConfig.getInt("wdm.timeout"), TimeUnit.SECONDS); driver.get(phantomjsDriverUrl);/* www .java 2 s.com*/ WebElement downloadsTable = driver.findElement(By.id("available-downloads")); List<WebElement> links = downloadsTable.findElements(By .xpath("//table[@id='uploaded-files']/tbody/tr[@class='iterable-item']/td[@class='name']" + "/a")); List<URL> urlList = new ArrayList<>(links.size()); for (WebElement element : links) { String href = element.getAttribute("href"); urlList.add(new URL(href)); } return urlList; }
From source file:io.tourniquet.selenium.SeleniumControl.java
License:Apache License
@Override protected void before() throws Throwable { this.managedContext = getSeleniumContext(); this.managedContext.ifPresent(SeleniumContext::init); SeleniumContext.currentContext().setBaseUrl(baseUrl); final WebDriver driver = SeleniumContext.currentDriver(); driver.get(baseUrl);/*from w ww . ja v a 2s .c om*/ driverInit.ifPresent(di -> di.accept(driver.manage())); this.startTime = Instant.now(); }
From source file:it.com.pyxis.jira.selenium.WebDriverFactory.java
License:Open Source License
private void setDriverSpeed(WebDriver driver) { try {//from w w w . j a va 2 s. c om driver.manage().setSpeed(Speed.FAST); } catch (Exception ex) { // nothing to do } }
From source file:it.com.pyxis.jira.selenium.WebDriverFactory.java
License:Open Source License
private void setTimeout(WebDriver driver) { try {//from w w w.jav a 2s . co m driver.manage().timeouts().implicitlyWait(DEFAULT_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS); } catch (Exception ex) { // nothing to do } }
From source file:jdave.webdriver.Browser.java
License:Apache License
public void close() { WebDriver webDriver = WebDriverHolder.get(); Options options = webDriver.manage(); if (options != null) { options.deleteAllCookies();//from w w w. ja va2 s . com } webDriver.quit(); }
From source file:jp.vmi.selenium.selenese.command.DeleteCookie.java
License:Apache License
@Override protected Result executeImpl(Context context, String... curArgs) { String name = curArgs[ARG_NAME]; WebDriver driver = context.getWrappedDriver(); Cookie cookie = driver.manage().getCookieNamed(name); if (cookie != null) { driver.manage().deleteCookieNamed(name); return new Success("Cookie \"" + name + "\" is deleted."); } else {/* w w w . ja v a 2 s .c o m*/ return new Success("Cookie \"" + name + "\" is not found."); } }
From source file:main.java.qa.android.util.WaitTool.java
License:Open Source License
/** * Wait for the element to be present in the DOM, and displayed on the page. * And returns the first WebElement using the given method. * //w w w .jav a2 s . c o m * @param WebDriver The driver object to be used * @param By selector to find the element * @param int The time in seconds to wait until returning a failure * * @return WebElement the first WebElement using the given method, or null (if the timeout is reached) * @throws ExpectedExceptions */ public static WebElement waitForElement(WebDriver driver, final By by, int timeOutInSeconds) { WebElement element; try { //To use WebDriverWait(), we would have to nullify implicitlyWait(). //Because implicitlyWait time also set "driver.findElement()" wait time. //info from: https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/6VO_7IXylgY driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); element = wait.until(ExpectedConditions.visibilityOfElementLocated(by)); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return element; //return the element } catch (Exception e) { Log.info(e.getMessage()); e.printStackTrace(); } return null; }
From source file:main.java.qa.android.util.WaitTool.java
License:Open Source License
public static WebElement waitForElementDriverWebElementSecond(WebDriver driver, WebElement wElement, int timeOutInSeconds) { WebElement element;// w w w .ja v a2s . co m try { //To use WebDriverWait(), we would have to nullify implicitlyWait(). //Because implicitlyWait time also set "driver.findElement()" wait time. //info from: https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/6VO_7IXylgY driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); element = wait.until(ExpectedConditions.visibilityOf(wElement)); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return element; //return the element } catch (Exception e) { Log.info(e.getMessage()); e.printStackTrace(); } return null; }