macaca提供了命令单独启动webdriver server.然后我们在repl作为client,向server端发送模拟操作命令。
首先启动server:
macaca server --verbose
启动server后,接下来首先给server发送命令,让server唤起模拟器:
>> var wd = require('webdriver-client')({
platformversion: '9.3',
devicename: 'iphone 5s',
platformname: 'ios',
app: your-app-path
});
>> var driver = wd.initpromisechain();
>> driver.initdriver();
//这个时候就能看到server启动了ios模拟器.
//接下来的操作就是编写脚本去操作模拟器的动作了
>> driver.waitforelementbyxpath('//xcuielementtypeapplication[1]/xcuielementtypewindow[1]/xcuielementtypeother[2]/xcuielementtypebutton[1]').click();
//看到native完成了一次操作
>> driver.waitforelementbyxpath('//xcuielementtypeapplication[1]/xcuielementtypewindow[1]/xcuielementtypeother[1]/xcuielementtypeother[1]/xcuielementtypeother[1]/xcuielementtypeother[1]/xcuielementtypeother[1]/xcuielementtypeother[1]/xcuielementtypeother[1]/xcuielementtypetextfield[1]').sendkeys(123456789)
//看到native完成了一次输入的操作
//...接下来大家就按自己的流程去写自己的测试脚本啦
↑图是client和server端进行http通讯的log.
使用repl去编写测试用例的比较方便的地方就是,整个测试过程不会因为你编写的测试用例存在问题而暂停整个server,或者模拟器,因此可以在repl里面先进行测试用例的编写,等到结果正确后再写入文件,等所有的测试用例完成后再进行整个的case测试过程。下一篇将如果编写webview的测试用例
作者:苹果小萝卜
来源:51cto