Capabilities 官网文档地址:http://appium.io/docs/en/writing-running-appium/caps/index.html
package com.test;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidDriver;
public class Appium {
public static void main(String[] args) throws Exception {
AndroidDriver driver;
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("automationName", "uiautomator2");// appium做自动化
// cap.setCapability("app", "C:\\software\\jrtt.apk");//安装apk
// cap.setCapability("browserName", "chrome");//设置HTML5的自动化,打开谷歌浏览器
cap.setCapability("deviceName", "5fa632f");// 设备名称
cap.setCapability("platformName", "Android"); // 安卓自动化还是IOS自动化
cap.setCapability("platformVersion", "5.0.2"); // 安卓操作系统版本
cap.setCapability("udid", "5fa632f"); // 设备的udid (adb devices 查看到的)
cap.setCapability("appPackage", "xxx.xxxx.xxx");// 被测app的包名
cap.setCapability("appActivity", "xxx.xxxx.xxxxActivity");// 被测app的入口Activity名称
cap.setCapability("unicodeKeyboard", "True"); // 支持中文输入
cap.setCapability("resetKeyboard", "True"); // 支持中文输入,必须两条都配置
cap.setCapability("noSign", "True"); // 不重新签名apk
cap.setCapability("newCommandTimeout", "300"); // 没有新命令,appium30秒退出
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), cap);// 把以上配置传到appium服务端并连接手机
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);// 隐式等待
// 通过xxx定位元素
driver.findElement(MobileBy.AccessibilityId("")).click();
driver.findElement(MobileBy.AndroidUIAutomator("")).click();
driver.findElement(MobileBy.id("")).click();
driver.findElement(MobileBy.xpath("")).click();
}
}
package com.test;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileBy;
import io.appium.java_client.ios.IOSDriver;
public class Appium {
public static void main(String[] args) throws Exception {
IOSDriver driver;
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("automationName", "XCUITest");// appium做自动化
// cap.setCapability("app", "C:\\software\\jrtt.ipa");//安装ipa
cap.setCapability("deviceName", "iphone8plus");// 设备名称
cap.setCapability("platformName", "iOS"); // 安卓自动化还是IOS自动化
cap.setCapability("platformVersion", "11.2.5"); //操作系统版本
cap.setCapability("udid", "c65d00a8cda9947953dac52e92071aa1481f23a2"); // 设备的udid
cap.setCapability("bundleId", "com.xxx.xxxx");// 被测app的bundledid
cap.setCapability("newCommandTimeout", "300"); // 没有新命令,appium30秒退出
driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), cap);// 把以上配置传到appium服务端并连接手机
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);// 隐式等待
// 通过xxx定位元素
driver.findElement(MobileBy.AccessibilityId("")).click();
driver.findElement(MobileBy.iOSNsPredicateString("")).click();
driver.findElement(MobileBy.xpath("")).click();
}
}