Невозможно запустить драйвер Android с нужными возможностями в проекте Appium - PullRequest
0 голосов
/ 07 сентября 2018

Я новичок в мобильной автоматизации и пытаюсь настроить appium с помощью eclipse, а также успешно подключил реальное устройство. Я установил все необходимое программное обеспечение и пакеты. Я могу найти свои устройства в списке устройств adb.

Я создал простой проект в Eclipse и объявил все правильные параметры в методе DesiredCapabilities. Я также включил appPackage и appActivity, но моя ошибка показывает

Требуемые возможности должны включать в себя «appPackage» или «browserName»

public class NewTest {
    AndroidDriver driver;
    AppiumDriverLocalService service;

    @Test
    public void f() {         
          driver.findElement(By.id("com.google.android.youtube:id/menu_search")).click();
          driver.findElement(By.xpath("com.google.android.youtube:id/search_edit_text")).sendKeys("nota");
                      }

   @BeforeTest
   public void beforeTest() {
          service = AppiumDriverLocalService.buildDefaultService();
          service.start();
          DesiredCapabilities capabilities = new DesiredCapabilities();
          capabilities.setCapability("deviceName", "S51C1LV1C0056422"); 
          capabilities.setCapability("browserName", "Android");
          capabilities.setCapability("platformVersion", "4.4.2");
          capabilities.setCapability("platformName", "Android");
          capabilities.setCapability("appPackage", "com.google.android.youtube");
          capabilities.setCapability("appActivity", "com.google.android.apps.youtube.app.WatchWhileActivity");
          try {
            driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
          driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
      }

   @AfterTest
   public void afterTest() {
          service = AppiumDriverLocalService.buildDefaultService();
          service.stop();
          driver.quit();
      }        
    }

Ниже вывод консоли.

