Search in sources :

Example 26 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project browsermator by pcalkins.

the class RunAllTests method FallbackDriver.

public void FallbackDriver(String fallbackdriver) {
    if ("HTMLUnit".equals(fallbackdriver)) {
        STAppData.setTargetBrowser("Silent Mode (HTMLUnit)");
        if (RUNWITHGUI) {
            STAppFrame.setTargetBrowserView("Silent Mode (HTMLUnit)");
        }
        driver = new HtmlUnitDriver();
    } else {
        STAppData.setTargetBrowser("Chrome 49");
        if (RUNWITHGUI) {
            STAppFrame.setTargetBrowserView("Chrome 49");
        }
        ChromeOptions optionsfallback49 = new ChromeOptions();
        optionsfallback49.setBinary(chrome_path);
        System.setProperty("webdriver.chrome.driver", WEBDRIVERSDIR + "chromedriver_win32" + File.separator + "chromedriver-winxp.exe");
        driver = new ChromeDriver(optionsfallback49);
    }
}
Also used : ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Example 27 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project scout.rt by eclipse.

the class SeleniumDriver method setUpDriver.

public static WebDriver setUpDriver() {
    // web-driver executable
    String webdriverChromeDriver = System.getProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY);
    if (StringUtility.isNullOrEmpty(webdriverChromeDriver)) {
        webdriverChromeDriver = OS.isFamilyWindows() ? "/seleniumDrivers/chromedriver.exe" : "/seleniumDrivers/chromedriver";
    }
    File chromeDriver = new File(webdriverChromeDriver);
    if (!chromeDriver.exists()) {
        System.out.println("Chrome driver executable not found at path: " + chromeDriver);
        URL webdriverChromeDriverResource = SeleniumDriver.class.getResource(webdriverChromeDriver);
        if (webdriverChromeDriverResource != null) {
            chromeDriver = new File(webdriverChromeDriverResource.getFile());
            webdriverChromeDriver = chromeDriver.getAbsolutePath();
        }
    }
    if (!StringUtility.matches(webdriverChromeDriver, ".+\\.exe", Pattern.CASE_INSENSITIVE) && chromeDriver.exists() && !chromeDriver.canExecute()) {
        chromeDriver.setExecutable(true);
    }
    System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, webdriverChromeDriver);
    logProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, webdriverChromeDriver);
    // log-file for web-driver
    File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    File logFile = new File(tmpDir, "webdriver.log");
    String logFilePath = logFile.getAbsolutePath();
    System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, logFilePath);
    logProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, logFilePath);
    // set web-driver in verbose mode
    System.setProperty(ChromeDriverService.CHROME_DRIVER_VERBOSE_LOG_PROPERTY, "true");
    logProperty(ChromeDriverService.CHROME_DRIVER_VERBOSE_LOG_PROPERTY, "true");
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    // Prepare options
    ChromeOptions options = new ChromeOptions();
    String chromeBinary = System.getProperty("chrome.binary");
    logProperty("chrome.binary", chromeBinary);
    if (StringUtility.hasText(chromeBinary)) {
        options.setBinary(chromeBinary);
    }
    options.addArguments("--lang=en");
    options.addArguments("--verbose");
    options.addArguments("--disable-infobars");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    // Set logging preferences (see BrowserLogRule)
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    // TODO [7.0] BSH Remove workaround, when Chrome bug is fixed
    // <WORKAROUND> https://bugs.chromium.org/p/chromedriver/issues/detail?id=1552
    Map<String, String> env = new HashMap<>();
    env.put("LANG", "en_US.UTF-8");
    System.out.println("Using custom environment variables for driver: " + new JSONObject(env).toString(2));
    RemoteWebDriver driver = new ChromeDriver(new ChromeDriverService.Builder().usingAnyFreePort().withEnvironment(// <--
    env).build(), capabilities);
    // RemoteWebDriver driver = new ChromeDriver(options)
    // </WORKAROUND>
    driver.manage().timeouts().setScriptTimeout(10000, TimeUnit.SECONDS);
    // Set window size roughly to the minimal supported screen size
    // (1280x1024 minus some borders for browser toolbar and windows taskbar)
    // Add extra 50 pixel height, because of yellow bar "Chrome is being controlled..." which comes up since v 65.0.3325
    // even tough the disable-infobars property is set - doesn't work anymore :-(
    driver.manage().window().setPosition(new Point(0, 0));
    driver.manage().window().setSize(new Dimension(1200, 900 + 50));
    Capabilities caps = driver.getCapabilities();
    System.out.println("Selenium driver configured with driver=" + driver.getClass().getName() + " browser.name=" + caps.getBrowserName() + " browser.version=" + caps.getVersion());
    return driver;
}
Also used : HashMap(java.util.HashMap) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) URL(java.net.URL) JSONObject(org.json.JSONObject) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File)

