Macaca 如何重头开始编辑一个自己的基于 Android app 的 macaca 用例脚本项目

老马 · 2016年08月09日 · 最后由 xi 回复于 2016年10月29日 · 4020 次阅读

该文为 macaca 的 nodejs 版本 样例https://github.com/macacajs/macaca-test-sample
macaca java 版本 https://github.com/macacajs/wd.java
macaca python 版本 https://github.com/macacajs/wd.py

类似于上一篇的思路。
https://testerhome.com/topics/5634

一 建立一个新用例脚本项目

D:\macaca\me-app

拷贝 D:\macaca\macaca-test-sample-master 官方示例脚本下的依赖文件 app 、package.json、 README.md
到新项目 me-app 下。为图方便。macaca-test 文件夹也整个 copy 过来。
您还需要将您的 apk 拷贝到目录\me-app\app 下。

二 创建用例脚本文件 *.test.js

D:\macaca\me-app\macaca-test
将示例脚本 macaca-mobile-sample.test.js 重命名为 android-acp-sample.test.js
开始编辑修改 android-acp-sample.test.js 脚本的内容。

三 编辑业务流脚本内容

3.1 用工具来定位元素

我们用到的是 macaca 团队刚发布的 app-inspector,关于该工具的安装部署请参考https://testerhome.com/topics/5626

3.2 android-acp-sample.test.js 脚本内容

只是简单的测试下,看是否可以如此构建自己的用例项目。所以业务流程只是简单的找到登录页 输入用户名 输入密码 点击登录而已 注释掉删除掉了一些验证步骤和自己不了解的原脚本内容。
其中截图实际是有问题的,因为环境目录设置问题。一会儿抽空看下调一下。

'use strict';

var path = require('path');
var _ = require('macaca-utils');

var platform = process.env.platform || 'Android';
platform = platform.toLowerCase();

var iOSOpts = {
  platformVersion: '9.3',
  deviceName: 'iPhone 5s',
  platformName: 'iOS',
  //bundleId: 'xudafeng.ios-app-bootstrap',
  app: path.join(__dirname, '..', 'app', `${platform}-app-bootstrap.zip`)
};

var androidOpts = {
  platformName: 'Android',
  //package: 'com.github.android_app_bootstrap',
  //activity: 'com.github.android_app_bootstrap.activity.WelcomeActivity',
  app: path.join(__dirname, '..', 'app', `your android apk.apk`)
};

var wd = require('webdriver-client')(_.merge({}, platform === 'ios' ? iOSOpts : androidOpts));

// override back for ios
wd.addPromiseChainMethod('customback', function() {
  if (platform === 'ios') {
    return this;
  }

  return this
    .back();
});

describe('macaca mobile sample', function() {
  this.timeout(5 * 60 * 1000);

  var driver = wd.initPromiseChain();

  driver.configureHttp({
    timeout: 600000
  });

  before(function() {
    return driver
      .initDriver();
  });

  after(function() {
    return driver
      .sleep(1000)
      .quit();
  });

  it('#1 Access 我的', function() {
    return driver
      .elementById('com.acp.aicaitencent:id/tvBottomTab4')
      .click()
      .sleep(1000);
  });

  it('#2 should display 我的page', function() {
    return driver
      .takeScreenshot();
  });

  it('#3 Access 立即登录/注册', function() {
    return driver
      .elementById('com.acp.aicaitencent:id/layoutLogin')
      .click()
      .sleep(1000);
  });

  it('#4 should display 登录Page', function() {
    return driver
      .takeScreenshot();
  });

  it('#5 Edit and Login', function() {
    return driver
      .elementById('com.acp.aicaitencent:id/etUserName')
      .sendKeys('***********')
      .sleep(5000)

      .elementById('com.acp.aicaitencent:id/etPwd')
      .sendKeys('***********')
      .sleep(5000)

      .elementById('com.acp.aicaitencent:id/tvLogin')
      .click()
      .sleep(5000)

      .takeScreenshot();
  });

});

