Search in sources :

Example 66 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project cia by Hack23.

the class AbstractRoleSystemTest method getWebDriver.

/**
 * Gets the web driver.
 *
 * @return the web driver
 */
protected final synchronized WebDriver getWebDriver() {
    WebDriver driver = null;
    if ("firefox".equals(browser)) {
        final DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);
        driver = new FirefoxDriver(capabilities);
        driver.manage().window().maximize();
    } else if ("chrome".equals(browser)) {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--allow-insecure-localhost", "--start-maximized");
        driver = new ChromeDriver(chromeOptions);
    } else if ("htmlunit-firefox".equals(browser)) {
        final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_45);
        htmlUnitDriver.setJavascriptEnabled(true);
        driver = htmlUnitDriver;
    } else if ("htmlunit-ie11".equals(browser)) {
        final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.INTERNET_EXPLORER);
        htmlUnitDriver.setJavascriptEnabled(true);
        driver = htmlUnitDriver;
    } else if ("htmlunit-edge".equals(browser)) {
        final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.EDGE);
        htmlUnitDriver.setJavascriptEnabled(true);
        driver = htmlUnitDriver;
    } else if ("htmlunit-chrome".equals(browser)) {
        final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.CHROME);
        htmlUnitDriver.setJavascriptEnabled(true);
        driver = htmlUnitDriver;
    } else {
        fail("No valid browser parameter:" + browser);
    }
    driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
    driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
    webDriverMap.put(browser, driver);
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Example 67 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method createWebDriver.

