Search in sources :

Example 41 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver 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 42 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project ghostdriver by detro.

the class BaseTest method prepareDriver.

@Before
public void prepareDriver() throws Exception {
    // Which driver to use? (default "phantomjs")
    String driver = sConfig.getProperty("driver", DRIVER_PHANTOMJS);
    // Start appropriate Driver
    if (isUrl(driver)) {
        sCaps.setBrowserName("phantomjs");
        mDriver = new RemoteWebDriver(new URL(driver), sCaps);
    } else if (driver.equals(DRIVER_FIREFOX)) {
        mDriver = new FirefoxDriver(sCaps);
    } else if (driver.equals(DRIVER_CHROME)) {
        mDriver = new ChromeDriver(sCaps);
    } else if (driver.equals(DRIVER_PHANTOMJS)) {
        mDriver = new PhantomJSDriver(sCaps);
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) URL(java.net.URL) Before(org.junit.Before)

Example 43 with ChromeDriver

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

the class GetHeight 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");
    driver.manage().window().setSize(new Dimension(1024, 768));
    driver.quit();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Dimension(org.openqa.selenium.Dimension) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 44 with ChromeDriver

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

the class GetWindowName 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 window.name"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 45 with ChromeDriver

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

the class UrlEditorWebDriverTest 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) BeforeClass(org.junit.BeforeClass)

Aggregations

ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)98 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)47 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)39 File (java.io.File)33 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)27 WebDriver (org.openqa.selenium.WebDriver)25 HashMap (java.util.HashMap)24 Before (org.junit.Before)15 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)13 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)13 URL (java.net.URL)12 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)12 Test (org.junit.Test)10 ChromeDriverService (org.openqa.selenium.chrome.ChromeDriverService)10 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)10 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)9 Actions (org.openqa.selenium.interactions.Actions)9 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)9 BeforeClass (org.junit.BeforeClass)7 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)7