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

The following are Jave code examples for showing how to use setCapability() of the org.openqa.selenium.remote.DesiredCapabilities class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Bytecoder   File: BytecoderUnitTestRunner.java   Source Code and License Vote up 6 votes
private WebDriver newDriverForTest() {
    ChromeOptions theOptions = new ChromeOptions();
    theOptions.addArguments("headless");
    theOptions.addArguments("disable-gpu");

    LoggingPreferences theLoggingPreferences = new LoggingPreferences();
    theLoggingPreferences.enable(LogType.BROWSER, Level.ALL);
    theOptions.setCapability(CapabilityType.LOGGING_PREFS, theLoggingPreferences);

    DesiredCapabilities theCapabilities = DesiredCapabilities.chrome();
    theCapabilities.setCapability(ChromeOptions.CAPABILITY, theOptions);

    return new RemoteWebDriver(DRIVERSERVICE.getUrl(), theCapabilities);
}
 
Example 2
Project: cordova-vue-sample   File: AndroidDriverProvider.java   Source Code and License Vote up 6 votes
@Override
public WebDriver createDriver(DesiredCapabilities desiredCapabilities) {
    desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "6.0.1");
    desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");
    desiredCapabilities.setCapability(AndroidMobileCapabilityType.UNICODE_KEYBOARD, "true");

    desiredCapabilities.setCapability(MobileCapabilityType.APP,
            Paths.get("../platforms/android/build/outputs/apk/android-debug.apk")
                    .toAbsolutePath()
                    .toString());

    //        capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,
    //                "com.github.backpaper0.sample.searchusers");
    //        capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,
    //                ".MainActivity");

    try {
        URL url = new URL("http://localhost:4723/wd/hub");
        AndroidDriver<WebElement> driver = new AndroidDriver<>(url, desiredCapabilities);
        return driver;
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Project: cucumber-jvm-appium-infra   File: 5.1 Hooks.java   Source Code and License Vote up 6 votes
private DesiredCapabilities getCommonDesiredCapabilities() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, config.getProperty(KEYS.PLATFORM_NAME.name()));
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, config.getProperty(KEYS.PLATFORM_VERSION.name()));
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, config.getProperty(KEYS.DEVICE_MAKE.name()));
    capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
    capabilities.setCapability(MobileCapabilityType.UDID, config.getProperty(KEYS.ID.name()));
    capabilities.setCapability(MobileCapabilityType.FULL_RESET, config.getProperty(KEYS.FULL_RESET.name()));
    capabilities.setCapability(MobileCapabilityType.NO_RESET, config.getProperty(KEYS.NO_RESET.name()));
    capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, config.getProperty(KEYS.APP_PACKAGE.name()));
    capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, config.getProperty(KEYS.APP_ACTIVITY.name()));
    capabilities.setCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, config.getProperty(KEYS.APP_WAIT_ACTIVITY.name()));
    capabilities.setCapability(AndroidMobileCapabilityType.APP_WAIT_DURATION,60000);
    capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 600);
    capabilities.setCapability("systemPort", Integer.parseInt(config.getProperty(KEYS.APPIUM_PORT.name())));
    return capabilities;
}
 
Example 4
Project: akita-testing-template   File: AkitaChromeDriverProvider.java   Source Code and License Vote up 6 votes
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
    Map<String, Object> preferences = new Hashtable<>();
    preferences.put("profile.default_content_settings.popups", 0);
    preferences.put("download.prompt_for_download", "false");
    String downloadsPath = System.getProperty("user.home") + "/Downloads";
    preferences.put("download.default_directory", loadSystemPropertyOrDefault("fileDownloadPath", downloadsPath));
    preferences.put("plugins.plugins_disabled", new String[]{
            "Adobe Flash Player", "Chrome PDF Viewer"});
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", preferences);

    capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    return new ChromeDriver(capabilities);
}
 