PS:2016年8月12日补充
书接上文,今天早上来又看了一遍原作者的 macaca-mobile-sample.test.js 样例,原作者为了更好的演示,大家看

it('#7 should works with web', function() {
    return driver
      .webview()
      .elementById('index-kw')
      .sendKeys('中文+TesterHome')
      .elementById('index-bn')
      .tap()
      .sleep(5000)
      .source()
      .then(function(html) {
        html.should.containEql('TesterHome');
      })
      .takeScreenshot();
  });

  it('#8 should logout success', function() {
    return driver
      .native()
      .elementByName('PERSONAL')
      .click()
      .sleep(1000)
      .takeScreenshot()
      .elementByName('Logout')
      .click()
      .sleep(1000)
      .takeScreenshot();

.webview() .native() 大家明白了吧 这就是展示 webview 元素定位 和 native 原生元素定位。 所以大家还是多研究样例 先把简单的搞懂模仿起来,再进行复杂的,一步一步来。

四 运行环境准备工作

老样子,你需要到有 package.json 文件的 D:\macaca\me-app 目录下执行下 npm i 来为 me-app 准备 macaca 的组件包依赖。
成功看到安装成功日志后,接下来便可以执行用例脚本了。

五 执行用例脚本

先启动个安卓模拟器,此处我依然启动的是 Genymotion 模拟器。adb devices -l 查看下是否启动正常。

cd 到 macaca-test 目录下

D:\macaca\me-app\macaca-test>macaca run -d android-acp-sample.test.js --verbose
>> index.js:17:12 [master] pid:10376 webdriver server start with config:
 { port: 3456,
  window: true,
  ip: '*.*.*.*',
  host: 'cmd-PC',
  loaded_time: '2016-08-09 10:30:03' }
>> middlewares.js:17:10 [master] pid:10376 base middlewares attached
>> router.js:108:10 [master] pid:10376 router set
>> webdriver sdk launched
>>

>>
  macaca mobile sample

>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: POST url: /wd/hub/session, jsonBody: {"desiredCapabilities":{"autoAcceptAlerts":true,"platformName":"Android","app":"D:\\macaca\\me-app\\app\\your android apk.apk","browserName":"firefox","version":"","javascriptEnabled":true,"platform":"ANY"}}
>> session.js:47:10 [master] pid:10376 Creating session, sessionId: b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0.
>> helper.js:191:12 [master] pid:10376 Using local app form D:\macaca\me-app\app\your android apk.apk
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=
com.android.uiautomator.client.Initialize:
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: test=testStartServer
INSTRUMENTATION_STATUS: class=com.android.uiautomator.client.Initialize
INSTRUMENTATION_STATUS: current=1
>> socket server ready
>> socket client ready
recive: {"cmd":"wake","args":{}}

return: {"success":true,"data":true}

>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0,"value":"{\"autoAcceptAlerts\":true,\"platformName\":\"Android\",\"app\":\"D:\\\\macaca\\\\me-app\\\\app\\\\your android apk.apk\",\"browserName\":\"firefox\",\"version\":\"\",\"javascriptEnabled\":true,\"platform\":\"ANY\",\"window\":true}"}
>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/element, jsonBody: {"using":"id","value":"com.acp.aicaitencent:id/tvBottomTab4"}
recive: {"cmd":"find","args":{"strategy":"id","selector":"com.acp.aicaitencent:id/tvBottomTab4","multiple":false}}

return: {"success":true,"data":{"ELEMENT":"1"}}
>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0,"value":"{\"ELEMENT\":\"1\"}"}


>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/element/1/click, jsonBody: {}
recive: {"cmd":"click","args":{"elementId":"1"}}

return: {"success":true,"data":true}
>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0,"value":"true"}


>>
>>#1 Access 我的 (1269ms)

>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: GET url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/screenshot, jsonBody: {}
>> responseHandler.js:50:12 [master] pid:10376 Send Error Respone to Client: Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "D:\Android\android-sdk-windows/platform-tools/adb -s 192.168.236.101:5555 pull /data/local/tmp/screenshot.png C:\Users\cmd\AppData\Local\Temp\macaca-android-screenshot11679-10376-150nd76.png"

