App自动化测试框架Appium安装和使用
安装Nodejs
安装nodejs 10.x(注意:18.04上自带的nodejs 8是不行的):
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install nodejs
安装Appium
理想方法:
npm install -g appium
npm install wd
appium &
实际安装方法:
sudo npm --proxy http://192.168.10.149:10809 install -g appium --unsafe-perm=true --allow-root
启动Appium
export JAVA_HOME=/home/tony/Work/02_sw/android-studio/jre
export ANDROID_SDK_ROOT=/home/tony/Work/02_sw/studio-sdk
appium
运行例子
mkidr test && cd test
npm init -y
node index.js
例子,来源:http://appium.io/docs/en/about-appium/getting-started/
// javascript
const wdio = require("webdriverio");
const assert = require("assert");
const opts = {
port: 4723,
path: "/wd/hub", // fix: The URL '/session' did not map to a valid resource
capabilities: {
platformName: "Android",
platformVersion: "10",
deviceName: "Android Emulator",
app: "/path/to/the/downloaded/ApiDemos.apk",
appPackage: "io.appium.android.apis",
appActivity: ".view.TextFields",
automationName: "UiAutomator2"
}
};
async function main () {
const client = await wdio.remote(opts);
const field = await client.$("android.widget.EditText");
await field.setValue("Hello World!");
const value = await field.getText();
assert.equal(value,"Hello World!");
await client.deleteSession();
}
main();