What is the use of DesiredCapabilities in Selenium WebDriver?

后端 未结 6 2024
栀梦
栀梦 2020-11-29 04:00

What is the use of DesiredCapabilities in Selenium WebDriver?

When we want to use this and how?

Answer with example would be appreciated.

6条回答
  •  温柔的废话
    2020-11-29 04:21

    I know I am very late to answer this question.
    But would like to add for further references to the give answers.
    DesiredCapabilities are used like setting your config with key-value pair.
    Below is an example related to Appium used for Automating Mobile platforms like Android and IOS.
    So we generally set DesiredCapabilities for conveying our WebDriver for specific things we will be needing to run our test to narrow down the performance and to increase the accuracy.

    So we set our DesiredCapabilities as:

    // Created object of DesiredCapabilities class.
    DesiredCapabilities capabilities = new DesiredCapabilities();
    
    // Set android deviceName desired capability. Set your device name.
    capabilities.setCapability("deviceName", "your Device Name");
    
    // Set BROWSER_NAME desired capability.
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
    
    // Set android VERSION desired capability. Set your mobile device's OS version.
    capabilities.setCapability(CapabilityType.VERSION, "5.1");
    
    // Set android platformName desired capability. It's Android in our case here.
    capabilities.setCapability("platformName", "Android");
    
    // Set android appPackage desired capability.
    

    //You need to check for your appPackage Name for your app, you can use this app for that APK INFO

    // Set your application's appPackage if you are using any other app. 
    capabilities.setCapability("appPackage", "com.android.appPackageName");
    
    // Set android appActivity desired capability. You can use the same app for finding appActivity of your app
    capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
    

    This DesiredCapabilities are very specific to Appium on Android Platform. For more you can refer to the official site of Selenium desiredCapabilities class

提交回复
热议问题