Search in sources :

Example 76 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method createWebDriver.

private WebDriver createWebDriver(TestName testName) throws IOException {
    String browser = System.getenv("BROWSER");
    if (browser == null)
        browser = "firefox";
    browser = browser.toLowerCase(Locale.ENGLISH);
    String display = getBrowserDisplay();
    switch(browser) {
        case "firefox":
            FirefoxProfile profile = new FirefoxProfile();
            profile.setAlwaysLoadNoFocusLib(true);
            profile.setPreference(LANGUAGE_SELECTOR, "en");
            // Config screen with many plugins can cause FF to complain JS takes too long to complete - set longer timeout
            profile.setPreference(DOM_MAX_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            profile.setPreference(DOM_MAX_CHROME_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            FirefoxBinary binary = new FirefoxBinary();
            if (display != null) {
                binary.setEnvironmentProperty("DISPLAY", display);
            }
            return new FirefoxDriver(binary, profile);
        case "ie":
        case "iexplore":
        case "iexplorer":
            return new InternetExplorerDriver();
        case "chrome":
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", Collections.singletonMap(LANGUAGE_SELECTOR, "en"));
            ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
            if (display != null) {
                builder.withEnvironment(Collections.singletonMap("DISPLAY", display));
            }
            return new ChromeDriver(builder.build(), options);
        case "safari":
            return new SafariDriver();
        case "htmlunit":
            return new HtmlUnitDriver(true);
        case "saucelabs":
        case "saucelabs-firefox":
            DesiredCapabilities caps = DesiredCapabilities.firefox();
            caps.setCapability("version", "29");
            caps.setCapability("platform", "Windows 7");
            caps.setCapability("name", testName.get());
            // if running inside Jenkins, expose build ID
            String tag = System.getenv("BUILD_TAG");
            if (tag != null)
                caps.setCapability("build", tag);
            return new SauceLabsConnection().createWebDriver(caps);
        case "phantomjs":
            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
            capabilities.setCapability(LANGUAGE_SELECTOR, "en");
            capabilities.setCapability(LANGUAGE_SELECTOR_PHANTOMJS, "en");
            return new PhantomJSDriver(capabilities);
        case "remote-webdriver-firefox":
            String u = System.getenv("REMOTE_WEBDRIVER_URL");
            if (StringUtils.isBlank(u)) {
                throw new Error("remote-webdriver-firefox requires REMOTE_WEBDRIVER_URL to be set");
            }
            return new RemoteWebDriver(// http://192.168.99.100:4444/wd/hub
            new URL(u), DesiredCapabilities.firefox());
        default:
            throw new Error("Unrecognized browser type: " + browser);
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) URL(java.net.URL) SafariDriver(org.openqa.selenium.safari.SafariDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SauceLabsConnection(org.jenkinsci.test.acceptance.utils.SauceLabsConnection)

Example 77 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project selenium_java by sergueik.

the class ProtractorDriver method init.

@Before
public void init() throws MalformedURLException {
    log.info("Launching (protractor) in " + browser + "...");
    DesiredCapabilities capabilities = null;
    if (browser.toLowerCase().equals("firefox")) {
        capabilities = capabilitiesFirefox(capabilities);
    } else if (browser.toLowerCase().equals("phantomjs")) {
        capabilities = capabilitiesPhantomJS(capabilities);
    } else if (browser.toLowerCase().equals("chrome")) {
        capabilities = capabilitiesChrome(capabilities);
    } else if (browser.toLowerCase().equals("iexplore")) {
        capabilities = capabilitiesExplorer(capabilities);
    } else if (browser.toLowerCase().equals("android")) {
        capabilities = capabilitiesAndroid(capabilities);
    } else if (browser.toLowerCase().equals("iphone")) {
        capabilities = capabilitiesiPhone(capabilities);
    } else if (browser.toLowerCase().equals("ipad")) {
        capabilities = capabilitiesiPad(capabilities);
    }
    if (!location.toLowerCase().contains("local")) {
        log.info("Running on Selenium Grid: " + location);
        driver = new RemoteWebDriver(new URL(location), capabilities);
    } else if (browser.toLowerCase().equals("firefox")) {
        driver = new FirefoxDriver(capabilities);
    } else if (browser.toLowerCase().equals("phantomjs")) {
        driver = new PhantomJSDriver(capabilities);
    } else if (browser.toLowerCase().equals("chrome")) {
        driver = new ChromeDriver(capabilities);
    } else if (browser.toLowerCase().equals("iexplore")) {
        driver = new InternetExplorerDriver(capabilities);
    } else if (browser.toLowerCase().equals("android")) {
        driver = new ChromeDriver(capabilities);
    } else if (browser.toLowerCase().equals("iphone")) {
        driver = new ChromeDriver(capabilities);
    } else if (browser.toLowerCase().equals("ipad")) {
        driver = new ChromeDriver(capabilities);
    }
    ngDriver = new NgWebDriver(driver);
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
    actions = new Actions(driver);
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) NgWebDriver(com.jprotractor.NgWebDriver) Actions(org.openqa.selenium.interactions.Actions) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) URL(java.net.URL) Before(cucumber.api.java.Before)

Example 78 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project selenium_java by sergueik.

the class RemoteTest method setupTest.

@Before
public void setupTest() throws MalformedURLException {
    DesiredCapabilities capability = DesiredCapabilities.chrome();
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) URL(java.net.URL) Before(org.junit.Before)

Example 79 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project selenium_java by sergueik.

the class GridInfoTest method setup.

@BeforeClass
public void setup() throws Exception {
    determiner = new ActiveNodeDeterminer();
    determiner.setGridPort(PORT);
    determiner.setGridHostName(IP);
    URL url = new URL("http://" + IP + ":" + PORT + "/wd/hub");
    getOsName();
    System.setProperty("webdriver.gecko.driver", osName.toLowerCase().startsWith("windows") ? new File("c:/java/selenium/geckodriver.exe").getAbsolutePath() : "/tmp/geckodriver");
    System.setProperty("webdriver.firefox.bin", osName.toLowerCase().startsWith("windows") ? new File("c:/Program Files (x86)/Mozilla Firefox/firefox.exe").getAbsolutePath() : "/usr/bin/firefox");
    // use legacy FirefoxDriver
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", false);
    driver = new RemoteWebDriver(url, capabilities);
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ActiveNodeDeterminer(com.mycompany.app.ActiveNodeDeterminer) File(java.io.File) URL(java.net.URL) BeforeClass(org.testng.annotations.BeforeClass)

Example 80 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project selenium_java by sergueik.

the class SessionTest method beforeClass.

@BeforeClass
public void beforeClass() throws IOException {
    getOsName();
    if (browser.equals("chrome")) {
        capabilities = DesiredCapabilities.chrome();
    } else if (browser.equals("firefox")) {
        // capabilities = DesiredCapabilities.firefox();
        capabilities = new DesiredCapabilities("firefox", "", Platform.ANY);
        FirefoxProfile profile = new ProfilesIni().getProfile("default");
        capabilities.setCapability("firefox_profile", profile);
    }
    driver = null;
    try {
        driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities);
    } catch (MalformedURLException ex) {
    }
    assertThat(driver, notNullValue());
    actions = new Actions(driver);
    driver.manage().timeouts().setScriptTimeout(scriptTimeout, TimeUnit.SECONDS);
    // Declare a wait time
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
    screenshot = ((TakesScreenshot) driver);
    js = ((JavascriptExecutor) driver);
    driver.manage().window().setSize(new Dimension(600, 800));
    driver.manage().timeouts().pageLoadTimeout(pageLoadTimeout, TimeUnit.SECONDS);
    driver.manage().timeouts().implicitlyWait(implicitlyWaitTimeout, TimeUnit.SECONDS);
    // print the node information
    getIPOfNode(driver);
    // Go to URL
    driver.get(baseURL);
}
Also used : MalformedURLException(java.net.MalformedURLException) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) ProfilesIni(org.openqa.selenium.firefox.internal.ProfilesIni) Actions(org.openqa.selenium.interactions.Actions) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Dimension(org.openqa.selenium.Dimension) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) URL(java.net.URL) TakesScreenshot(org.openqa.selenium.TakesScreenshot) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)101 URL (java.net.URL)39 Test (org.junit.Test)36 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)29 File (java.io.File)16 WebDriver (org.openqa.selenium.WebDriver)14 MalformedURLException (java.net.MalformedURLException)13 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)13 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)12 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)12 IOException (java.io.IOException)11 Dimension (org.openqa.selenium.Dimension)9 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)7 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)6 EventFiringWebDriver (org.openqa.selenium.support.events.EventFiringWebDriver)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5