Appium-创建会话-错误:应提供JSONWP或W3C功能

时间:2019-03-14 22:44:01

标签: java android automation appium

我无法让Appium启动Android会话,也找不到与我在网上搜索时收到的错误消息相关的任何内容。

运行测试时,Appium将转储此日志:

[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]

我的测试:

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

Either JSONWP or W3C capabilities should be provided是什么意思?

2 个答案:

答案 0 :(得分:1)

ApplicationName> Absolute 替换为 App 或( appPackage appActivity

sleep

答案 1 :(得分:1)

@Dave Thomas ,您好。

考虑official spec表示

  • JSONWP Spec所需功能的优先级高于所需功能,必须为要创建的会话进行设置
  • 必须设置
  • W3C规范功能。必须始终为要创建的会话设置Match。 abilities.firstMatch必须至少匹配一个(将使用第一个匹配的对象)

我认为您应该深入研究功能设置。
让我分享一段可能对您有帮助的代码:

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

    ......        }
        }

也请参阅this article,以了解Web和移动测试自动化驱动程序以及相应功能之间的区别。

并且还提供the whole listing of Appium Desired Capabilities

希望这对您有所帮助, 问候, 尤金