cnpm install -g appium
npm install -g appium-doctor
// appium-doctor --android
- 启动Appium(需要开两个cmd 一个启动appium 一个启动js脚本)
appium -p 端口号
// cnpm i wd -S
const wd = require('wd');
let driver = await wd.promiseChainRemote({
host: '127.0.0.1',
port: 4723
});
let desiredCaps = {
platformName: 'Android',
deviceName: '127.0.0.1:62001',
"appPackage": "ssss.xxxx",
"appActivity": "com.yy.xxxxx.startup.MainActivity",
automationName: 'Appium'
};
await driver.init(desiredCaps);
await driver.setImplicitWaitTimeout(6000);
- 操作获取到的元素(通过appium客户端可以获取元素id)(尽量不要用Xpath)
// 点击
let avatar = await driver.elementById("video.like:id/rl_avatar");
await avatar.click();
// 填写账号
let phone = await driver.elementById("video.like:id/et_phone");
await phone.sendKeys("137XXXXXXX");
await (new wd.TouchAction(driver))
.press({x: 368, y: 1011})
.moveTo({x: 366, y: 340})
.release()
.perform();
网友评论