>> responseHandler.js:56:14 [master] pid:10376 Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "D:\Android\android-sdk-windows/platform-tools/adb -s 192.168.236.101:5555 pull /data/local/tmp/screenshot.png C:\Users\cmd\AppData\Local\Temp\macaca-android-screenshot11679-10376-150nd76.png"

    at ChildProcess.exithandler (child_process.js:213:12)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:827:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

  Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "D:\Android\android-sdk-windows/platform-tools/adb -s 192.168.236.101:5555 pull /data/local/tmp/screenshot.png C:\Users\cmd\AppData\Local\Temp\macaca-android-screenshot11679-10376-150nd76.png"

      at ChildProcess.exithandler (child_process.js:213:12)
      at emitTwo (events.js:87:13)
      at ChildProcess.emit (events.js:172:7)
      at maybeClose (internal/child_process.js:827:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

>>
>>     1) #2 should display 我的page

>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/element, jsonBody: {"using":"id","value":"com.acp.aicaitencent:id/layoutLogin"}
recive: {"cmd":"find","args":{"strategy":"id","selector":"com.acp.aicaitencent:id/layoutLogin","multiple":false}}

return: {"success":true,"data":{"ELEMENT":"2"}}

>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0,"value":"{\"ELEMENT\":\"2\"}"}
>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/element/2/click, jsonBody: {}
recive: {"cmd":"click","args":{"elementId":"2"}}

return: {"success":true,"data":true}

>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0,"value":"true"}
>>
>>#3 Access 立即登录/注册 (1441ms)

>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: GET url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/screenshot, jsonBody: {}
>> responseHandler.js:50:12 [master] pid:10376 Send Error Respone to Client: Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "D:\Android\android-sdk-windows/platform-tools/adb -s 192.168.236.101:5555 pull /data/local/tmp/screenshot.png C:\Users\cmd\AppData\Local\Temp\macaca-android-screenshot11679-10376-14ljgkf.png"

>> responseHandler.js:56:14 [master] pid:10376 Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "D:\Android\android-sdk-windows/platform-tools/adb -s 192.168.236.101:5555 pull /data/local/tmp/screenshot.png C:\Users\cmd\AppData\Local\Temp\macaca-android-screenshot11679-10376-14ljgkf.png"

    at ChildProcess.exithandler (child_process.js:213:12)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:827:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

  Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "D:\Android\android-sdk-windows/platform-tools/adb -s 192.168.236.101:5555 pull /data/local/tmp/screenshot.png C:\Users\cmd\AppData\Local\Temp\macaca-android-screenshot11679-10376-14ljgkf.png"

      at ChildProcess.exithandler (child_process.js:213:12)
      at emitTwo (events.js:87:13)
      at ChildProcess.emit (events.js:172:7)
      at maybeClose (internal/child_process.js:827:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

    2) #4 should display 登录Page

>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/element, jsonBody: {"using":"id","value":"com.acp.aicaitencent:id/etUserName"}
recive: {"cmd":"find","args":{"strategy":"id","selector":"com.acp.aicaitencent:id/etUserName","multiple":false}}

return: {"success":true,"data":{"ELEMENT":"3"}}

>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0,"value":"{\"ELEMENT\":\"3\"}"}
>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/element/3/value, jsonBody: {"value":["*****"]}
recive: {"cmd":"setText","args":{"elementId":"3","text":"******"}}

return: {"success":true,"data":true}

>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0,"value":"true"}
>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/element, jsonBody: {"using":"id","value":"com.acp.aicaitencent:id/etPwd"}
recive: {"cmd":"find","args":{"strategy":"id","selector":"com.acp.aicaitencent:id/etPwd","multiple":false}}

return: {"success":true,"data":{"ELEMENT":"4"}}

>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0,"value":"{\"ELEMENT\":\"4\"}"}
>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/element/4/value, jsonBody: {"value":["*****"]}
recive: {"cmd":"setText","args":{"elementId":"4","text":"*********"}}

