ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
appuim环境搭建 1下载安装并配置jdk ``` JAVA_HOME=C:\Program Files\Java\jdk1.8.0_271 path=%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin CLASSPATH=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar ``` 2下载安装idea 3下载并配置sdk环境变量 ![](https://img.kancloud.cn/6e/b6/6eb6f5d2fd7e3ecbafd0c55f6878ebd2_1145x3000.png) ``` ANDROID_HOME=F:\softTest\tools\appuim\android-sdk_r24 PATH=;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools; ``` 4 下载安装夜神模拟器 5 把sdk中的adb命令替换到夜神模拟器中 6 在idea中创建项目,完善项目资源及代码 ``` ~~~ package com; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.AndroidElement; public class AppuimTest { private static AndroidDriver<AndroidElement> driver; public static void init() { // 获取当前程序的路径 File classpathRoot = new File(System.getProperty("user.dir")); // 获取apps文件 File appDir = new File(classpathRoot, "apps"); // 获取apk文件 File app = new File(appDir, "ContactManager.apk"); // 包装数据发送给appium-servier DesiredCapabilities capabilities = new DesiredCapabilities(); // 启动的设备名称 capabilities.setCapability("device", "127.0.0.1:62001");// 夜神模拟器名称 // 系统平台名称 capabilities.setCapability("PLATFORM", "Android"); // 系统平台版本 capabilities.setCapability("platformVersion", "7.1.2"); // app的绝对路径 capabilities.setCapability("app", app.getAbsolutePath()); // app的包名 // capabilities.setCapability("appPackage", "com.example.android.contactmanager"); // app的入口启动activity capabilities.setCapability("appActivity", ".ContactManager"); // 连接appium启动相应app try { driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } System.out.println("App is launched!");// } public static void start() throws InterruptedException { Thread.sleep(100); // 找到相应元素 WebElement el = driver.findElement(By.name("Add Contact")); el.click();// 模拟点击 // 找到eidit控件 List<AndroidElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText"); // 为第一个edit控件设置值 textFieldsList.get(0).sendKeys("Some Name"); Thread.sleep(100); WebElement spin = driver.findElement(By.id("com.example.android.contactmanager:id/contactPhoneTypeSpinner")); spin.click(); Thread.sleep(100); WebElement t = driver.findElement(By.name("手机")); t.click(); Thread.sleep(100); // 为第三个edit控件设置值 textFieldsList.get(2).sendKeys("Some@example.com"); Thread.sleep(500); WebElement spin2 = driver.findElement(By.id("com.example.android.contactmanager:id/contactEmailTypeSpinner")); spin2.click(); Thread.sleep(500); WebElement tt = driver.findElement(By.name("其他")); System.out.println(); tt.click(); Thread.sleep(100); System.out.println("App is done!"); } public static void end() { // 关闭子窗口 driver.quit(); } public static void main(String[] args) throws InterruptedException{ System.out.println("-----"); init(); Thread.sleep(3000); end(); } } ~~~ ``` 7 测试运行脚本