Example usage for org.openqa.selenium WebDriver manage

List of usage examples for org.openqa.selenium WebDriver manage

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver manage.

Prototype

Options manage();

Source Link

Document

Gets the Option interface

Usage

From source file:com.ecofactor.qa.automation.newapp.ThermostatControlEETest.java

License:Open Source License

/**
 * Creates the driver.//from  w w w. ja va 2s.  co m
 * @return the web driver
 */
private WebDriver createWebDriver() {

    LogUtil.setLogString("Create New webdriver", true);
    LogUtil.setLogString("Browser : " + System.getProperty("browser"), true);
    final WebDriver driver = SeleniumDriverUtil.createBrowserDriver(System.getProperty("browser"));
    driver.manage().window().maximize();
    final String url = mobileConfig.get(MobileConfig.ECOFACTOR_URL);
    LogUtil.setLogString("Load Url: " + url, true);
    driver.navigate().to(url);
    WaitUtil.smallWait();
    return driver;
}

From source file:com.ecofactor.qa.automation.newapp.ThermostatTest.java

License:Open Source License

/**
 * Creates the driver.// ww  w . jav a 2s.c o  m
 * @return the web driver
 */
private WebDriver createDriver() {

    LogUtil.setLogString("Create New webdriver", true);
    LogUtil.setLogString("Browser : " + System.getProperty("browser"), true);
    final WebDriver driver = SeleniumDriverUtil.createBrowserDriver(System.getProperty("browser"));
    driver.manage().window().maximize();
    final String url = mobileConfig.get(ECOFACTOR_URL);
    LogUtil.setLogString("Load Url: " + url, true);
    driver.navigate().to(url);
    smallWait();
    return driver;
}

From source file:com.ecofactor.qa.automation.platform.ops.impl.DesktopOperations.java

License:Open Source License

/**
 * Creates the device driver.//  w  ww .java2 s  .co m
 * @return the web driver
 * @throws DeviceException the device exception
 * @see com.ecofactor.qa.automation.mobile.ops.impl.AbstractDriverOperations#createDeviceDriver()
 */
@Override
protected WebDriver createDeviceDriver() throws DeviceException {

    final String browser = System.getProperty("browser");
    setLogString("Browser: " + browser, true);
    setLogString("Create instance for WebDriver", true);
    final WebDriver driver = SeleniumDriverUtil.createBrowserDriver(browser);
    setLogString("Maximize the Browser window", true);
    driver.manage().window().maximize();
    setLogString("Wait for few seconds after driver initialize", true);
    final String driverWait = System.getProperty("defaultBrowserWaitInMilliSecs");
    LOGGER.info("Wait for driver startup " + driverWait, true);
    if (driverWait == null || driverWait.isEmpty()) {
        largeWait();
    } else {
        waitUntil(Long.valueOf(driverWait));
    }
    return driver;
}

From source file:com.elastica.driver.WebUtility.java

License:Apache License

public static void main(final String[] args) {
    WebUIDriver.getWebUXDriver().setMode("ExistingGrid");
    WebUIDriver.getWebUXDriver().setHubUrl(" ");

    WebDriver driver = WebUIDriver.getWebDriver(true);
    System.out//from  w w w . j  a  va  2 s.co m
            .print(driver.manage().window().getSize().width + ":" + driver.manage().window().getSize().height);
}

From source file:com.emc.kibana.emailer.KibanaEmailer.java

License:Open Source License

