public static AndroidDriver<AndroidElement> driver;
/**
* >aapt d badging GJDMALL-V2.2.0.3349-436-debug-99a5c6a.apk|findstr "package launchable-activity"
* package: name=‘com.jingdong.th.app‘ versionCode=‘3346‘ versionName=‘2.2.0‘ platformBuildVersionName=‘8.0.0‘
* launchable-activity: name=‘com.jingdong.global.app.welcome.WelcomeActivity‘ label=‘‘ icon=‘‘
* 初始化
* @return
* @throws Exception
*/
public static AndroidDriver<AndroidElement> initDriver() throws Exception {
File app = new File(".\\apk\\GJDMALL-V2.2.0.3349-436-debug-99a5c6a.apk");
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "android");
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "android");
caps.setCapability(MobileCapabilityType.APPIUM_VERSION, "4.4.2");
//caps.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); //自动安装
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "127.0.0.1:62001");
caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 600);
//caps.setCapability(MobileCapabilityType.FULL_RESET, true); //结束后会卸载程序
caps.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.jingdong.th.app");
caps.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.jingdong.global.app.welcome.WelcomeActivity");
caps.setCapability(AndroidMobileCapabilityType.UNICODE_KEYBOARD, true);
caps.setCapability(AndroidMobileCapabilityType.RESET_KEYBOARD, true);
caps.setCapability(AndroidMobileCapabilityType.NO_SIGN, true);
driver = new AndroidDriver<>(
new URL("http://127.0.0.1:4723/wd/hub"), caps);
return driver;
}
出现错误
HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"appActivity":"com.jingdong.global.app.welcome.WelcomeActivity","appPackage":"com.jingdong.th.app","newCommandTimeout":600,"noSign":true,"appiumVersion":"4.4.2","automationName":"Appium","unicodeKeyboard":true,"platformName":"Android","udid":"127.0.0.1:62001","resetKeyboard":true},"capabilities":{"firstMatch":[{"appium:appActivity":"com.jingdong.global.app.welcome.WelcomeActivity","appium:appPackage":"com.jingdong.th.app","appium:appiumVersion":"4.4.2","appium:automationName":"Appium","appium:newCommandTimeout":600,"appium:noSign":true,"platformName":"android","appium:resetKeyboard":true,"appium:udid":"127.0.0.1:62001","appium:unicodeKeyboard":true}]}}
[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"appActivity":"com.jingdong.global.app.welcome.WelcomeActivity","appPackage":"com.jingdong.th.app","newCommandTimeout":600,"noSign":true,"appiumVersion":"4.4.2","automationName":"Appium","unicodeKeyboard":true,"platformName":"Android","udid":"127.0.0.1:62001","resetKeyboard":true},null,{"firstMatch":[{"appium:appActivity":"com.jingdong.global.app.welcome.WelcomeActivity","appium:appPackage":"com.jingdong.th.app","appium:appiumVersion":"4.4.2","appium:automationName":"Appium","appium:newCommandTimeout":600,"appium:noSign":true,"platformName":"android","appium:resetKeyboard":true,"appium:udid":"127.0.0.1:62001","appium:unicodeKeyboard":true}]}]
[debug] [BaseDriver] Event ‘newSessionRequested‘ logged at 1561284179583 (18:02:59 GMT+0800 (中国标准时间))
[Appium] Could not parse W3C capabilities: ‘deviceName‘ can‘t be blank
[Appium] Trying to fix W3C capabilities by merging them with JSONWP caps
[BaseDriver] The capabilities ["appActivity","appPackage","appiumVersion","automationName","newCommandTimeout","noSign","resetKeyboard","udid","unicodeKeyboard"] are not standard capabilities and should have an extension prefix
*[Appium] Could not parse fixed W3C capabilities: ‘deviceName‘ can‘t be blank. Falling back to JSONWP protocol*
[debug] [BaseDriver] Event ‘newSessionStarted‘ logged at 1561284179596 (18:02:59 GMT+0800 (中国标准时间))
[debug] [MJSONWP] Encountered internal error running command: Error: Could not find a driver for automationName ‘Appium‘ and platformName ‘Android‘. Please check your desired capabilities.
[debug] [MJSONWP] at AppiumDriver.getDriverAndVersionForCaps (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\lib\appium.js:205:11)
[debug] [MJSONWP] at AppiumDriver.getDriverAndVersionForCaps [as createSession] (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\lib\appium.js:268:66)
[debug] [MJSONWP] at AppiumDriver.executeCommand (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-base-driver@3.15.4@appium-base-driver\lib\basedriver\driver.js:301:19)
[debug] [MJSONWP] at AppiumDriver.executeCommand (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\lib\appium.js:420:26)
[debug] [MJSONWP] at executeCommand (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-base-driver@3.15.4@appium-base-driver\lib\protocol\protocol.js:352:34)
[debug] [MJSONWP] at asyncHandler (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-base-driver@3.15.4@appium-base-driver\lib\protocol\protocol.js:489:15)
[debug] [MJSONWP] at Layer.handle [as handle_request] (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\layer.js:95:5)
[debug] [MJSONWP] at next (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\route.js:137:13)
[debug] [MJSONWP] at Route.dispatch (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\route.js:112:3)
[debug] [MJSONWP] at Layer.handle [as handle_request] (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\layer.js:95:5)
[debug] [MJSONWP] at C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\index.js:281:22
[debug] [MJSONWP] at Function.process_params (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\index.js:335:12)
[debug] [MJSONWP] at next (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\index.js:275:10)
[debug] [MJSONWP] at logger (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_morgan@1.9.1@morgan\index.js:144:5)
[debug] [MJSONWP] at Layer.handle [as handle_request] (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\layer.js:95:5)
[debug] [MJSONWP] at trim_prefix (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\index.js:317:13)
[debug] [MJSONWP] at C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\index.js:284:7
[debug] [MJSONWP] at Function.process_params (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\index.js:335:12)
[debug] [MJSONWP] at next (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_express@4.16.4@express\lib\router\index.js:275:10)
[debug] [MJSONWP] at C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_body-parser@1.18.3@body-parser\lib\read.js:130:5
[debug] [MJSONWP] at invokeCallback (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_raw-body@2.3.3@raw-body\index.js:224:16)
[debug] [MJSONWP] at done (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_raw-body@2.3.3@raw-body\index.js:213:7)
[debug] [MJSONWP] at IncomingMessage.onEnd (C:\Users\liwen406\AppData\Roaming\npm\node_modules\appium\node_modules\_raw-body@2.3.3@raw-body\index.js:273:7)
[debug] [MJSONWP] at emitNone (events.js:106:13)
[debug] [MJSONWP] at IncomingMessage.emit (events.js:208:7)
[debug] [MJSONWP] at endReadableNT (_stream_readable.js:1055:12)
[debug] [MJSONWP] at _combinedTickCallback (internal/process/next_tick.js:138:11)
[debug] [MJSONWP] at process._tickCallback (internal/process/next_tick.js:180:9)
解决
public static AndroidDriver<AndroidElement> initDriver() throws Exception {
File app = new File(".\\apk\\GJDMALL-V2.2.0.3349-436-debug-99a5c6a.apk");
DesiredCapabilities caps = new DesiredCapabilities();
// caps.setCapability(MobileCapabilityType.DEVICE_NAME, "android");
// caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "android");
caps.setCapability(MobileCapabilityType.APPIUM_VERSION, "4.4.2");
//caps.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); //自动安装
// caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "127.0.0.1:62001");
caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 600);
//caps.setCapability(MobileCapabilityType.FULL_RESET, true); //结束后会卸载程序
caps.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.jingdong.th.app");
caps.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.jingdong.global.app.welcome.WelcomeActivity");
caps.setCapability(AndroidMobileCapabilityType.UNICODE_KEYBOARD, true);
caps.setCapability(AndroidMobileCapabilityType.RESET_KEYBOARD, true);
caps.setCapability(AndroidMobileCapabilityType.NO_SIGN, true);
driver = new AndroidDriver<>(
new URL("http://127.0.0.1:4723/wd/hub"), caps);
return driver;
}
正常启动appium