Appium - Create Session - Error: Either JSONWP or W3C capabilities should be provided

后端 未结 2 763
一整个雨季
一整个雨季 2021-01-25 21:39

I am unable to get Appium to start an Android session and did not find anything related to the error message I am getting when I searched online.

When I run my test Appi

相关标签:
2条回答
  • 2021-01-25 22:16

    @Dave Thomas, hi.

    Considering official spec says that

    • JSONWP Spec Required capabilities have higher priority than desired capabilities and must be set for the session to be created
    • W3C Spec capabilities.alwaysMatch must be set for session to be created; capabilities.firstMatch must match at least one (the first one to match will be used)

    I think You should dig into capabilities set-up.
    Let me share piece of code that might be helpful for You:

            package io.mytestproject.appium.tests;
            import io.appium.java_client.android.AndroidDriver;
            import io.appium.java_client.remote.AndroidMobileCapabilityType;
            import io.appium.java_client.remote.MobileCapabilityType;
            import io.testproject.appium.pom.tests.pages.LoginPage;
            import io.testproject.appium.pom.tests.pages.ProfilePage;
            import org.openqa.selenium.Platform;
            import org.openqa.selenium.remote.DesiredCapabilities;
            import java.net.URL;
            public class PositiveLoginTest {
                private final static String APP_PACKAGE_NAME = "io.mytestproject.demo";
                private final static String APP_ACTIVITY_NAME = ".MainActivity";
    
       public void setup() throws Exception {
                    // Prepare Appium session
                    DesiredCapabilities capabilities = DesiredCapabilities.android();
                    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.ANDROID);
                    capabilities.setCapability(MobileCapabilityType.UDID, "YOUR_DEVICE_UDID");
                    capabilities.setCapability(MobileCapabilityType.NO_RESET, false);
                    capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, APP_PACKAGE_NAME);
                    capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, APP_ACTIVITY_NAME);
                    // Initialize driver
                    AndroidDriver driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
    
        ......        }
            }
    

    Please also see this article to understand the difference between web and mobile test automation drivers and corresponding capabilities.

    And also, providing the whole listing of Appium Desired Capabilities

    Hope this helps for You, Regards, Eugene

    0 讨论(0)
  • 2021-01-25 22:40

    Replace ApplicationName> Absolute to either App or (appPackage and appActivity)

    //Either add following line in the DesiredCapabilities
    capabilities.setCapability(MobileCapabilityType.App, "Path to your apk file");
    
    //OR add following two capabilities if the app is already installed in the testing device
    capabilities.setCapability("appPackage", "app package name");
    capabilities.setCapability("appActivity, "app activity name");
    
    0 讨论(0)
提交回复
热议问题