Javascript+webdriverio实现app自动化demo


1.新建工程和安装库

使用WebStorm新建一个空项目然后在编辑器打开终端输入如下命令:

npm init -y

npm install webdriverio
npm install sleep
 
2.编写代码
代码如下:

// javascript
const webdriver = require("webdriverio");
const sleep = require("sleep");
const caps = {
    path: '/wd/hub',
    port: 4723,
    capabilities: {
        fullreset: false,
        platformName: "android",
        uiautomator2ServerInstallTimeout: 100000,
        platformVersion: "10",
        deviceName: "Galaxy A11",
        automationName: "UiAutomator2",
        newCommandTimeout: 1000,
        appActivity: "com.atlasv.android.mvmaker.mveditor.SplashActivity",
        appPackage: "vidma.video.editor.videomaker",
        autoGrantPermissions: false,
        noReset: true
    }
};


async function main() {
    const client = await webdriver.remote(caps);
    sleep.sleep(5);
    await client.$("id=vidma.video.editor.videomaker:id/ivAdd").click()
    sleep.sleep(3);
    await client.$$("id=vidma.video.editor.videomaker:id/ivIcon")[1].click();
    sleep.sleep(3);
    await client.$("id=vidma.video.editor.videomaker:id/tvNext").click();
    sleep.sleep(3);
    await client.$("id=vidma.video.editor.videomaker:id/ivBack").click();
    client.closeApp();
}

main().then(() => console.log("执行完成!"));

原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/tech/webdev/272748.html

(0)
上一篇 2022年7月9日 10:25
下一篇 2022年7月9日 10:26

相关推荐

发表回复

登录后才能评论