Search in sources :

Example 86 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project nzbhydra2 by theotherp.

the class WebDriverConfiguration method initializeChromeDriver.

@Bean
@Profile("dev")
protected ChromeDriver initializeChromeDriver() {
    logger.info("Creating chrome web driver");
    System.setProperty("webdriver.chrome.driver", CHROMEDRIVER);
    ChromeDriver webDriver = new ChromeDriver();
    WebDriverConfiguration.webDriver = webDriver;
    return webDriver;
}
Also used : ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Profile(org.springframework.context.annotation.Profile) Bean(org.springframework.context.annotation.Bean)

Example 87 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project zeppelin by apache.

the class WebDriverManager method getWebDriver.

public static WebDriver getWebDriver() {
    WebDriver driver = null;
    try {
        int firefoxVersion = WebDriverManager.getFirefoxVersion();
        LOG.info("Firefox version " + firefoxVersion + " detected");
        downLoadsDir = FileUtils.getTempDirectory().toString();
        String tempPath = downLoadsDir + "/firefox/";
        downloadGeekoDriver(firefoxVersion, tempPath);
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.download.folderList", 2);
        profile.setPreference("browser.download.dir", downLoadsDir);
        profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.download.manager.showAlertOnComplete", false);
        profile.setPreference("browser.download.manager.closeWhenDone", true);
        profile.setPreference("app.update.auto", false);
        profile.setPreference("app.update.enabled", false);
        profile.setPreference("dom.max_script_run_time", 0);
        profile.setPreference("dom.max_chrome_script_run_time", 0);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
        profile.setPreference("network.proxy.type", 0);
        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);
        ImmutableMap<String, String> displayImmutable = ImmutableMap.<String, String>builder().build();
        if ("true".equals(System.getenv("TRAVIS"))) {
            // Run with DISPLAY 99 for TRAVIS or other build machine
            displayImmutable = ImmutableMap.of("DISPLAY", ":99");
        }
        System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
        System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
        driver = new FirefoxDriver(new GeckoDriverService.Builder().usingDriverExecutable(new File(tempPath + "geckodriver")).withEnvironment(displayImmutable).build(), firefoxOptions);
    } catch (Exception e) {
        LOG.error("Exception in WebDriverManager while FireFox Driver ", e);
    }
    if (driver == null) {
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while ChromeDriver ", e);
        }
    }
    if (driver == null) {
        try {
            driver = new SafariDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while SafariDriver ", e);
        }
    }
    String url;
    if (System.getenv("url") != null) {
        url = System.getenv("url");
    } else {
        url = "http://localhost:8080";
    }
    long start = System.currentTimeMillis();
    boolean loaded = false;
    driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS);
    driver.get(url);
    while (System.currentTimeMillis() - start < 60 * 1000) {
        // wait for page load
        try {
            (new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {

                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElement(By.xpath("//i[@uib-tooltip='WebSocket Connected']")).isDisplayed();
                }
            });
            loaded = true;
            break;
        } catch (TimeoutException e) {
            LOG.info("Exception in WebDriverManager while WebDriverWait ", e);
            driver.navigate().to(url);
        }
    }
    if (loaded == false) {
        fail();
    }
    driver.manage().window().maximize();
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) IOException(java.io.IOException) TimeoutException(org.openqa.selenium.TimeoutException) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) GeckoDriverService(org.openqa.selenium.firefox.GeckoDriverService) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) TimeoutException(org.openqa.selenium.TimeoutException)

Example 88 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project BuildRadiator by BuildRadiator.

the class RadiatorWebDriverTest method sharedForAllTests.

@BeforeClass
public static void sharedForAllTests() {
    // Keep the WebDriver browser window open between tests
    ChromeOptions co = new ChromeOptions();
    boolean headless = Boolean.parseBoolean(System.getProperty("HEADLESS", "false"));
    if (headless) {
        co.addArguments("headless");
    }
    co.addArguments("window-size=1200x800");
    DRIVER = new ChromeDriver(co);
    FWD = new FluentWebDriver(DRIVER);
}
Also used : FluentWebDriver(org.seleniumhq.selenium.fluent.FluentWebDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 89 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project java.webdriver by sayems.

the class GetTitle method main.

public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.navigate().to("http://www.google.com");
    JavascriptExecutor js = (JavascriptExecutor) driver;
    System.out.println(js.executeScript("return document.title"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 90 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project java.webdriver by sayems.

the class ScrollUpDown method main.

public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.navigate().to("http://www.google.com");
    JavascriptExecutor js = (JavascriptExecutor) driver;
    // Scroll up
    js.executeScript("scroll(250, 0)");
    // Scroll down
    js.executeScript("window.scrollBy(0,250)", "");
}
Also used : WebDriver(org.openqa.selenium.WebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

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