使用macaca进行移动端hybird自动化测试(三)

macaca提供了命令单独启动webdriver server.然后我们在REPL作为client,向server端发送模拟操作命令。

首先启动server:

    macaca server --verbose

使用macaca进行移动端hybird自动化测试(三)_第1张图片

启动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完成了一次输入的操作
    
    //...接下来大家就按自己的流程去写自己的测试脚本啦

使用macaca进行移动端hybird自动化测试(三)_第2张图片

↑图是clientserver端进行http通讯的log.

使用REPL去编写测试用例的比较方便的地方就是,整个测试过程不会因为你编写的测试用例存在问题而暂停整个server,或者模拟器,因此可以在REPL里面先进行测试用例的编写,等到结果正确后再写入文件,等所有的测试用例完成后再进行整个的case测试过程。下一篇将如果编写webview的测试用例

你可能感兴趣的:(自动化测试,macaca,javascript)