编程语言
首页 > 编程语言> > Javascript+webdriverio实现app自动化demo

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("执行完成!"));

标签:vidma,demo,app,Javascript,client,sleep,editor,videomaker,id
来源: https://www.cnblogs.com/wanyuan/p/16408864.html