python版的链接如下:
链接:https://pan.baidu.com/s/10dIjiiI1il6KmQRO6jWwVg
提取码:exjs
Java版用的是appium-desktop1.8.1,testng6.11,java-client6.1.0,selenium-java3.13.0
1、下载逍遥模拟器,装好app
2、下载adb,用adb连接逍遥模拟器,找到abd路径,在cmd里cd D:\platform-tools-latest-windows\platform-tools , 用 adb connect 127.0.0.1:21503
3、用adb devices,查看是否连接到模拟器
5、启动server1.9.1,Start Inspector Session,配置Desired Capabilities,
首先配置aapt的环境变量:类似于D:\androidSDK\build-tools\29.0.3,然后进入CMD
使用aapt dump badging C:\Users\Administrator\Downloads\xxx.apk(APK的全名),
第一行获取包名,下拉到中间部分获取activity
6、start session 进入到定位元素页面,大功告成,可以写脚本了
7、第一个DEMO,创建maven项目,配置pom文件如下
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.test
AppiumLatest
0.0.1-SNAPSHOT
org.testng
testng
6.11
org.apache.commons
commons-lang3
3.7
com.google.guava
guava
23.0
io.appium
java-client
6.1.0
org.seleniumhq.selenium
selenium-java
3.13.0
org.apache.maven.plugins
maven-surefire-plugin
2.18.1
false
testng.xml
8、创建一个hahaha的类,如下
package com.yidong.Test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
public class hahaha {
static AndroidDriver driver;
static DesiredCapabilities capabilities;
@BeforeTest
public static void start() throws MalformedURLException, InterruptedException{
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),setCapsforMobileBrowser(capabilities));
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.id("com.creditease.android:id/btnStart")).click();
driver.findElement(By.id("com.creditease.android:id/agree")).click();
WebElement tvlift=driver.findElementById("com.creditease.android:id/tv_life");
Assert.assertEquals(tvlift.isEnabled(), true);
}
@Test
public void init() throws MalformedURLException, InterruptedException {
try {
start();
} catch (Exception e) {
System.out.println("inside catch");
e.printStackTrace();
}
}
public static DesiredCapabilities setCapsforMobileBrowser(DesiredCapabilities capabilities){
capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.APPIUM_VERSION, "1.8.1");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "SM-A053F");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.creditease.android");
capabilities.setCapability("appActivity", ".view.activity.home.SplashH5AdvertisementActivity");
capabilities.setCapability("noRest", true);
return capabilities;
}
@AfterTest
public void tearDown(){
driver.quit();
}
}
9.运行,testng test,成功