我使用Visual Studio Code, WDIO和Appium在模拟器上通过Android Studio测试Android,但是由于某些原因我不能运行Appium,但是Android home和Java home已经被设置,Appium Doctor确认必要的依赖关系已经完成,不需要修复。我试过Appium单机版和命令版。
在Appium单机版中,ERROR日志如下。
ERROR webdriver: Request failed with status 500 due to session not created: Unable to create session from {
"desiredCapabilities": {
"platformName": "android",
"appium:deviceName": "Pixel",
"appium:platformVersion": "10.0",
"appium:app": "\u002fUsers\u002fzsolt\u002fappium_js\u002fApiDemos-debug.apk"
如果我在wdio.config.js中添加['appium']到services中,虽然Appium单机版已经关闭,但ERROR日志如下。
ERROR @wdio/cli:utils: A service failed in the 'onPrepare' hook
Error: Appium exited before timeout (exit code: 2)
[HTTP] Could not start REST http interface listener. The requested port may already be in use. Please make sure there is no other instance of this server running already.
at ChildProcess.<anonymous> (C:\Users\zsolt\Documents\AppiumTestProject\node_modules\@wdio\appium-service\build\launcher.js:103:16)
at Object.onceWrapper (events.js:417:26)
at ChildProcess.emit (events.js:310:20)
at ChildProcess.EventEmitter.emit (domain.js:482:12)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
这是我的wdio.config.js文件,使用的是Appium standalone:
exports.config = {
runner: 'local',
port: 4723,
specs: [
'./test/specs/**/*.js'
],
exclude: [
// 'path/to/excluded/files'
],
maxInstances: 10,
capabilities: [{
platformName: 'android',
'appium:deviceName': 'Pixel',
'appium:platformVersion': '10.0',
'appium:app': '/Users/zsolt/appium_js/ApiDemos-debug.apk'
}],
logLevel: 'error',
bail: 0,
baseUrl: 'http://localhost',
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
services: ['selenium-standalone',
/*['appium', {
//command : 'appium'
}]*/],
reporters: ['spec'],
mochaOpts: {
ui: 'bdd',
timeout: 60000
},
这些是我的:
"devDependencies": {
"@wdio/local-runner": "^6.1.11",
"@wdio/mocha-framework": "^6.1.8",
"@wdio/selenium-standalone-service": "^6.0.16",
"@wdio/spec-reporter": "^6.1.9",
"@wdio/sync": "^6.1.8",
"appium": "^1.17.1"
有人知道我做错了什么吗?
欢迎来到Stack-overflow!
下面是我的配置,我相信你错过了一些重要的细节。
{
platformName: 'Android',
maxInstances: 1,
'appium:deviceName': 'Device Name',
'appium:platformVersion': '8'
'appium:orientation': 'PORTRAIT',
'appium:app': 'Path to App',
'appium:automationName': 'UiAutomator2',
'appium:noReset': true,
'appium:newCommandTimeout': 240,
}
有来自维护者本身的锅炉模板 此处.
我玩了一下锅炉模板,终于可以通过Appium在android模拟器上运行测试了。
然后,我比较了conf.js中的差异,发现,执行测试需要下面的东西。
services:[
[
'appium',
{
// For options see
// https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
args: {
// For arguments see
// https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
},
command: 'appium',
},
],
],
有趣的是,实际上测试运行时也只有下面的能力。
capabilities: [{
platformName: 'Android',
'appium:deviceName': 'Pixel 2',
'appium:app': join(process.cwd(), './ApiDemos/ApiDemos-debug.apk'),
}],
当我执行测试时,它记录的错误信息和之前几乎一样,尽管在执行结束时,它在模拟器上运行测试。我没有使用Appium桌面应用。
虽然不是很完美,但还能用...
我想这个问题已经解决了。
干杯