Example 28 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project muikku by otavanopisto.

the class AbstractUITest method createChromeDriver.

protected RemoteWebDriver createChromeDriver() {
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--lang=en_US");
    options.addArguments("--start-maximized");
    ChromeDriver chromeDriver = new ChromeDriver(options);
    return chromeDriver;
}
Also used : ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 29 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project chrome_page_performance_sqlite_java by sergueik.

the class ChromePagePerformanceObjectTest method beforeClass.

@SuppressWarnings("deprecation")
@BeforeClass
public static void beforeClass() throws IOException {
    getOsName();
    System.setProperty("webdriver.chrome.driver", osName.toLowerCase().startsWith("windows") ? new File("c:/java/selenium/chromedriver.exe").getAbsolutePath() : "/var/run/chromedriver");
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    ChromeOptions options = new ChromeOptions();
    Map<String, Object> chromePrefs = new HashMap<>();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    String downloadFilepath = System.getProperty("user.dir") + System.getProperty("file.separator") + "target" + System.getProperty("file.separator");
    chromePrefs.put("download.default_directory", downloadFilepath);
    chromePrefs.put("enableNetwork", "true");
    options.setExperimentalOption("prefs", chromePrefs);
    for (String option : (new String[] { "allow-running-insecure-content", "allow-insecure-localhost", "enable-local-file-accesses", "disable-notifications", /* "start-maximized" , */
    "browser.download.folderList=2", "--browser.helperApps.neverAsk.saveToDisk=image/jpg,text/csv,text/xml,application/xml,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/excel,application/pdf", String.format("browser.download.dir=%s", downloadFilepath) /* "user-data-dir=/path/to/your/custom/profile"  , */
    })) {
        options.addArguments(option);
    }
    // options for headless
    if (headless) {
        // headless option arguments
        for (String option : (osName.toLowerCase().startsWith("windows")) ? new String[] { "headless", "disable-gpu", "disable-plugins", "window-size=1200x600", "window-position=-9999,0" } : new String[] { "headless", "disable-gpu", "remote-debugging-port=9222", "window-size=1200x600" }) {
            options.addArguments(option);
        }
    // on Windows need ChromeDriver 2.31 / Chrome 60 to support headless
    // With earlier versions of chromedriver: chrome not reachable...
    // https://developers.google.com/web/updates/2017/04/headless-chrome
    // https://stackoverflow.com/questions/43880619/headless-chrome-and-selenium-on-windows
    }
    // 
    capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    driver = new ChromeDriver(capabilities);
    try {
        // origin:
        // https://www.tutorialspoint.com/sqlite/sqlite_java.htm
        Class.forName("org.sqlite.JDBC");
        // String dbURL = "jdbc:sqlite:performance.db";
        conn = DriverManager.getConnection("jdbc:sqlite:performance.db");
        if (conn != null) {
            // System.out.println("Connected to the database");
            DatabaseMetaData databaseMetadata = conn.getMetaData();
            System.out.println("Driver name: " + databaseMetadata.getDriverName());
            System.out.println("Driver version: " + databaseMetadata.getDriverVersion());
            System.out.println("Product name: " + databaseMetadata.getDatabaseProductName());
            System.out.println("Product version: " + databaseMetadata.getDatabaseProductVersion());
            createNewTable();
        // insertData("name", 1.0);
        // conn.close();
        }
    } catch (ClassNotFoundException | SQLException ex) {
        ex.printStackTrace();
    } finally {
    }
    assertThat(driver, notNullValue());
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) DatabaseMetaData(java.sql.DatabaseMetaData) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 30 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project flow by vaadin.

the class ChromeBrowserTest method createHeadlessChromeDriver.

private WebDriver createHeadlessChromeDriver() {
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--headless", "--disable-gpu");
    return TestBench.createDriver(new ChromeDriver(options));
}
Also used : ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Aggregations

ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)50 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)39 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)28 File (java.io.File)20 HashMap (java.util.HashMap)19 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)16 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)10 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)8 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)8 WebDriver (org.openqa.selenium.WebDriver)7 Actions (org.openqa.selenium.interactions.Actions)7 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)6 URL (java.net.URL)5 WebDriverException (org.openqa.selenium.WebDriverException)5 LoggingPreferences (org.openqa.selenium.logging.LoggingPreferences)5 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)5 ArrayList (java.util.ArrayList)4 BeforeClass (org.junit.BeforeClass)4 TakesScreenshot (org.openqa.selenium.TakesScreenshot)4 ChromeDriverService (org.openqa.selenium.chrome.ChromeDriverService)4