Search in sources :

Example 31 with ChromeDriver

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

the class NgMultiSelectTest method setUp.

@Before
public void setUp() throws Exception {
    // change according to platform
    // NOTE:
    // java.lang.IllegalStateException: The driver executable does not exist: /var/run/chromedriver
    // java.lang.IllegalStateException: The driver is not executable: /var/run/chromedriver
    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 {
        seleniumDriver = new ChromeDriver(capabilities);
        ngDriver = new NgWebDriver(seleniumDriver);
    }
    ngDriver.get(baseUrl);
    ngDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    page = new NgMultiSelectPage();
    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) Before(org.junit.Before)

Example 32 with ChromeDriver

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

the class NgQualityShepherdTest 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 {
        seleniumDriver = new ChromeDriver(capabilities);
        ngDriver = new NgWebDriver(seleniumDriver);
    }
    ngDriver.get(baseUrl);
    ngDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    page = new NgQualityShepherdPage();
    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) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) Before(org.junit.Before)

Example 33 with ChromeDriver

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

the class AppTest method setupBeforeSuite.

@BeforeSuite(alwaysRun = true)
public void setupBeforeSuite(ITestContext context) throws InterruptedException, MalformedURLException {
    selenium_host = context.getCurrentXmlTest().getParameter("selenium.host");
    selenium_port = context.getCurrentXmlTest().getParameter("selenium.port");
    selenium_browser = context.getCurrentXmlTest().getParameter("selenium.browser");
    selenium_run = context.getCurrentXmlTest().getParameter("selenium.run");
    // Remote Configuration
    if (selenium_browser.compareToIgnoreCase("remote") == 0) {
        String hub = "http://" + selenium_host + ":" + selenium_port + "/wd/hub";
        LoggingPreferences logging_preferences = new LoggingPreferences();
        logging_preferences.enable(LogType.BROWSER, Level.ALL);
        logging_preferences.enable(LogType.CLIENT, Level.INFO);
        logging_preferences.enable(LogType.SERVER, Level.INFO);
        if (selenium_browser.compareToIgnoreCase("chrome") == 0) {
            DesiredCapabilities capabilities = new DesiredCapabilities("chrome", "", Platform.ANY);
            capabilities.setBrowserName("chrome");
            capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
            try {
                driver = new RemoteWebDriver(new URL("http://" + selenium_host + ":" + selenium_port + "/wd/hub"), capabilities);
            } catch (MalformedURLException ex) {
            }
        } else {
            DesiredCapabilities capabilities = new DesiredCapabilities("firefox", "", Platform.ANY);
            capabilities.setBrowserName("firefox");
            FirefoxProfile profile = new ProfilesIni().getProfile("default");
            capabilities.setCapability("firefox_profile", profile);
            capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
            try {
                driver = new RemoteWebDriver(new URL("http://" + selenium_host + ":" + selenium_port + "/wd/hub"), capabilities);
            } catch (MalformedURLException ex) {
            }
        }
    } else // standalone
    {
        if (selenium_browser.compareToIgnoreCase("chrome") == 0) {
            System.setProperty("webdriver.chrome.driver", "c:/java/selenium/chromedriver.exe");
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            LoggingPreferences logging_preferences = new LoggingPreferences();
            logging_preferences.enable(LogType.BROWSER, Level.ALL);
            capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
            /*
			   prefs.js:user_pref("extensions.logging.enabled", true);
			   user.js:user_pref("extensions.logging.enabled", true);
			 */
            driver = new ChromeDriver(capabilities);
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        } else {
            DesiredCapabilities capabilities = DesiredCapabilities.firefox();
            LoggingPreferences logging_preferences = new LoggingPreferences();
            logging_preferences.enable(LogType.BROWSER, Level.ALL);
            capabilities.setCapability(CapabilityType.LOGGING_PREFS, logging_preferences);
            driver = new FirefoxDriver(capabilities);
        }
    }
    try {
        driver.manage().window().setSize(new Dimension(600, 800));
        driver.manage().timeouts().pageLoadTimeout(50, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    } catch (Exception ex) {
        System.out.println(ex.toString());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ProfilesIni(org.openqa.selenium.firefox.internal.ProfilesIni) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) Dimension(org.openqa.selenium.Dimension) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) URL(java.net.URL) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 34 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project teammates by TEAMMATES.

the class Browser method createWebDriver.

private WebDriver createWebDriver() {
    System.out.print("Initializing Selenium: ");
    String browser = TestProperties.BROWSER;
    if ("firefox".equals(browser)) {
        System.out.println("Using Firefox.");
        String firefoxPath = TestProperties.FIREFOX_PATH;
        if (!firefoxPath.isEmpty()) {
            System.out.println("Custom path: " + firefoxPath);
            System.setProperty("webdriver.firefox.bin", firefoxPath);
        }
        // Allow CSV files to be download automatically, without a download popup.
        // This method is used because Selenium cannot directly interact with the download dialog.
        // Taken from http://stackoverflow.com/questions/24852709
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.download.panel.shown", false);
        profile.setPreference("browser.helperApps.neverAsk.openFile", "text/csv,application/vnd.ms-excel");
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/vnd.ms-excel");
        profile.setPreference("browser.download.folderList", 2);
        profile.setPreference("browser.download.dir", System.getProperty("java.io.tmpdir"));
        return new FirefoxDriver(profile);
    } else if ("chrome".equals(browser)) {
        System.out.println("Using Chrome with driver path: " + TestProperties.CHROMEDRIVER_PATH);
        System.setProperty("webdriver.chrome.driver", TestProperties.CHROMEDRIVER_PATH);
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--allow-file-access-from-files");
        return new ChromeDriver(options);
    }
    System.out.println("Using " + browser + " is not supported!");
    return null;
}
Also used : FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 35 with ChromeDriver

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

the class RunASingleTest method FallbackDriver.

public void FallbackDriver(String fallbackdriver) {
    if ("HTMLUnit".equals(fallbackdriver)) {
        STAppData.setTargetBrowser("Silent Mode (HTMLUnit)");
        STAppFrame.setTargetBrowserView("Silent Mode (HTMLUnit)");
        driver = new HtmlUnitDriver();
    } else {
        STAppData.setTargetBrowser("Chrome 49");
        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)

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