Java Code Examples for org.openqa.selenium.remote.DesiredCapabilities#setCapability()

The following examples show how to use org.openqa.selenium.remote.DesiredCapabilities#setCapability() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UiTestBase.java    From cloud-personslist-scenario with Apache License 2.0 6 votes vote down vote up
private static void setupFirefox() {
	final DesiredCapabilities capabilities = new DesiredCapabilities();
	final String proxyHost = System.getProperty("http.proxyHost");
	final String proxyPort = System.getProperty("http.proxyPort");
	if (proxyHost != null) {
		System.out
				.println("Configuring Firefox Selenium web driver with proxy "
						+ proxyHost
						+ (proxyPort == null ? "" : ":" + proxyPort)
						+ " (requires Firefox browser)");
		final Proxy proxy = new Proxy();
		final String proxyString = proxyHost
				+ (proxyPort == null ? "" : ":" + proxyPort);
		proxy.setHttpProxy(proxyString).setSslProxy(proxyString);
		proxy.setNoProxy("localhost");
		capabilities.setCapability(CapabilityType.PROXY, proxy);
	} else {
		System.out
				.println("Configuring Firefox Selenium web driver without proxy (requires Firefox browser)");
	}

	driver = new FirefoxDriver(capabilities);
	driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
 
Example 2
Source File: SearchTest.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 6 votes vote down vote up
@BeforeTest
public void setUp() throws Exception {


    String USERNAME = "benehmke";
    String AUTOMATE_KEY = "RzA1hJpssWs1i4NcxRxR";
    String URL = "https://" + USERNAME + ":"
            + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

    // Set the desired capabilities for iPhone X
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("browserName", "iPhone");
    caps.setCapability("device", "iPhone X");
    caps.setCapability("realMobile", "true");
    caps.setCapability("os_version", "11.0");

    driver = new RemoteWebDriver(new URL(URL), caps);

    driver.get("http://demo-store.seleniumacademy.com/");
}
 
Example 3
Source File: BaseTest.java    From test-samples with Apache License 2.0 6 votes vote down vote up
private void setupRemoteDriver(String device, String xmlTestName) throws MalformedURLException {
    loadProperties(device);

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("bitbar_apiKey", "<YOUR_BITBAR_API_KEY>");
    capabilities.setCapability("bitbar_testrun", this.getClass().getSimpleName());
    capabilities.setCapability("bitbar_project", xmlTestName);
    capabilities.setCapability("bitbar_device", bitbarDevice);
    capabilities.setCapability("browserName", browserName);
    capabilities.setCapability("platformName", platformName);
    capabilities.setCapability("deviceName", deviceName);
    if (automationName != null)
        capabilities.setCapability("automationName", automationName);

    driver.set(new RemoteWebDriver(new URL("https://appium.bitbar.com/wd/hub/"), capabilities));
}
 
Example 4
Source File: StartingAppLocallyTest.java    From java-client with Apache License 2.0 5 votes vote down vote up
@Test public void startingAndroidAppWithCapabilitiesAndFlagsOnServerSideTest() {
    DesiredCapabilities serverCapabilities = new DesiredCapabilities();
    serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
    serverCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true);
    serverCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60);
    serverCapabilities.setCapability(MobileCapabilityType.APP, apiDemosApk().toAbsolutePath().toString());

    WebDriverManager chromeManager = chromedriver();
    chromeManager.setup();
    serverCapabilities.setCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE,
            chromeManager.getBinaryPath());

    AppiumServiceBuilder builder = new AppiumServiceBuilder()
            .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
            .withArgument(GeneralServerFlag.STRICT_CAPS).withCapabilities(serverCapabilities);

    DesiredCapabilities clientCapabilities = new DesiredCapabilities();
    clientCapabilities
        .setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis");
    clientCapabilities
        .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1");

    AndroidDriver<?> driver = new AndroidDriver<>(builder, clientCapabilities);
    try {
        Capabilities caps = driver.getCapabilities();

        assertEquals(MobilePlatform.ANDROID, caps.getCapability(MobileCapabilityType.PLATFORM_NAME));
        assertNotEquals(null, caps.getCapability(MobileCapabilityType.DEVICE_NAME));
    } finally {
        driver.quit();
    }
}
 
Example 5
Source File: Edition118_Multi_Device.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
private AndroidDriver<WebElement> getChrome() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("deviceName", "Android Emulator");
    capabilities.setCapability("browserName", "Chrome");
    capabilities.setCapability("automationName", "UiAutomator2");
    return new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);
}
 
Example 6
Source File: Edition028_Parallel_Testing_iOS.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogin_iOS() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "iOS");
    capabilities.setCapability("platformVersion", "11.4");
    capabilities.setCapability("deviceName", "iPhone 8");
    capabilities.setCapability("wdaLocalPort", 8100);
    capabilities.setCapability("app", APP);

    IOSDriver driver = new IOSDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);
    actualTest(driver);
}
 