Example 5
Project: appium_tutorial   File: BaseDriver.java   Source Code and License Vote up 6 votes
@Before
  public void setUp() throws Exception {
      File classpathRoot = new File(System.getProperty("user.dir"));
      File appDir = new File(classpathRoot, "/apps/");
      File app = new File(appDir.getCanonicalPath(), "Financius.v0.18.2.apk");
      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setCapability("deviceName", ""); // device UID from adb
capabilities.setCapability("platformVersion", "6.0.1"); // android version
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.code44.finance"); // package name
capabilities.setCapability("appWaitActivity", "com.code44.finance.*"); // default activity

capabilities.setCapability("no-reset", "true"); 
capabilities.setCapability("full-reset", "false"); 
      driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
  
  }
 
Example 6
Project: NoraUi   File: DriverFactory.java   Source Code and License Vote up 6 votes
/**
 * Generates a htmlunit webdriver.
 *
 * @return
 *         A htmlunit webdriver
 */
private WebDriver generateHtmlUnitDriver() {
    logger.info("Generating HtmlUnit driver...");
    final DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
    capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    capabilities.setJavascriptEnabled(true);

    setLoggingLevel(capabilities);

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
    }
    return new HtmlUnitDriver(capabilities);
}
 
Example 7
Project: Habanero   File: SauceLabsDriver.java   Source Code and License Vote up 6 votes
private static Capabilities caps(String platform, String browserName, String appiumVersion, String deviceName, String deviceOrientation, String platformVersion) {
    try {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        String buildName = SystemProperties.getCurrentShortDate() + " "
                + WebDriverDiscovery.getBrowserName() + " "
                + WebDriverDiscovery.getBrowserVersion() + " "
                + WebDriverDiscovery.getPlatform();
        capabilities.setCapability("appiumVersion", appiumVersion);
        capabilities.setCapability("deviceName", deviceName);
        capabilities.setCapability("deviceOrientation", deviceOrientation);
        capabilities.setCapability("browserName", browserName);
        capabilities.setCapability("platformName", platform);
        capabilities.setCapability("platformVersion", platformVersion);
        capabilities.setCapability("sauce-advisor", false);
        capabilities.setCapability("record-video", true);
        capabilities.setCapability("record-screenshots", true);
        capabilities.setCapability("build", buildName);

        LOG.info("capabilities : " + capabilities.asMap().toString());
        return capabilities;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 8
Project: Cognizant-Intelligent-Test-Scripter   File: IOSpy.java   Source Code and License Vote up 5 votes
private static void startIOSSpy() {
    try {
        if (wd == null) {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            for (String key : caps.keySet()) {
                capabilities.setCapability(key, caps.get(key));
            }
            wd = new IOSDriver(new URL(url), capabilities);
        }
    } catch (Exception ex) {
        Logger.getLogger(IOSpy.class.getName()).log(Level.SEVERE, null, ex);
        Notification.show("Couldn't Connect to Device/Simulator Check Settings/Appium Logs");
    }
}
 
Example 9
Project: phoenix.webui.framework   File: CapabilityConfig.java   Source Code and License Vote up 5 votes
/**
 * 火狐浏览器配置
 */
private void firefox()
{
	DesiredCapabilities capability = DesiredCapabilities.firefox();
	capability.setCapability("marionette", true);
	engineCapMap.put(DRIVER_FIREFOX, capability);
}
 
Example 10
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   Source Code and License Vote up 5 votes
public static WebDriver get32IEDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\IEDriverServer32.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);
	return new InternetExplorerDriver(caps);
}
 
Example 11
Project: Cognizant-Intelligent-Test-Scripter   File: WebDriverFactory.java   Source Code and License Vote up 5 votes
private static DesiredCapabilities getFFUAECaps(DesiredCapabilities caps, Emulator emulator) {
    FirefoxProfile profile = new FirefoxProfile();
    if (!emulator.getUserAgent().trim().isEmpty()) {
        profile.setPreference("general.useragent.override", emulator.getUserAgent());
    }
    caps.setCapability(FirefoxDriver.PROFILE, profile);
    return caps;
}
 
Example 12
Project: WebAndAppUITesting   File: DriverFactory.java   Source Code and License Vote up 5 votes
/**
 * Android app测试
 * 
 * @param noReset
 */
