最近完成一项基于 Appium + Junit5 + Allure + Maven 进行 Android APP UI 自动化测试的项目。我会分不同的方面来整理所学和所遇到的问题。这里首先介绍测试环境的准备。
adb:Android 的控制工具,用于获取 Android 的各种数据和控制
D:\AndroidSdk\tools\bin
sdkmanager "platform-tools" "platforms;android-29"
)、build-tools(sdkmanager "build-tools;29.0.2"
),并添加环境变量:D:\AndroidSdk\platform-tools;
D:\AndroidSdk\build-tools\;
Appium Server:Appium 的核心工具,命令行工具
npm install-gcnpm--registry=https://registry.npm.taobao.org
cnpm install -g appium
Appium Desktop:内嵌了 Appium server 和 inspector 工具的综合工具
Github 下载安装appium desktop
Appium Client:各种语言的客户端封装库,用于连接 Appium Server
添加如下配置到 pom.xml 文件
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>${appium-java-client.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Junit5 由三个不同子项目中的 3 个模块组成:JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage
。添加如下配置到 pom.xml 文件:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
Allure 是开源的测试报告框架,支持多种主流语言,生成适合团队所有人查看的测试报告。添加如下配置到 pom.xml 文件:
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>${allure-junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>RELEASE</version>
</dependency>
Maven2017.3 之后的版本支持 Junit5,请注意 Maven 版本。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.erp.www</groupId>
<artifactId>xiangmuname</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<junit.jupiter.version>5.5.2</junit.jupiter.version>
<aspectj.version>1.8.10</aspectj.version>
<allure-junit5.version>2.13.1</allure-junit5.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<allure-maven.version>2.10.0</allure-maven.version>
<appium-java-client.version>7.3.0</appium-java-client.version>
<jackson-dataformat-yaml.version>2.10.1</jackson-dataformat-yaml.version>
<hamcrest-core.version>2.2</hamcrest-core.version>
<encoding>UTF-8</encoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.encoding>UTF-8</project.encoding>
<project.build.sourceEncoding>${project.encoding}</project.build.sourceEncoding>
<project.reporting.outputEncoding>${project.encoding}</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
</properties>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>${appium-java-client.version}</version>
<scope>test</scope>
</dependency>
<!--JUNIT 5 Dependencies-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-core -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-dataformat-yaml.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>${jackson-dataformat-yaml.version}</version>
<scope>test</scope>
</dependency>
<!--Allure Reporting Dependencies-->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>${allure-junit5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Need at least 2.22.0 to support JUnit 5 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<properties>
<property>
<name>listener</name>
<value>io.qameta.allure.junit5.AllureJunit5</value>
</property>
</properties>
<includes>
<include>**/*Test*.java</include>
</includes>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<systemProperties>
<property>
<name>junit.jupiter.extensions.autodetection.enabled</name>
<value>true</value>
</property>
<property>
<name>allure.results.directory</name>
<value>${project.basedir}/target/allure-results</value>
</property>
</systemProperties>
<reportFormat>plain</reportFormat>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>${allure-maven.version}</version>
<configuration>
<reportVersion>2.8.1</reportVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>