创建第一個appium脚本
在jave-project 創建
創建class
開始代碼的編寫
举例子app:驾考宝典apk
先查找出包名和出口
确定appPackage
在命令行输入如下:
D:\Andriod_SDK\build-tools\27.0.1>aapt dump badging D:\test\駕考寶典.apk | findstr package
打开
D:\Andriod_SDK\build-tools\27.0.1,输入cmd,跳出如下,输入aapt dump badging D:\test\駕考寶典.apk | findstr package
找入口appActivity
D:\Andriod_SDK\build-tools\27.0.1>aapt dump badging D:\test\駕考寶典.apk | findstr launchable-activity
脚本如下:
package com.test.firstAppium;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URL;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
public class AppiumTest001 {
public static void main(String[] args) throws MalformedURLException {
//1.創建配置對象
DesiredCapabilities desiredCapabilities=new DesiredCapabilities();
//2.添加配置
//deviceName:可以找到我们测试的设备
desiredCapabilities.setCapability("deviceName", "127.0.0.1:62001");
//platformName:测试平台android or IOS
desiredCapabilities.setCapability("platformName", "Android");
//appPackage:找到测试 APP:aapt dump badging.....
desiredCapabilities.setCapability("appPackage", "com.handsgo.jiakao.android");
//appActivity:测试app入口
desiredCapabilities.setCapability("appActivity","com.handsgo.jiakao.android.splash.Login");
//创建驱动
//传入2个参数
//第一个参数:Appium通讯地址
//第二个参数:配置对象
AndroidDriver <WebElement> androidDriver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);
}
public class AppiumTest001 {
public static void main(String[] args) throws MalformedURLException {
//1.創建配置對象
DesiredCapabilities desiredCapabilities=new DesiredCapabilities();
//2.添加配置
//deviceName:可以找到我们测试的设备
desiredCapabilities.setCapability("deviceName", "127.0.0.1:62001");
//platformName:测试平台android or IOS
desiredCapabilities.setCapability("platformName", "Android");
//appPackage:找到测试 APP:aapt dump badging.....
desiredCapabilities.setCapability("appPackage", "com.handsgo.jiakao.android");
//appActivity:测试app入口
desiredCapabilities.setCapability("appActivity","com.handsgo.jiakao.android.splash.Login");
//创建驱动
//传入2个参数
//第一个参数:Appium通讯地址
//第二个参数:配置对象
AndroidDriver <WebElement> androidDriver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);
}
}运行脚本的时候,启动appium和模拟器夜神
cmd:adb devices检查是否已经连接了
![](https://img2020.cnblogs.com/i-beta/1946760/202003/1946760-20200307175328026-1310599136.png)
运行成功,APK 在模拟器被打开