Search in sources :

Example 1 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project webmagic by code4craft.

the class SeleniumTest method testSelenium.

@Ignore("need chrome driver")
@Test
public void testSelenium() {
    System.getProperties().setProperty("webdriver.chrome.driver", "/Users/yihua/Downloads/chromedriver");
    Map<String, Object> contentSettings = new HashMap<String, Object>();
    contentSettings.put("images", 2);
    Map<String, Object> preferences = new HashMap<String, Object>();
    preferences.put("profile.default_content_settings", contentSettings);
    DesiredCapabilities caps = DesiredCapabilities.chrome();
    caps.setCapability("chrome.prefs", preferences);
    caps.setCapability("chrome.switches", Arrays.asList("--user-data-dir=/Users/yihua/temp/chrome"));
    WebDriver webDriver = new ChromeDriver(caps);
    webDriver.get("http://huaban.com/");
    WebElement webElement = webDriver.findElement(By.xpath("/html"));
    System.out.println(webElement.getAttribute("outerHTML"));
    webDriver.close();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HashMap(java.util.HashMap) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) WebElement(org.openqa.selenium.WebElement) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project Ebselen by Ardesco.

the class EbselenCore method setHTMLUnitCapabilities.

private DesiredCapabilities setHTMLUnitCapabilities(htmlUnitEmulation browserVersion) {
    DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
    capabilities.setJavascriptEnabled(true);
    switch(browserVersion) {
        case FIREFOX:
            capabilities.setBrowserName("firefox");
            break;
        case IE6:
            capabilities.setBrowserName("internet explorer");
            capabilities.setVersion("6");
            break;
        case IE7:
            capabilities.setBrowserName("internet explorer");
            capabilities.setVersion("7");
            break;
        case IE8:
            capabilities.setBrowserName("internet explorer");
            capabilities.setVersion("8");
            break;
        default:
            break;
    }
    return capabilities;
}
Also used : DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities)

Example 3 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project page-factory-2 by sbtqa.

the class TagMobileDriver method createDriver.

private static void createDriver() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName", PROPERTIES.getAppiumDeviceName());
    capabilities.setCapability("platformVersion", PROPERTIES.getAppiumDevicePlatform());
    capabilities.setCapability("appPackage", PROPERTIES.getAppiumAppPackage());
    capabilities.setCapability("appActivity", PROPERTIES.getAppiumAppActivity());
    capabilities.setCapability("autoGrantPermissions", "true");
    capabilities.setCapability("unicodeKeyboard", "true");
    capabilities.setCapability("resetKeyboard", "true");
    LOG.info("Capabilities are {}", capabilities);
    URL url;
    try {
        url = new URL(PROPERTIES.getAppiumUrl());
    } catch (MalformedURLException e) {
        throw new FactoryRuntimeException("Could not parse appium url. Check 'appium.url' property", e);
    }
    PageFactory.setAspectsEnabled(false);
    LOG.debug("Aspect disabled");
    mobileDriver = new AndroidDriver<>(url, capabilities);
    LOG.info("Mobile driver created {}", mobileDriver);
    deviceUdId = (String) mobileDriver.getSessionDetails().get("deviceUDID");
}
Also used : MalformedURLException(java.net.MalformedURLException) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FactoryRuntimeException(ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException) URL(java.net.URL)

Example 4 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project page-factory-2 by sbtqa.

the class TagWebDriver method createDriver.

private static void createDriver() throws UnsupportedBrowserException, MalformedURLException {
    DesiredCapabilities capabilities = new WebDriverCapabilitiesParser().parse();
    if (!PROPERTIES.getProxy().isEmpty()) {
        Proxy seleniumProxy = ProxyConfigurator.configureProxy();
        capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
    }
    String browserName = getBrowserName();
    capabilities.setBrowserName(browserName);
    String webDriverUrl = PROPERTIES.getWebDriverUrl();
    if (!webDriverUrl.isEmpty()) {
        setWebDriver(createRemoteWebDriver(webDriverUrl, capabilities));
    } else {
        if (browserName.equalsIgnoreCase(FIREFOX)) {
            setWebDriver(new FirefoxDriver(capabilities));
        } else if (browserName.equalsIgnoreCase(SAFARI)) {
            setWebDriver(new SafariDriver(capabilities));
        } else if (browserName.equalsIgnoreCase(CHROME)) {
            WebDriverManagerConfigurator.configureDriver(ChromeDriverManager.getInstance(), CHROME);
            setWebDriver(new ChromeDriver(capabilities));
        } else if (browserName.equalsIgnoreCase(IE)) {
            WebDriverManagerConfigurator.configureDriver(InternetExplorerDriverManager.getInstance(), IE);
            setWebDriver(new InternetExplorerDriver(capabilities));
        } else {
            throw new UnsupportedBrowserException("'" + browserName + "' is not supported yet");
        }
    }
    webDriver.manage().timeouts().pageLoadTimeout(PageFactory.getTimeOutInSeconds(), TimeUnit.SECONDS);
    setBrowserSize();
    webDriver.get(PROPERTIES.getStartingUrl());
}
Also used : UnsupportedBrowserException(ru.sbtqa.tag.pagefactory.exceptions.UnsupportedBrowserException) Proxy(org.openqa.selenium.Proxy) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebDriverCapabilitiesParser(ru.sbtqa.tag.pagefactory.support.capabilities.WebDriverCapabilitiesParser) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 5 with DesiredCapabilities

use of org.openqa.selenium.remote.DesiredCapabilities in project android by nextcloud.

the class Common method setUpCommonDriver.

protected AndroidDriver setUpCommonDriver() throws Exception {
    File rootPath = new File(System.getProperty("user.dir"));
    File appDir = new File(rootPath, "src/test/resources");
    File app = new File(appDir, "ownCloud.apk");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("deviceName", "test");
    capabilities.setCapability("app", app.getAbsolutePath());
    capabilities.setCapability("appPackage", "com.owncloud.android");
    capabilities.setCapability("appActivity", ".ui.activity.FileDisplayActivity");
    capabilities.setCapability("appWaitActivity", ".authentication.AuthenticatorActivity");
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(waitingTime, TimeUnit.SECONDS);
    wait = new WebDriverWait(driver, waitingTime, 50);
    return driver;
}
Also used : DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) AndroidDriver(io.appium.java_client.android.AndroidDriver) File(java.io.File) URL(java.net.URL)

Aggregations

DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)177 File (java.io.File)55 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)40 URL (java.net.URL)34 HashMap (java.util.HashMap)34 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)30 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)29 Test (org.testng.annotations.Test)22 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)20 BeforeClass (org.junit.BeforeClass)19 TestSetup (com.coveros.selenified.utilities.TestSetup)17 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)17 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)16 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)14 MalformedURLException (java.net.MalformedURLException)13 Before (org.junit.Before)13 Test (org.junit.Test)13 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)12 Actions (org.openqa.selenium.interactions.Actions)12 Dimension (org.openqa.selenium.Dimension)11