private WebDriver createWebDriver(TestName testName) throws IOException {
    String browser = System.getenv("BROWSER");
    if (browser == null)
        browser = "firefox";
    browser = browser.toLowerCase(Locale.ENGLISH);
    String display = getBrowserDisplay();
    switch(browser) {
        case "firefox":
            FirefoxProfile profile = new FirefoxProfile();
            profile.setAlwaysLoadNoFocusLib(true);
            profile.setPreference(LANGUAGE_SELECTOR, "en");
            // Config screen with many plugins can cause FF to complain JS takes too long to complete - set longer timeout
            profile.setPreference(DOM_MAX_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            profile.setPreference(DOM_MAX_CHROME_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            FirefoxBinary binary = new FirefoxBinary();
            if (display != null) {
                binary.setEnvironmentProperty("DISPLAY", display);
            }
            return new FirefoxDriver(binary, profile);
        case "ie":
        case "iexplore":
        case "iexplorer":
            return new InternetExplorerDriver();
        case "chrome":
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", Collections.singletonMap(LANGUAGE_SELECTOR, "en"));
            ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
            if (display != null) {
                builder.withEnvironment(Collections.singletonMap("DISPLAY", display));
            }
            return new ChromeDriver(builder.build(), options);
        case "safari":
            return new SafariDriver();
        case "htmlunit":
            return new HtmlUnitDriver(true);
        case "saucelabs":
        case "saucelabs-firefox":
            DesiredCapabilities caps = DesiredCapabilities.firefox();
            caps.setCapability("version", "29");
            caps.setCapability("platform", "Windows 7");
            caps.setCapability("name", testName.get());
            // if running inside Jenkins, expose build ID
            String tag = System.getenv("BUILD_TAG");
            if (tag != null)
                caps.setCapability("build", tag);
            return new SauceLabsConnection().createWebDriver(caps);
        case "phantomjs":
            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
            capabilities.setCapability(LANGUAGE_SELECTOR, "en");
            capabilities.setCapability(LANGUAGE_SELECTOR_PHANTOMJS, "en");
            return new PhantomJSDriver(capabilities);
        case "remote-webdriver-firefox":
            String u = System.getenv("REMOTE_WEBDRIVER_URL");
            if (StringUtils.isBlank(u)) {
                throw new Error("remote-webdriver-firefox requires REMOTE_WEBDRIVER_URL to be set");
            }
            return new RemoteWebDriver(// http://192.168.99.100:4444/wd/hub
            new URL(u), DesiredCapabilities.firefox());
        default:
            throw new Error("Unrecognized browser type: " + browser);
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) URL(java.net.URL) SafariDriver(org.openqa.selenium.safari.SafariDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SauceLabsConnection(org.jenkinsci.test.acceptance.utils.SauceLabsConnection)

Example 68 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project selenium_java by sergueik.

the class ChromePagePerformanceUtil method getLoadTime.

public double getLoadTime(String endUrl, By by) {
    WebDriver driver = new ChromeDriver();
    WebDriverWait wait = new WebDriverWait(driver, flexibleWait);
    driver.navigate().to(endUrl);
    if (by != null) {
        wait.until(ExpectedConditions.presenceOfElementLocated(by)).click();
    }
    waitPageToLoad(driver, wait);
    setTimer(driver);
    return calculateLoadTime();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 69 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project selenium_java by sergueik.

the class ChromePagePerformanceUtil method getLoadTime.

public double getLoadTime(String endUrl) {
    WebDriver driver = new ChromeDriver();
    WebDriverWait wait = new WebDriverWait(driver, flexibleWait);
    driver.navigate().to(endUrl);
    waitPageToLoad(driver, wait);
    setTimer(driver);
    return calculateLoadTime();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 70 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project selenium_java by sergueik.

the class ProtractorDriver method init.

@Before
public void init() throws MalformedURLException {
    log.info("Launching (protractor) in " + browser + "...");
    DesiredCapabilities capabilities = null;
    if (browser.toLowerCase().equals("firefox")) {
        capabilities = capabilitiesFirefox(capabilities);
    } else if (browser.toLowerCase().equals("phantomjs")) {
        capabilities = capabilitiesPhantomJS(capabilities);
    } else if (browser.toLowerCase().equals("chrome")) {
        capabilities = capabilitiesChrome(capabilities);
    } else if (browser.toLowerCase().equals("iexplore")) {
        capabilities = capabilitiesExplorer(capabilities);
    } else if (browser.toLowerCase().equals("android")) {
        capabilities = capabilitiesAndroid(capabilities);
    } else if (browser.toLowerCase().equals("iphone")) {
        capabilities = capabilitiesiPhone(capabilities);
    } else if (browser.toLowerCase().equals("ipad")) {
        capabilities = capabilitiesiPad(capabilities);
    }
    if (!location.toLowerCase().contains("local")) {
        log.info("Running on Selenium Grid: " + location);
        driver = new RemoteWebDriver(new URL(location), capabilities);
    } else if (browser.toLowerCase().equals("firefox")) {
        driver = new FirefoxDriver(capabilities);
    } else if (browser.toLowerCase().equals("phantomjs")) {
        driver = new PhantomJSDriver(capabilities);
    } else if (browser.toLowerCase().equals("chrome")) {
        driver = new ChromeDriver(capabilities);
    } else if (browser.toLowerCase().equals("iexplore")) {
        driver = new InternetExplorerDriver(capabilities);
    } else if (browser.toLowerCase().equals("android")) {
        driver = new ChromeDriver(capabilities);
    } else if (browser.toLowerCase().equals("iphone")) {
        driver = new ChromeDriver(capabilities);
    } else if (browser.toLowerCase().equals("ipad")) {
        driver = new ChromeDriver(capabilities);
    }
    ngDriver = new NgWebDriver(driver);
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
    actions = new Actions(driver);
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) NgWebDriver(com.jprotractor.NgWebDriver) Actions(org.openqa.selenium.interactions.Actions) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) URL(java.net.URL) Before(cucumber.api.java.Before)

Aggregations

ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)91 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)41 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)39 File (java.io.File)33 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)27 WebDriver (org.openqa.selenium.WebDriver)24 HashMap (java.util.HashMap)21 Before (org.junit.Before)13 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)13 URL (java.net.URL)11 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)11 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)11 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)11 Test (org.junit.Test)10 ChromeDriverService (org.openqa.selenium.chrome.ChromeDriverService)9 Actions (org.openqa.selenium.interactions.Actions)9 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)9 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)8 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)7 SafariDriver (org.openqa.selenium.safari.SafariDriver)7