使用macaca進(jìn)行移動(dòng)端hybird自動(dòng)化測(cè)試(三)
macaca提供了命令單獨(dú)啟動(dòng)webdriver server.然后我們?cè)赗EPL作為client,向server端發(fā)送模擬操作命令。
首先啟動(dòng)server:
- macaca server --verbose
啟動(dòng)server后,接下來首先給server發(fā)送命令,讓server喚起模擬器:
- >> var wd = require('webdriver-client')({
- platformVersion: '9.3',
- deviceName: 'iPhone 5s',
- platformName: 'iOS',
- app: YOUR-APP-PATH
- });
- >> var driver = wd.initPromiseChain();
- >> driver.initDriver();
- //這個(gè)時(shí)候就能看到server啟動(dòng)了IOS模擬器.
- //接下來的操作就是編寫腳本去操作模擬器的動(dòng)作了
- >> 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完成了一次輸入的操作
- //...接下來大家就按自己的流程去寫自己的測(cè)試腳本啦
↑圖是client和server端進(jìn)行http通訊的log.
使用REPL去編寫測(cè)試用例的比較方便的地方就是,整個(gè)測(cè)試過程不會(huì)因?yàn)槟憔帉懙臏y(cè)試用例存在問題而暫停整個(gè)server,或者模擬器,因此可以在REPL里面先進(jìn)行測(cè)試用例的編寫,等到結(jié)果正確后再寫入文件,等所有的測(cè)試用例完成后再進(jìn)行整個(gè)的case測(cè)試過程。下一篇將如果編寫webview的測(cè)試用例