Appium - Create Session - Error: Either JSONWP or

2020-05-06 12:41发布

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 Appium dumps this log:

[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [null,null,[{"desiredCapabilities":{"platformVersion":"7.0","appiumVersion":"1.11.1","automationName":"UiAutomator2","platformName":"Android","deviceName":"ZX1G22GRHD","applicationName":"Absolute"}},{"requiredCapabilities":{}}]]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1552607433945 (16:50:33 GMT-0700 (Pacific Daylight Time))
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1552607433945 (16:50:33 GMT-0700 (Pacific Daylight Time))
[debug] [W3C] Encountered internal error running command: Error: Either JSONWP or W3C capabilities should be provided
[debug] [W3C]     at parseCapsForInnerDriver (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/lib/utils.js:58:14)
[debug] [W3C]     at AppiumDriver.createSession (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/lib/appium.js:262:26)
[debug] [W3C]     at AppiumDriver.executeCommand (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:301:19)
[debug] [W3C]     at AppiumDriver.executeCommand (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/lib/appium.js:429:26)
[debug] [W3C]     at asyncHandler (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:352:34)
[debug] [W3C]     at app.(anonymous function) (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:489:15)
[debug] [W3C]     at Layer.handle [as handle_request] (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [W3C]     at next (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/route.js:137:13)
[debug] [W3C]     at Route.dispatch (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/route.js:112:3)
[debug] [W3C]     at Layer.handle [as handle_request] (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [W3C]     at /Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/index.js:281:22
[debug] [W3C]     at Function.process_params (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/index.js:335:12)
[debug] [W3C]     at next (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
[debug] [W3C]     at logger (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/morgan/index.js:144:5)
[debug] [W3C]     at Layer.handle [as handle_request] (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [W3C]     at trim_prefix (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/index.js:317:13)
[debug] [W3C]     at /Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/index.js:284:7
[debug] [W3C]     at Function.process_params (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/index.js:335:12)
[debug] [W3C]     at next (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
[debug] [W3C]     at /Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/body-parser/lib/read.js:130:5
[debug] [W3C]     at invokeCallback (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/raw-body/index.js:224:16)
[debug] [W3C]     at done (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/raw-body/index.js:213:7)
[debug] [W3C]     at IncomingMessage.onEnd (/Users/davethomas/.nvm/versions/node/v10.15.0/lib/node_modules/appium/node_modules/raw-body/index.js:273:7)
[debug] [W3C]     at IncomingMessage.emit (events.js:182:13)
[debug] [W3C]     at endReadableNT (_stream_readable.js:1094:12)
[debug] [W3C]     at process._tickCallback (internal/process/next_tick.js:63:19)
[HTTP] <-- POST /wd/hub/session 500 5 ms - 738
[HTTP]

My test:

public class AndroidTestCaseExample {

    public AndroidDriver driver;

    @BeforeTest
    public void setup() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.0");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        capabilities.setCapability(MobileCapabilityType.APPIUM_VERSION, "1.11.1");
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "ZX1G22GRHD");
        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"UiAutomator2");
        capabilities.setCapability(MobileCapabilityType.APPLICATION_NAME, "Absolute");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }

    @Test
    public void loadApp() {
        List<MobileElement> elements = (List<MobileElement>)
                driver.findElementByClassName("android.widget.EditText");

        for (MobileElement element : elements) {
            System.out.println(element.toJson());
        }
    }
}

What does Either JSONWP or W3C capabilities should be provided mean?

2条回答
Juvenile、少年°
2楼-- · 2020-05-06 13:03

@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

查看更多
霸刀☆藐视天下
3楼-- · 2020-05-06 13:13

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");
查看更多
登录 后发表回答