Example 7
Source File: Edition107_Generic_Swipe_Actions_Android.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("platformName", "Android");
    caps.setCapability("deviceName", "Android Emulator");
    caps.setCapability("app", APP);
    driver = new AndroidDriver<MobileElement>(new URL("http://localhost:4723/wd/hub"), caps);
}
 
Example 8
Source File: BaseTest.java    From at.info-knowledge-base with MIT License 5 votes vote down vote up
private DesiredCapabilities getDesireCapabilities() {
    final DesiredCapabilities capability = new DesiredCapabilities();

    if (proxy != null && seleniumProxy != null) {
        capability.setCapability(CapabilityType.PROXY, seleniumProxy);
    } else {
        final Proxy noProxy = new Proxy();
        noProxy.setProxyType(Proxy.ProxyType.DIRECT);
        capability.setCapability(CapabilityType.PROXY, noProxy);
    }

    return capability;
}
 
Example 9
Source File: UtilsTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void providesRemoteAccessToAppCache() {
  DesiredCapabilities caps = new DesiredCapabilities();
  caps.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true);

  CapableDriver driver = mock(CapableDriver.class);
  when(driver.getCapabilities()).thenReturn(caps);
  when(driver.execute(DriverCommand.GET_APP_CACHE_STATUS, null))
      .thenReturn(AppCacheStatus.CHECKING.name());

  ApplicationCache cache = Utils.getApplicationCache(driver);
  assertEquals(AppCacheStatus.CHECKING, cache.getStatus());
}
 
Example 10
Source File: CapabilityConfig.java    From phoenix.webui.framework with Apache License 2.0 5 votes vote down vote up
/**
 * ie浏览器
 */
private void ie()
{
	String initialUrl = enginePro.getProperty(DriverConstants.INITIAL_URL,
			"http://surenpi.com");
	
	DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
	capability.setCapability(
			InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
	capability.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, initialUrl);
	capability.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, false);
	engineCapMap.put(DRIVER_IE, capability);
}
 
Example 11
Source File: JavaDriverLogsTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void loglevelsAreRespected() {
    LoggingPreferences prefs = new LoggingPreferences();
    prefs.enable(LogType.DRIVER, Level.WARNING);
    DesiredCapabilities caps = JavaDriver.defaultCapabilities();
    caps.setCapability(CapabilityType.LOGGING_PREFS, prefs);
    driver = new JavaDriver(caps, caps);
    LogEntries logEntries = driver.manage().logs().get(LogType.DRIVER);
    List<LogEntry> all = logEntries.getAll();
    AssertJUnit.assertEquals(0, all.size());
}
 
Example 12
Source File: Edition031_iOS_Alerts.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("platformName", "iOS");
    caps.setCapability("platformVersion", "11.4");
    caps.setCapability("deviceName", "iPhone 6");
    caps.setCapability("app", APP);
    driver = new IOSDriver<MobileElement>(new URL("http://localhost:4723/wd/hub"), caps);
    wait  = new WebDriverWait(driver, 10);
}
 
Example 13
Source File: Browser.java    From coteafs-selenium with Apache License 2.0 5 votes vote down vote up
private static void setupCloud(final RemoteSetting remoteSetting, final DesiredCapabilities caps,
                               final String source) {
    final Map<String, Object> capabilities = remoteSetting.getCapabilities();
    capabilities.forEach(caps::setCapability);
    if (isNotEmpty(source)) {
        caps.setCapability(format("{0}:options", source), remoteSetting.getCloudCapabilities());
    }
}
 
Example 14
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void succeedsWhenRequestingNativeEventsCapability() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities("java", "1.0", Platform.getCurrent());
    caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    Capabilities capabilities = ((RemoteWebDriver) driver).getCapabilities();
    AssertJUnit.assertTrue(capabilities.is("nativeEvents"));
}
 
Example 15
Source File: Edition094_Events_API.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "iOS");
    capabilities.setCapability("platformVersion", "11.4");
    capabilities.setCapability("deviceName", "iPhone X");
    capabilities.setCapability("app", APP);

    driver = new IOSDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);
}
 
Example 16
Source File: Edition004_Web_Testing.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppiumProSite_Android() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("deviceName", "Android Emulator");
    capabilities.setCapability("browserName", "Chrome");

    // Open up Chrome
    AndroidDriver driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
    actualTest(driver);
}
 
Example 17
Source File: FirefoxDriverConfig.java    From jmeter-plugins-webdriver with Apache License 2.0 4 votes vote down vote up
Capabilities createCapabilities() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, createProxy());
    return capabilities;
}
 
