Appium - Создать сеанс - Ошибка: должны быть предоставлены возможности JSONWP или W3C - PullRequest
0 голосов
/ 15 марта 2019

Я не могу заставить 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 ]

1 голос
/ 15 марта 2019

@ Дейв Томас , привет.

Учитывая официальная спецификация говорит, что

  • JSONWP Spec Требуемые возможности имеют более высокий приоритет, чем требуемые возможности, и должны быть установлены для создаваемого сеанса
  • Спецификации W3C Spec.alwaysMatch должны быть установлены для сеанса, который будет создан;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);

    ......        }
        }

Также ознакомьтесь с этой статьей , чтобы понять разницу между сетевыми и мобильными драйверами автоматизации тестирования и соответствующими возможностями.

А также, предоставляя весь список желаемых возможностей Appium

Надеюсь, это поможет вам, С уважением, Евгений

1 голос
/ 15 марта 2019

Заменить ApplicationName> Absolute на App или ( appPackage и 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");
...