Java教程

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("执行完成!"));
这篇关于Javascript+webdriverio实现app自动化demo的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!