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