使用macaca進行移動端hybird自動化測試(三)
作者:蘋果小蘿卜
macaca提供了命令單獨啟動webdriver server.然后我們在REPL作為client,向server端發送模擬操作命令。
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的測試用例
責任編輯:龐桂玉
來源:
segmentfault