Example 18
Source File: Edition065_Capture_Network_Requests.java    From appiumpro with Apache License 2.0 4 votes vote down vote up
@Test
public void captureIosSimulatorTraffic() throws IOException, URISyntaxException, InterruptedException, ExecutionException, TimeoutException {
    List<InterceptedMessage> messages = new ArrayList<InterceptedMessage>();

    // remember to set local OS proxy settings in the Network Preferences
    proxy = new MitmproxyJava("/usr/local/bin/mitmdump", (InterceptedMessage m) -> {
        System.out.println("intercepted request for " + m.requestURL.toString());
        messages.add(m);
        return m;
    });

    proxy.start();

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("platformName", "iOS");
    caps.setCapability("platformVersion", "12.0");
    caps.setCapability("deviceName", "iPhone Xs");
    caps.setCapability("automationName", "XCUITest");
    caps.setCapability("app", IOS_APP);

    driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), caps);

    // automatically install mitmproxy certificate. Can be skipped if done manually on the simulator already.
    Path certificatePath = Paths.get(System.getProperty("user.home"), ".mitmproxy", "mitmproxy-ca-cert.pem");
    Map<String, Object> args = new HashMap<>();
    byte[] byteContent = Files.readAllBytes(certificatePath);
    args.put("content", Base64.getEncoder().encodeToString(byteContent));
    driver.executeScript("mobile: installCertificate", args);

    WebElement picker = driver.findElementByAccessibilityId("Picker Demo");
    picker.click();
    WebElement button = driver.findElementByAccessibilityId("learnMore");
    button.click();
    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.alertIsPresent());
    driver.switchTo().alert().accept();


    assertTrue(messages.size() > 0);

    InterceptedMessage appiumIORequest = messages.stream().filter((m) -> m.requestURL.getHost().equals("history.muffinlabs.com")).findFirst().get();

    assertTrue(appiumIORequest.responseCode == 200);
}
 
Example 19
Source File: Edition001_iOS_Photos.java    From appiumpro with Apache License 2.0 4 votes vote down vote up
@Test
public void testSeedPhotoPicker () throws IOException, InterruptedException {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    File classpathRoot = new File(System.getProperty("user.dir"));
    File appDir = new File(classpathRoot, "../apps/");
    File app = new File(appDir.getCanonicalPath(), "SamplePhotosApp.app.zip");

    capabilities.setCapability("platformName", "iOS");
    capabilities.setCapability("deviceName", "iPhone 8 Plus");
    capabilities.setCapability("platformVersion", "11.2");
    capabilities.setCapability("app", app);

    // Open the app.
    IOSDriver driver = new IOSDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);

    try {
        // first allow the app to access photos on the phone
        driver.switchTo().alert().accept();

        // navigate to the photo view and count how many there are
        WebDriverWait wait = new WebDriverWait(driver, 10);
        WebElement el = wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("All Photos")));
        el.click();

        List<WebElement> photos = driver.findElements(MobileBy.className("XCUIElementTypeImage"));
        int numPhotos = photos.size();

        // set up the file we want to push to the phone's library
        File assetDir = new File(classpathRoot, "../assets");
        File img = new File(assetDir.getCanonicalPath(), "cloudgrey.png");

        // push the file -- note that it's important it's just the bare basename of the file
        driver.pushFile("pano.jpg", img);

        // in lieu of a formal verification, simply print out the new number of photos, which
        // should have increased by one
        photos = driver.findElements(MobileBy.className("XCUIElementTypeImage"));
        System.out.println("There were " + numPhotos + " photos before, and now there are " +
            photos.size() + "!");

    } finally {
        driver.quit();
    }
}
 
Example 20
Source File: IECapabilitiesFactory.java    From seleniumtestsframework with Apache License 2.0 4 votes vote down vote up
public DesiredCapabilities createCapabilities(final DriverConfig cfg) {

        // Set IEDriver for Local Mode
        if (cfg.getMode() == DriverMode.LOCAL) {
            if (cfg.getIeDriverPath() != null) {
                System.setProperty("webdriver.ie.driver", cfg.getIeDriverPath());
            } else {
                if (System.getenv("webdriver.ie.driver") != null) {
                    System.out.println("Get IE Driver from property:" + System.getenv("webdriver.ie.driver"));
                    System.setProperty("webdriver.ie.driver", System.getenv("webdriver.ie.driver"));
                } else {
                    try {
                        handleExtractResources();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

        }

        DesiredCapabilities capability = DesiredCapabilities.internetExplorer();

        capability.setBrowserName(DesiredCapabilities.internetExplorer().getBrowserName());

        if (cfg.isEnableJavascript()) {
            capability.setJavascriptEnabled(true);
        } else {
            capability.setJavascriptEnabled(false);
        }

        capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability("ignoreZoomSetting", true);

        if (cfg.getBrowserVersion() != null) {
            capability.setVersion(cfg.getBrowserVersion());
        }

        if (cfg.getWebPlatform() != null) {
            capability.setPlatform(cfg.getWebPlatform());
        }

        if (cfg.getProxyHost() != null) {
            Proxy proxy = cfg.getProxy();
            capability.setCapability(CapabilityType.PROXY, proxy);
        }

        capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        return capability;
    }