private void createAndroidDriver(Boolean noReset) {

	capabilities = new DesiredCapabilities();
	// app is absolute path

	capabilities.setCapability("app",
			String.join(File.separator, System.getProperty("user.dir"), property.getProperty("app")));
	capabilities.setCapability("platformName", property.getProperty("platformName"));
	capabilities.setCapability("platformVersion", property.getProperty("platformVersion"));
	// On Android this capability is currently ignored, though it remains required.
	capabilities.setCapability("deviceName", property.getProperty("deviceName"));
	capabilities.setCapability("appPackage", property.getProperty("appPackage"));
	capabilities.setCapability("appActivity", property.getProperty("appActivity"));
	// physical device
	capabilities.setCapability("udid", property.getProperty("udid"));
	// debug时,等待时间调大点!!
	capabilities.setCapability("newCommandTimeout", property.getProperty("newCommandTimeout"));
	capabilities.setCapability("noReset", noReset); // 不卸载、不重装
	capabilities.setCapability("noSign", "true");
	// 重置输入法,并且设置可以中文输入
	capabilities.setCapability("unicodeKeyboard", "True");
	capabilities.setCapability("resetKeyboard", "True");

	try {
		driver = new AndroidDriver<MobileElement>(new URL(property.getProperty("remote.address")), capabilities);
	} catch (Exception e) {
		e.printStackTrace();
		AssertUtil.fail("初始化对象失败,e = " + e.getMessage());
	}
}
 
Example 13
Project: delay-repay-bot   File: PhantomJSTest.java   Source Code and License Vote up 5 votes
public static DesiredCapabilities getDefaultDesiredCapabilities() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setJavascriptEnabled(true);
    capabilities.setCapability("acceptSslCerts", true);
    capabilities.setCapability("takesScreenshot", true);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, asList("--ignore-ssl-errors=true"));
    LoggingPreferences loggingPreferences = new LoggingPreferences();
    loggingPreferences.enable(LogType.BROWSER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);
    return capabilities;
}
 
Example 14
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   Source Code and License Vote up 5 votes
public static WebDriver getEdgeDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\EdgeWebDriver.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);
	return new InternetExplorerDriver(caps);
}
 
Example 15
Project: SilkAppDriver   File: MobileTests.java   Source Code and License Vote up 5 votes
@Ignore
@Test
public void test() throws IOException {
	Map<String, String> baseState = new HashMap<>();
	baseState.put("type", "MOBILE");
	baseState.put("connectionString", "platformName=Android;app=C:\\apps\\InsuranceMobile.apk");

	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("appdriver-basestate", baseState);

	WebDriver driver = new RemoteWebDriver(new URL("http://localhost:8080"), capabilities);
	String title = driver.getTitle();

	assertEquals("", title); // TODO: Maybe we find something to use as the
								// title?

	WebElement email = driver
			.findElement(By.xpath("//MobileTextField[@resource-id='silktest.insurancemobile:id/email']"));
	email.sendKeys("test");
	assertEquals("test", email.getText());
	
	email.clear();
	assertEquals("", email.getText());
	email.sendKeys("[email protected]");

	driver.findElement(By.xpath("//MobileTextField[@resource-id='silktest.insurancemobile:id/password']"))
			.sendKeys("john");

	driver.findElement(By.xpath("//MobileButton[@resource-id='silktest.insurancemobile:id/log_in_button']"))
			.click();

	driver.findElement(By.xpath("//MobileObject[@content-desc='drawer_open']")).click();

	driver.findElement(By.xpath("//MobileObject[@caption='Logout']")).click();

	driver.quit();
}
 
Example 16
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   Source Code and License Vote up 5 votes
public static WebDriver getFirefoxDriver(String pathToFirefoxExecutable)
{
       String path = "src/test/resources/geckodriver";
	System.setProperty("webdriver.gecko.driver", path);
	System.setProperty("webdriver.firefox.bin", pathToFirefoxExecutable);

	DesiredCapabilities capabilities =  DesiredCapabilities.firefox();
       capabilities.setCapability("marionette", true);
       capabilities.setCapability("networkConnectionEnabled", true);
       capabilities.setCapability("browserConnectionEnabled", true);

	WebDriver driver = new MarionetteDriver(capabilities);

	return driver;
}
 
Example 17
Project: SWET   File: BrowserDriver.java   Source Code and License Vote up 5 votes
private static DesiredCapabilities capabilitiesAndroid() {
	DesiredCapabilities capabilities = DesiredCapabilities.chrome();

	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);

	return capabilities;
}
 