private static void generatePdfReports() {

    try {/* w  ww.  jav a  2 s  . c  om*/
        System.setProperty("webdriver.chrome.driver", chromeDriverPath);

        Map<String, Object> chromeOptions = new HashMap<String, Object>();

        // Specify alternate browser location
        if (chromeBrowserPath != null && !chromeBrowserPath.isEmpty()) {
            chromeOptions.put("binary", chromeBrowserPath);
        }

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();

        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

        int index = 1;
        Date timestamp = new Date(System.currentTimeMillis());

        for (Map<String, String> entry : kibanaUrls) {

            String dashboardName = entry.get(NAME_KEY);
            String dashboardUrl = entry.get(URL_KEY);

            if (dashboardUrl == null) {
                continue;
            }

            String filename;

            if ((dashboardName != null)) {
                String invalidCharRemoved = dashboardName.replaceAll("[\\/:\"*?<>|]+", "_").replaceAll(" ",
                        "_");
                filename = invalidCharRemoved + ".png";
            } else {
                filename = "dashboard-" + index++ + ".png";
            }

            WebDriver driver = new ChromeDriver(capabilities);
            driver.manage().window().maximize();
            driver.get(dashboardUrl);

            // let kibana load for x seconds before taking the snapshot
            Integer delay = (screenCaptureDelay != null) ? (screenCaptureDelay * 1000) : (20000);
            Thread.sleep(delay);
            // take screenshot
            File scrnshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

            // generate absolute path filename
            String absoluteFileName = destinationPath + File.separator + DATA_DATE_FORMAT.format(timestamp)
                    + File.separator + filename;
            Map<String, String> fileMap = new HashMap<String, String>();
            // file name portion
            fileMap.put(FILE_NAME_KEY, filename);
            fileMap.put(ABSOLUE_FILE_NAME_KEY, absoluteFileName);

            kibanaScreenCaptures.add(fileMap);
            File destFile = new File(absoluteFileName);

            logger.info("Copying " + scrnshot + " in " + destFile.getAbsolutePath());

            FileUtils.copyFile(scrnshot, destFile);
            driver.close();
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (IOException e1) {
        throw new RuntimeException(e1);
    }
}

From source file:com.epam.jdi.uitests.mobile.appium.driver.AppiumDriverFactory.java

License:Open Source License

public WebDriver getDriver(String driverName) {
    try {/*from  w  ww.j a  v  a  2  s .co m*/
        if (runDrivers.keys().contains(driverName))
            return runDrivers.get(driverName);
        WebDriver resultDriver = drivers.get(driverName).get();
        runDrivers.add(driverName, resultDriver);
        if (resultDriver == null)
            throw exception("Can't get Webdriver '%s'. This Driver name not registered", driverName);
        resultDriver.manage().timeouts().implicitlyWait(timeouts.getCurrentTimeoutSec(), SECONDS);
        return resultDriver;
    } catch (Exception ex) {
        throw exception("Can't get driver");
    }
}

From source file:com.epam.jdi.uitests.web.selenium.driver.SeleniumDriverFactory.java

License:Open Source License

private static void maximizeMacBrowser(WebDriver driver) {
    java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    driver.manage().window().setSize(new org.openqa.selenium.Dimension(screenSize.width, screenSize.height));
}

From source file:com.esure.motorinsurance.webpages.QuoteDetailPage.java

public QuoteDetailPage(WebDriver driver) {
    this.driver = driver;
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    PageFactory.initElements(driver, this);
}

From source file:com.evidon.areweprivateyet.Crawler.java

License:Open Source License

public Crawler(String namedProfile) throws Exception {
    loadSiteList();/*  w  w w . j  a v  a  2 s . c o  m*/

    int sleepTime = (namedProfile.equals("baseline") ? 10 : 5);
    boolean started = false;
    String baseWindow = "";

    FirefoxProfile profile = new ProfilesIni().getProfile(namedProfile);
    //profile.setPreference("webdriver.load.strategy", "fast");

    WebDriver driver = new FirefoxDriver(profile);

    driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
    driver.manage().timeouts().setScriptTimeout(40, TimeUnit.SECONDS);

    // figure out where the fucking profile is. wow!
    String profileDir = getDriverProfile();

    log("Crawling started for " + namedProfile);

    int count = 0;
    for (String url : urls) {
        if (!started) {
            // Original window handle to be used as base. Used so we can close all other popups.  
            baseWindow = driver.getWindowHandle();
            started = true;
        }

        count++;
        log("\t" + count + ". navigating to: " + url);

        CrawlusInterruptus ci = new CrawlusInterruptus(60);
        try {
            ci.start();

            try {
                // Confirm handling for one of those super fucking annoying "Are you sure you wonna go anywhere else?"
                driver.switchTo().alert().accept();
                log("\tAccepted a navigate away modal");
            } catch (Exception e) {
            }

            driver.get("http://" + url);

            // WTF, why would their own fucking wait not work?!?
            // new WebDriverWait(driver, 5 * 1000);
        } catch (TimeoutException te) {
            handleTimeout(baseWindow, url, driver);
        } catch (org.openqa.selenium.UnhandledAlertException me) {
            log("\tModal exception caused by previous site?");

            // Retry current site.
            try {
                driver.get("http://" + url);
            } catch (TimeoutException te) {
                handleTimeout(baseWindow, url, driver);
            }
        } finally {
            ci.interrupt();
        }

        try {
            Thread.sleep(sleepTime * 1000);
        } catch (InterruptedException e) {
        }

        killPopups(baseWindow, driver);
    }

    // 4th party does not know when the crawl is over, so we send a trip signal by navigating to the "last" domain
    try {
        driver.get("http://www.josesignanini.com");
    } catch (TimeoutException te) {
    }
    try {
        Thread.sleep(60 * 1000);
    } catch (InterruptedException e) {
    }

    // copy the fourthparty database out.
    FileUtils.copyFile(new File(profileDir + "/fourthparty.sqlite"),
            new File(path + "/fourthparty-" + namedProfile + ".sqlite"));

    driver.quit();
    log("Crawling completed for " + namedProfile);

    recordLog(namedProfile);
}

From source file:com.expedia.lux.accountsettingstest.core.CreateWebDriverHelper.java

License:Open Source License

public static WebDriver createWebDriverSaucelab(String testName) {
    DesiredCapabilities capabillities = new DesiredCapabilities();
    // Set test name, use to show the test case name on remote site
    List tags = new ArrayList<String>();
    tags.add("LUX5");
    tags.add("PromotionsTest");
    capabillities.setCapability("tags", tags);
    capabillities.setCapability("build", buildNum);
    capabillities.setCapability("idle-timeout", 120);
    capabillities.setCapability("disable-popup-handler", true);
    capabillities.setCapability("record-video", false);
    capabillities.setCapability("video-upload-on-pass", false);
    capabillities.setCapability("capture-html", true);
    capabillities.setCapability("webdriver.remote.quietExceptions", false);
    capabillities.setCapability("sauce-advisor", false);
    // Set test use and password for remote site
    capabillities.setCapability("username", SAUCE_USER);
    capabillities.setCapability("accessKey", SAUCE_KEY);
    capabillities.setCapability("tunnel-identifier", identifier);
    capabillities.setCapability("name", testName);
    capabillities = DesiredCapabilities.chrome();
    capabillities.setBrowserName("chrome");

    try {/*from   w ww . j a  va2  s .c  om*/
        WebDriver driver = new RemoteWebDriver(new URL(remoteSite), capabillities);
        // Set driver implicit time to wait for element to appear
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        return driver;
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}