return: {"success":true,"data":true}

>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0,"value":"true"}
>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/element, jsonBody: {"using":"id","value":"com.acp.aicaitencent:id/tvLogin"}
recive: {"cmd":"find","args":{"strategy":"id","selector":"com.acp.aicaitencent:id/tvLogin","multiple":false}}

return: {"success":true,"data":{"ELEMENT":"5"}}
>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0,"value":"{\"ELEMENT\":\"5\"}"}


>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/element/5/click, jsonBody: {}
recive: {"cmd":"click","args":{"elementId":"5"}}


return: {"success":true,"data":true}

>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0,"value":"true"}
>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: GET url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0/screenshot, jsonBody: {}
>> responseHandler.js:50:12 [master] pid:10376 Send Error Respone to Client: Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "D:\Android\android-sdk-windows/platform-tools/adb -s 192.168.236.101:5555 pull /data/local/tmp/screenshot.png C:\Users\cmd\AppData\Local\Temp\macaca-android-screenshot11679-10376-cm89un.png"

>> responseHandler.js:56:14 [master] pid:10376 Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "D:\Android\android-sdk-windows/platform-tools/adb -s 192.168.236.101:5555 pull /data/local/tmp/screenshot.png C:\Users\cmd\AppData\Local\Temp\macaca-android-screenshot11679-10376-cm89un.png"

    at ChildProcess.exithandler (child_process.js:213:12)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:827:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

  Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "D:\Android\android-sdk-windows/platform-tools/adb -s 192.168.236.101:5555 pull /data/local/tmp/screenshot.png C:\Users\cmd\AppData\Local\Temp\macaca-android-screenshot11679-10376-cm89un.png"

      at ChildProcess.exithandler (child_process.js:213:12)
      at emitTwo (events.js:87:13)
      at ChildProcess.emit (events.js:172:7)
      at maybeClose (internal/child_process.js:827:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

    3) #5 Edit and Login

>> responseHandler.js:11:12 [master] pid:10376 Recieve HTTP Request from Client: method: DELETE url: /wd/hub/session/b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0, jsonBody: {}
>> macaca-android.js:60:14 [master] pid:10376 Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "D:\Android\android-sdk-windows/platform-tools/adb emu kill"
error: no emulator detected

    at ChildProcess.exithandler (child_process.js:213:12)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:827:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
>> session.js:80:12 [master] pid:10376 Delete session, sessionId: b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0
>> responseHandler.js:43:14 [master] pid:10376 Send HTTP Respone to Client: {"sessionId":"b7ff1a6b-c532-40fe-b5c8-074f24b2d0b0","status":0}
>>