    [RemoteTestNG] detected TestNG version 6.14.2
    [35m[Appium][39m Welcome to Appium v1.9.0
    [35m[Appium][39m Appium REST http interface listener started on 0.0.0.0:4723
    [35m[HTTP][39m [37m-->[39m [37mGET[39m [37m/wd/hub/status[39m
    [35m[HTTP][39m [90m{}[39m
    [debug] [35m[MJSONWP][39m Calling AppiumDriver.getStatus() with args: []
    [debug] [35m[MJSONWP][39m Responding to client with driver.getStatus() result: {"build":{"version":"1.9.0"}}
    [35m[HTTP][39m [37m<-- GET /wd/hub/status [39m[32m200[39m [90m17 ms - 67[39m
    [35m[HTTP][39m [90m[39m
    [35m[HTTP][39m [37m-->[39m [37mPOST[39m [37m/wd/hub/session[39m
    [35m[HTTP][39m [90m{"desiredCapabilities":{"appActivity":"com.google.android.apps.youtube.app.WatchWhileActivity","appPackage":"com.google.android.youtube","platformVersion":"4.4.2","browserName":"Android","platformName":"Android","deviceName":"S51C1LV1C0056422"},"capabilities":{"alwaysMatch":{"appium:appActivity":"com.google.android.apps.youtube.app.WatchWhileActivity","appium:appPackage":"com.google.android.youtube","browserName":"Android","appium:deviceName":"S51C1LV1C0056422","platformName":"android","appium:platformVersion":"4.4.2"},"firstMatch":[{}]}}[39m
    [debug] [35m[MJSONWP][39m Calling AppiumDriver.createSession() with args: [{"appActivity":"com.google.android.apps.youtube.app.WatchWhileActivity","appPackage":"com.google.android.youtube","platformVersion":"4.4.2","browserName":"Android","platformName":"Android","deviceName":"S51C1LV1C0056422"},null,{"alwaysMatch":{"appium:appActivity":"com.google.android.apps.youtube.app.WatchWhileActivity","appium:appPackage":"com.google.android.youtube","browserName":"Android","appium:deviceName":"S51C1LV1C0056422","platformName":"android","appium:platformVersion":"4.4.2"},"firstMatch":[{}]}]
    [debug] [35m[BaseDriver][39m Event 'newSessionRequested' logged at 1536289004500 (08:26:44 GMT+0530 (India Standard Time))
    [35m[Appium][39m Creating new AndroidDriver (v3.7.0) session
    [35m[Appium][39m Capabilities:
    [35m[Appium][39m   browserName: Android
    [35m[Appium][39m   platformName: android
    [35m[Appium][39m   appActivity: com.google.android.apps.youtube.app.WatchWhileActivity
    [35m[Appium][39m   appPackage: com.google.android.youtube
    [35m[Appium][39m   deviceName: S51C1LV1C0056422
    [35m[Appium][39m   platformVersion: 4.4.2
    [debug] [35m[BaseDriver][39m W3C capabilities {"alwaysMatch":{"browserNam... and MJSONWP desired capabilities {"appActivity":"com.google.... were provided
    [debug] [35m[BaseDriver][39m Creating session with W3C capabilities: {"alwaysMatch":{"browserNam...
    [35m[AndroidDriver][39m Error: The desired capabilities must include either 'appPackage' or 'browserName'
    [35m[AndroidDriver][39m     at Object.wrappedLogger.errorAndThrow (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\appium-support\lib\logging.js:78:13)
    [35m[AndroidDriver][39m     at Object.helpers.validateDesiredCaps (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\android-helpers.js:705:14)
    [35m[AndroidDriver][39m     at AndroidDriver.validateDesiredCaps (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\driver.js:470:20)
    [35m[AndroidDriver][39m     at AndroidDriver.callee$0$0$ (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\commands\session.js:45:8)
    [35m[AndroidDriver][39m     at tryCatch (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
    [35m[AndroidDriver][39m     at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    [35m[AndroidDriver][39m     at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    [35m[AndroidDriver][39m     at invoke (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
    [35m[AndroidDriver][39m     at enqueueResult (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:185:17)
    [35m[AndroidDriver][39m     at new Promise (<anonymous>)
    [35m[AndroidDriver][39m     at new F (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\core-js\library\modules\$.export.js:30:36)
    [35m[AndroidDriver][39m     at AsyncIterator.enqueue (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:184:12)
    [35m[AndroidDriver][39m     at AsyncIterator.prototype.(anonymous function) [as next] (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    [35m[AndroidDriver][39m     at Object.runtime.async (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:209:12)
    [35m[AndroidDriver][39m     at AndroidDriver.callee$0$0 [as createSession] (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\build\lib\basedriver\commands\session.js:35:30)
    [35m[AndroidDriver][39m     at AndroidDriver.createSession$ (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\driver.js:29:20)
    [35m[AndroidDriver][39m     at tryCatch (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
    [35m[AndroidDriver][39m     at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    [35m[AndroidDriver][39m     at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    [35m[AndroidDriver][39m     at invoke (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
    [35m[AndroidDriver][39m     at enqueueResult (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:185:17)
    [35m[AndroidDriver][39m     at new Promise (<anonymous>)
    [35m[AndroidDriver][39m     at new F (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\core-js\library\modules\$.export.js:30:36)
    [35m[AndroidDriver][39m     at AsyncIterator.enqueue (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:184:12)
    [35m[AndroidDriver][39m     at AsyncIterator.prototype.(anonymous function) [as next] (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    [35m[AndroidDriver][39m     at Object.runtime.async (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:209:12)
    [35m[AndroidDriver][39m     at AndroidDriver.createSession (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\build\lib\driver.js:140:34)
    [35m[AndroidDriver][39m     at AppiumDriver.callee$2$0$ (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\lib\appium.js:293:43)
    [35m[AndroidDriver][39m     at tryCatch (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
    [35m[AndroidDriver][39m     at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    [35m[AndroidDriver][39m     at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    [35m[AndroidDriver][39m     at GeneratorFunctionPrototype.invoke (C:\Users\WELCOME\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
    [35m[AndroidDriver][39m     at <anonymous>
    [35m[AndroidDriver][39m     at process._tickCallback 

Ответы [ 2 ]

0 голосов
/ 07 сентября 2018

Вы должны определить AppiumDriver вместо AndroidDriver .

public class NewTest {
    AppiumDriver<WebElement> driver;
    //...
}

Включить appPackage , appActivity , имя_платформы , имя_устройства в требуемые возможности.

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Android phone");   
caps.setCapability("platformName", "Android");  
caps.setCapability("appPackage", "Your app Package");
caps.setCapability("appActivity", "app activity name");

Не включайте browserName , если вы не открываете свое приложение в веб-браузере.

Инициализируйте ваш драйвер следующим образом:

driver = new AndroidDriver<WebElement>(new URL(
                    "http://0.0.0.0:4723/wd/hub"), caps);
0 голосов
/ 07 сентября 2018

Если вы передадите browserName и appPackage оба capabilities, это означает, что это противоречие, так как appium не сможет понять, что он должен запустить браузер (на основе browerName cap) или приложение (на основе appPackage cap)

Удалить возможность имени браузера

  capabilities.setCapability("browserName", "Android");

Добавить эту возможность

  capabilities.setCapability("platformName", "Android");
...