Reputation: 515
I am new to mobile automation and trying to setup appium with eclipse and also successfully connected a real device. I have installed all the required software and packages. I am able to find my devices under adb device list.
I have created a simple project in eclipse and declared all the right parameters in the DesiredCapabilities method. I have also included the appPackage and appActivity but my error shows
The desired capabilities must include either 'appPackage' or '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();
}
}
Below is the console output.
[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
Upvotes: 1
Views: 2424
Reputation: 2526
You must define AppiumDriver instead of AndroidDriver.
public class NewTest {
AppiumDriver<WebElement> driver;
//...
}
Include appPackage, appActivity, platformName, deviceName in Desired capabilities.
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");
Don't include browserName if you are not opening your app in web browser.
Initialize your driver like following:
driver = new AndroidDriver<WebElement>(new URL(
"http://0.0.0.0:4723/wd/hub"), caps);
Upvotes: 2
Reputation: 4597
If you pass browserName
and appPackage
both capabilities
then that means its a contradiction , as appium will not be able to understand that it has to launch
browser (based on browerName
cap) or app(based on appPackage
cap)
Remove browser name capability
capabilities.setCapability("browserName", "Android");
Add this capability
capabilities.setCapability("platformName", "Android");
Upvotes: 1