>>
  2 passing (1m)
  3 failing

  1) macaca mobile sample #2 should display 我的page:
     Error: [takeScreenshot()] Not JSON response
      at exports.newError (D:\macaca\me-app\node_modules\macaca-wd\wd\lib\utils.js:139:13)
      at D:\macaca\me-app\node_modules\macaca-wd\wd\lib\callbacks.js:59:17
      at D:\macaca\me-app\node_modules\macaca-wd\wd\lib\webdriver.js:179:5
      at Request._callback (D:\macaca\me-app\node_modules\macaca-wd\wd\lib\http-utils.js:87:7)
      at Request.self.callback (D:\macaca\me-app\node_modules\macaca-wd\node_modules\request\request.js:368:22)
      at Request.<anonymous> (D:\macaca\me-app\node_modules\macaca-wd\node_modules\request\request.js:1219:14)
      at IncomingMessage.<anonymous> (D:\macaca\me-app\node_modules\macaca-wd\node_modules\request\request.js:1167:12)
      at endReadableNT (_stream_readable.js:921:12)

  2) macaca mobile sample #4 should display 登录Page:
     Error: [takeScreenshot()] Not JSON response
      at exports.newError (D:\macaca\me-app\node_modules\macaca-wd\wd\lib\utils.js:139:13)
      at D:\macaca\me-app\node_modules\macaca-wd\wd\lib\callbacks.js:59:17
      at D:\macaca\me-app\node_modules\macaca-wd\wd\lib\webdriver.js:179:5
      at Request._callback (D:\macaca\me-app\node_modules\macaca-wd\wd\lib\http-utils.js:87:7)
      at Request.self.callback (D:\macaca\me-app\node_modules\macaca-wd\node_modules\request\request.js:368:22)
      at Request.<anonymous> (D:\macaca\me-app\node_modules\macaca-wd\node_modules\request\request.js:1219:14)
      at IncomingMessage.<anonymous> (D:\macaca\me-app\node_modules\macaca-wd\node_modules\request\request.js:1167:12)
      at endReadableNT (_stream_readable.js:921:12)

  3) macaca mobile sample #5 Edit and Login:
     Error: [takeScreenshot()] Not JSON response
      at exports.newError (D:\macaca\me-app\node_modules\macaca-wd\wd\lib\utils.js:139:13)
      at D:\macaca\me-app\node_modules\macaca-wd\wd\lib\callbacks.js:59:17
      at D:\macaca\me-app\node_modules\macaca-wd\wd\lib\webdriver.js:179:5
      at Request._callback (D:\macaca\me-app\node_modules\macaca-wd\wd\lib\http-utils.js:87:7)
      at Request.self.callback (D:\macaca\me-app\node_modules\macaca-wd\node_modules\request\request.js:368:22)
      at Request.<anonymous> (D:\macaca\me-app\node_modules\macaca-wd\node_modules\request\request.js:1219:14)
      at IncomingMessage.<anonymous> (D:\macaca\me-app\node_modules\macaca-wd\node_modules\request\request.js:1167:12)
      at endReadableNT (_stream_readable.js:921:12)

>> Test completed!


以下为参考的文章,向作者表示感谢,提供了思路。
如何从头编写你的 Macaca 测试用例
编写移动端 Macaca 测试用例 [单步调试]
Macaca-iOS 入门那些事 2
[基于 Node.js 的自动化测试-Macaca] - 自动化测试实践总结

更多信息请参考 wiki 汇总

小马的 macaca 入门指引合集

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 14 条回复 时间 点赞

求助 这个问题怎么解决

老马 [该话题已被删除] 中提及了此贴 10月10日 10:21

1) macaca mobile sample "before all" hook:
[init({"autoAcceptAlerts":true,"platformName":"Android","app":"/Users/mining/macaca-test-sample/app/android-app-bootstrap.zip"})] connect ECONNREFUSED 211.139.136.73:3457
Error: connect ECONNREFUSED 211.139.136.73:3457
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect as oncomplete

2) macaca mobile sample "after all" hook:
[quit()] connect ECONNREFUSED 211.139.136.73:3457
Error: connect ECONNREFUSED 211.139.136.73:3457
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect as oncomplete

这个问题如何解决?

@yangha 什么系统平台的 只是跑样例 macaca-mobile-sample.test.js 吗 请提供些具体的信息
macaca 版本啊 macaca doctor 啊

bash-3.2$ macaca doctor

macaca-doctor version: 1.0.23

Node.js checklist:

node env: /usr/local/bin/node
node version: v6.9.1

iOS checklist:

Xcode is installed at: /Applications/Xcode.app/Contents/Developer
Xcode Command Line Tools is ready, version: 2343.
Command Line Tools: ios_webkit_debug_proxy is uninstalled

Android checklist:

JAVA version is 1.7.0_79
JAVA_HOME is set to /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
ANDROID_HOME is set to /Users/mining/Downloads/sdk
Platforms is set to /Users/mining/Downloads/sdk/platforms/android-24
Android tools is set to /Users/mining/Downloads/sdk/tools/android
ADB tool is set to /Users/mining/Downloads/sdk/platform-tools/adb

Installed driver list:

android: 1.0.39

-bash-3.2$ sudo make test-android
Password:
macaca doctor

macaca-doctor version: 1.0.23

Node.js checklist:

node env: /usr/local/bin/node
node version: v6.9.1

iOS checklist:

Xcode is installed at: /Applications/Xcode.app/Contents/Developer
Xcode Command Line Tools is ready, version: 2343.
Command Line Tools: ios_webkit_debug_proxy is uninstalled

Android checklist:

JAVA version is 1.7.0_79
JAVA_HOME is not set
ANDROID_HOME is not set

Installed driver list:

android: 1.0.39

platform=android macaca run --verbose -d ./macaca-test/macaca-mobile-sample.test.js

port: 3456 was occupied, changed port: 3457
index.js:17:12 [master] pid:2911 webdriver server start with config:
{ port: 3457,
verbose: false,
always: true,
window: true,
ip: '192.168.55.102',
host: 'miningdeiMac-4.local',
loaded_time: '2016-10-28 15:13:20' }
middlewares.js:17:10 [master] pid:2911 base middlewares attached
router.js:129:10 [master] pid:2911 router set
webdriver sdk launched

macaca mobile sample

1) "before all" hook

2) "after all" hook

0 passing (1s)

2 failing

1) macaca mobile sample "before all" hook:
[init({"autoAcceptAlerts":true,"platformName":"Android","app":"/Users/mining/macaca-test-sample/app/android-app-bootstrap.zip"})] connect ECONNREFUSED 211.139.136.73:3457
Error: connect ECONNREFUSED 211.139.136.73:3457
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect as oncomplete

2) macaca mobile sample "after all" hook:
[quit()] connect ECONNREFUSED 211.139.136.73:3457
Error: connect ECONNREFUSED 211.139.136.73:3457
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect as oncomplete

我运行 sudo make test-android 时提示我 JAVA_HOME is not set
ANDROID_HOME is not set
什么原因

mac 平台,仅仅跑样例

@yangha 看样子 像是你的 macaca server 有问题,建议你确认下其他样例可跑 如果其他样例可跑 说明 macaca server 也就是 macaca-cli 部署没问题。如果只是这个 macaca-mobile-sample 脚本有问题,你先确认下 adb devices -l 是否显示正常以确保和真机或模拟器通信正常。如果正常,请检查下脚本 是否有不对的地方。

@yanghaitao 你是 ios 啊 那应该是 直接项目目录下 make test-ios 大哥~~~~ 然后确保你启动的 ios 模拟器是正常联通的,由于我没有 mac 平台 怎么确认 你搜下。 另 提示我 JAVA_HOME is not set
ANDROID_HOME is not set 可能是你带了 sudo 请先确认自己 java 环境正常。ANDROID_HOME 你这个不用弄 你是 mac 环境 除非你要在 mac 下测安卓应用,这块我没 mac 平台没尝试过。

脚本我没改,设备是连上的,我是在 mac 测 android 的,win7 行不?另外的确我带了 sudo 就提示 not set,但是运行 java --version 有结果的

老马 #11 · 2016年10月28日 Author

@yanghaitao https://testerhome.com/topics/5804 参考这个 一些基础问题 比如 mac 系统 java 环境配置 这些自己去搜

make-test android 我不加 sudo 的话出现 Error: EACCES: permission denied, open '/usr/local/lib/node_modules/.macaca-cli_npminstall/node_modules/.1.0.67@webdriver-server/logs/digest-2016_10_28.log'
at Error (native),加 sudo 的话又找不到 java。。。。。。

老马 #13 · 2016年10月28日 Author

@yanghaitao 属于基本的 类 linux 平台 软件安装部署问题。
我没 mac,我就类比 Linux ubuntu 说下, 感觉你可能是 部署的时候 有的加了 sudo 有的没加。导致权限混乱。
你可以 就用一非 root 账号部署,不要穿插着 root 账号用。 注意部署时使用的账号,注意权限设置,比如可以 chown -R 账号:账号组 目录 来改变某一软件目录的权限。mac 怎么配置管理权限 你自己搜下。

谢谢,这方面知识的确需要补一下

15楼 已删除

@harsayer 谢谢,把权限的问题解决了,然后 jdk 换成了 1.8,mac 中跑 android 成功了!

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册