Example 18
Project: teasy   File: DriverUtils.java   Source Code and License Vote up 4 votes
private static DesiredCapabilities getFireFoxDesiredCapabilities(Settings settings) {
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    capabilities.setCapability(FirefoxDriver.PROFILE, getFirefoxProfile(settings));
    return capabilities;
}
 
Example 19
Project: ats-framework   File: MobileDriver.java   Source Code and License Vote up 4 votes
/**
 * Start session to device and load the application <br/>
 * @param appPath the absolute path to the application:
 * <pre>
 *       <b>iOS</b>: absolute path to simulator-compiled .app file or the bundle_id of the desired target on device
 *       <b>Android</b>: absolute path to .apk file
 * </pre>
 */
@PublicAtsApi
public void start( String appPath ) {

    log.info("Starting mobile testing session to device: " + getDeviceDescription());
    try {
        // http://appium.io/slate/en/master/?java#appium-server-capabilities
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability("automationName", "Appium");
        if (isAndroidAgent) {

            // start emulator:          .../sdk/tools/emulator -avd vmname
            // install application:     .../sdk/platform-tools/adb install /usr/local/apps/SecureTransportMobile.apk

            if (this.adbLocation == null) {
                // try to set Android home and adb location from the ANDROID_HOME environment variable
                readAndroidHomeFromEnvironment();
                if (this.adbLocation == null) {
                    throw new MobileOperationException("You must specify a valid Android home location or define "
                                                       + ANDROID_HOME_ENV_VAR
                                                       + " environment variable. The ADB executable must be located in a 'platform-tools/' subfolder");
                }
            }
            desiredCapabilities.setCapability("platformName", "Android");
        } else {

            desiredCapabilities.setCapability("platformName", "iOS");
        }
        desiredCapabilities.setCapability("deviceName", deviceName);
        desiredCapabilities.setCapability("platformVersion", this.platformVersion);
        if (!StringUtils.isNullOrEmpty(this.udid)) {
            desiredCapabilities.setCapability("udid", this.udid);
        }
        desiredCapabilities.setCapability("app", appPath);
        desiredCapabilities.setCapability("autoLaunch", true);
        desiredCapabilities.setCapability("newCommandTimeout", 30 * 60);
        desiredCapabilities.setCapability("noReset", true); // don’t reset settings and app state before this session
        // desiredCapabilities.setCapability( "fullReset", true ); // clean all Android/iOS settings (iCloud settings), close and uninstall the app

        URL url = new URL("http://" + this.host + ":" + this.port + "/wd/hub");
        if (isAndroidAgent) {
            driver = new AndroidDriver<WebElement>(url, desiredCapabilities);
        } else {
            driver = new IOSDriver<WebElement>(url, desiredCapabilities);
        }
        driver.setLogLevel(Level.ALL);

        // the following timeout only works for NATIVE context, but we will handle it in MobileElementState.
        // Also there is a problem when != 0. In some reason, for iOS only(maybe), this timeout acts as session timeout ?!?
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);

        // driver.manage().timeouts().pageLoadTimeout( 30000, TimeUnit.MILLISECONDS ); // UnsupportedCommandException
        // driver.manage().timeouts().setScriptTimeout( 10000, TimeUnit.MILLISECONDS ); // WebDriverException: Not yet implemented

        driver.context(NATIVE_CONTEXT);
        this.screenDimensions = driver.manage().window().getSize(); // must be called in NATIVE context

        mobileEngine = new MobileEngine(this, this.mobileDeviceUtils);
    } catch (Exception e) {
        throw new MobileOperationException("Error starting connection to device and application under test."
                                           + " Check if there is connection to device and the Appium server is running.",
                                           e);
    }
}
 
Example 20
Project: colibri-ui-template   File: AndroidDriverConfigurator.java   Source Code and License Vote up 4 votes
protected void additionalAndroidCapabilities(AppSettings appSettings, DesiredCapabilities capabilities) {
    capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
    capabilities.setCapability(AndroidMobileCapabilityType.UNICODE_KEYBOARD, true);
    capabilities.setCapability(AndroidMobileCapabilityType.APP_WAIT_ACTIVITY, appSettings.getPackageName() + appSettings.getStartPageId());
}