Search in sources :

Example 71 with ChromeDriver

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

the class ChromeAndFirefoxTest method setupTest.

@Before
public void setupTest() {
    chrome = new ChromeDriver();
    firefox = new FirefoxDriver();
}
Also used : FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Before(org.junit.Before)

Example 72 with ChromeDriver

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

the class SuperCalculatorTest method setUp.

@Before
public void setUp() throws Exception {
    // change according to platformm
    System.setProperty("webdriver.chrome.driver", osName.toLowerCase().startsWith("windows") ? new File("c:/java/selenium/chromedriver.exe").getAbsolutePath() : resolveEnvVars(chromeDriverPath));
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    if (isMobile) {
        Map<String, String> mobileEmulation = new HashMap<>();
        mobileEmulation.put("deviceName", "Google Nexus 5");
        Map<String, Object> chromeOptions = new HashMap<>();
        chromeOptions.put("mobileEmulation", mobileEmulation);
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
        seleniumDriver = new ChromeDriver(capabilities);
        // set ignoreSynchronization to true to handle page sync ourselves
        // instead of using waitForAngular call in JProtractor
        ngDriver = new NgWebDriver(seleniumDriver, true);
    } else {
        /*
			 * DesiredCapabilities capabilities = new
			 * DesiredCapabilities("firefox", "", Platform.ANY); FirefoxProfile
			 * profile = new ProfilesIni().getProfile("default");
			 * profile.setEnableNativeEvents(false);
			 * capabilities.setCapability("firefox_profile", profile);
			 * seleniumDriver = new FirefoxDriver(capabilities);
			 */
        seleniumDriver = new ChromeDriver(capabilities);
        ngDriver = new NgWebDriver(seleniumDriver);
    }
    ngDriver.get(baseUrl);
    ngDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    superCalculatorPage = new SuperCalculatorPage();
    JPageFactory.initElements(ngDriver, channel, superCalculatorPage);
}
Also used : NgWebDriver(com.github.sergueik.jprotractor.NgWebDriver) HashMap(java.util.HashMap) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) Before(org.junit.Before)

Example 73 with ChromeDriver

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

the class TodoListTest method setUp.

@Before
public void setUp() throws Exception {
    // change according to platformm
    System.setProperty("webdriver.chrome.driver", osName.toLowerCase().startsWith("windows") ? new File("c:/java/selenium/chromedriver.exe").getAbsolutePath() : resolveEnvVars(chromeDriverPath));
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    if (isMobile) {
        Map<String, String> mobileEmulation = new HashMap<>();
        mobileEmulation.put("deviceName", "Google Nexus 5");
        Map<String, Object> chromeOptions = new HashMap<>();
        chromeOptions.put("mobileEmulation", mobileEmulation);
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
        seleniumDriver = new ChromeDriver(capabilities);
        // set ignoreSynchronization to true to handle page sync ourselves
        // instead of using waitForAngular call in JProtractor
        ngDriver = new NgWebDriver(seleniumDriver, true);
    } else {
        /*
			 * DesiredCapabilities capabilities = new
			 * DesiredCapabilities("firefox", "", Platform.ANY); FirefoxProfile
			 * profile = new ProfilesIni().getProfile("default");
			 * profile.setEnableNativeEvents(false);
			 * capabilities.setCapability("firefox_profile", profile);
			 * seleniumDriver = new FirefoxDriver(capabilities);
			 */
        seleniumDriver = new ChromeDriver(capabilities);
        ngDriver = new NgWebDriver(seleniumDriver);
    }
    ngDriver.get(baseUrl);
    ngDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    page = new TodoListPage();
    page.setDriver(ngDriver);
    JPageFactory.initElements(ngDriver, channel, page);
}
Also used : NgWebDriver(com.github.sergueik.jprotractor.NgWebDriver) HashMap(java.util.HashMap) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) TodoListPage(org.henrrich.jpagefactory.example.todolist.TodoListPage) Before(org.junit.Before)

Example 74 with ChromeDriver

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

the class FlowPaneEx method setUpSeleniumDriver.

public void setUpSeleniumDriver() {
    // Create a new instance of a driver
    System.setProperty("webdriver.chrome.driver", (new File("c:/java/selenium/chromedriver.exe")).getAbsolutePath());
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    driver = new ChromeDriver(capabilities);
    // Navigate to the right place
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("http://www.google.ca/");
}
Also used : DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File)

Example 75 with ChromeDriver

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

the class CommonFunctions method getSeleniumDriver.

@SuppressWarnings("deprecation")
public static WebDriver getSeleniumDriver() throws IOException {
    checkEnvironment();
    if (isDestopTesting) {
        // For desktop browser testing, run a Selenium node and Selenium hub on
        // port 4444
        // For Vagrant box browser testing have localhost port 4444 forwarded to
        // the hub 4444
        // Alternatively make the test class launch the browser
        osName = System.getProperty("os.name");
        if (browser.equals("chrome")) {
            System.setProperty("webdriver.chrome.driver", new File((chromeDriverPath == null) ? osName.toLowerCase().startsWith("windows") ? "C:\\java\\selenium\\chromedriver.exe" : "/tmp/chromedriver" : chromeDriverPath).getAbsolutePath());
            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);
            options.addArguments("allow-running-insecure-content");
            options.addArguments("allow-insecure-localhost");
            options.addArguments("enable-local-file-accesses");
            options.addArguments("disable-notifications");
            // options.addArguments("start-maximized");
            options.addArguments("browser.download.folderList=2");
            options.addArguments("--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");
            options.addArguments("browser.download.dir=" + downloadFilepath);
            // options.addArguments("user-data-dir=/path/to/your/custom/profile");
            capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
            capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            seleniumDriver = new ChromeDriver(capabilities);
        } else if (browser.equals("firefox")) {
            // alternatively one can add Geckodriver to system path
            System.setProperty("webdriver.gecko.driver", "c:/java/selenium/geckodriver.exe");
            // https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
            DesiredCapabilities capabilities = DesiredCapabilities.firefox();
            // use legacy FirefoxDriver
            capabilities.setCapability("marionette", false);
            // http://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.firefox.FirefoxProfile
            capabilities.setCapability("locationContextEnabled", false);
            capabilities.setCapability("acceptSslCerts", true);
            capabilities.setCapability("elementScrollBehavior", 1);
            FirefoxProfile profile = new FirefoxProfile();
            profile.setAcceptUntrustedCertificates(true);
            profile.setAssumeUntrustedCertificateIssuer(true);
            // no longer supported as of Selenium 3.8.x
            // profile.setEnableNativeEvents(false);
            System.out.println(System.getProperty("user.dir"));
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            try {
                // java.lang.ClassCastException:
                // org.openqa.selenium.remote.service.DriverCommandExecutor cannot be
                // cast to
                // org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor
                seleniumDriver = new FirefoxDriver(capabilities);
            } catch (WebDriverException e) {
                e.printStackTrace();
                throw new RuntimeException("Cannot initialize Firefox driver");
            }
        }
    } else {
        DesiredCapabilities capabilities = new DesiredCapabilities("phantomjs", "", Platform.ANY);
        capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { "--web-security=false", "--ssl-protocol=any", "--ignore-ssl-errors=true", "--local-to-remote-url-access=true", // prevent local file test XMLHttpRequest Exception 101
        "--webdriver-loglevel=INFO" // set to DEBUG for a really verbose console output
        });
        seleniumDriver = new PhantomJSDriver(capabilities);
    }
    return seleniumDriver;
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) HashMap(java.util.HashMap) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException)

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