Skip to content

Commit dbebe0c

Browse files
committed
init
0 parents  commit dbebe0c

33 files changed

+4025
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.idea
2+
/target
3+
nohup.out
4+
*.iml
5+
/.settings
6+
.classpath
7+
.project
8+
.vscode
9+
.DS_Store
10+
chromedriver
11+
config
12+
scripts

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# KoolTest UI 自动化测试框架
2+
3+
为了给用户提供更优质的产品体验,在产品上线前需要进行各项测试。其中回归测试多由测试人员手动执行,耗费了大量人力,并且还可能存在漏测问题。鉴于此,我们在跨端的 UI 自动化上面做了大量的优化和思考,实现了 KoolTest 的 跨端 UI 自动化测试方案,用以降低人力成本。目前本框架支持使用一套脚本规范来测试 Android、iOS、Web。
4+
5+
6+
7+
## 基本原理
8+
9+
![](https://qhstaticssl.kujiale.com/newt/165/image/png/1629281227269/C942720CFE68A7305D4EB8EBCD995E9D.png)
10+
11+
虽然 iOS、Android、Web 不同,但他们在元素查找、元素操作方式上有一定的共性,当然也有很多区别。比如 iOS 和 Android 支持 AccessibilityId 定位,而 Web 不支持;再比如 Web 支持的 class 方式查找,客户端平台不支持等,并且 iOS 和 Android 本身也有不一样的地方。所以我们在实现同时面向三者的测试平台时,需要特别注意这些差异的地方,尽量使用共性的部分,在使用平台独有功能时,在代码中进行平台判断。我们把其三者的关系梳理如下,其中 AppiumDriver 是客户端测试共性的类,基于 Selenium 提供的 RemoteWebDriver 实现,iOS 和 Android 的 Driver 基于 AppiumDriver 实现。
12+
13+
![](https://qhstaticssl.kujiale.com/newt/165/image/png/1629282336357/54F4C33A4F569F794E34C3D3B4BF3A14.png)
14+
15+
在 Client 之上,我们基于 Cucumber 实现了一套 BDD+关键字风格的测试描述语言(Kool Lang)。如下这个脚本,可以执行在所有终端,只要文案一致。
16+
17+
```
18+
Feature: 登陆测试
19+
Scenario: 登录失败
20+
* open "https://www.kujiale.com"
21+
* tap "我的设计"
22+
* input "test@test.com" to "手机号/邮箱"
23+
* input "111111" to "密码"
24+
* tap "登录"
25+
* assert_exists "账号密码错误"
26+
```
27+
28+
29+
30+
## 快速开始
31+
32+
**安装 java 环境**
33+
34+
https://docs.oracle.com/goldengate/1212/gg-winux/GDRAD/java.htm#BGBFJHAB
35+
36+
37+
38+
**安装 VSCode,并安装 kool-test-script 插件**
39+
40+
https://code.visualstudio.com/
41+
42+
![](https://qhstaticssl.kujiale.com/newt/165/image/png/1620440762840/48F1331DE7F02091AC40A183B083DF95.png)
43+
44+
45+
46+
**开始书写**
47+
48+
直接使用 VsCode 创建一个空项目,增加一个 .feature 文件,比如
49+
50+
![](https://qhstaticssl.kujiale.com/newt/165/image/png/1629283979942/45885072951456B290D39995F2B059A8.png)
51+
52+
点击 ***脚本回放***(首次运行因为要下载对应环境配置,所以会慢一些),则直接会运行该脚本,如果需要打断点调试,可以在某个步骤中插入 debugger 标签(注意 debugger 标签不要放在 Scenario 第一行,也不要放在 Background 中),再点击运行回放时,网页会停留在该断点处,此时你可以使用截图、脚本录制(只能在 .macro 中进行录制),或自行获取 selector。比如
53+
54+
```
55+
Scenario: 酷家乐网页登录测试-登录错误
56+
* input "12345" to "输入密码"
57+
* tap "登录"
58+
debugger
59+
* assert_exists "账号密码不正确"
60+
```
61+
62+
63+
64+
***OK,以上就是所有你需要掌握的啦~,恭喜!*** 接下来你可以学习下 KoolTest 的基础词汇啦。[点击前往学习](https://github.com/Kujiale-Mobile/KoolTest/wiki/%E5%9F%BA%E7%A1%80%E8%AF%8D%E6%B1%87)
65+
66+
67+
68+
## 开源说明
69+
70+
本开源库为 KoolTest 的运行时部分,由 java 代码编写。Clone 本库后,可以使用 任何顺手的 Java IDE 进行修改调试。然后可以使用 `mvn package` 进行打包,得到的 jar 包包含了所有依赖,可以直接使用。 以下为该 jar 包的所有参数。
71+
72+
```
73+
java -jar KoolTest.jar . // 其中 . 表示当前目录,该命令会执行在当前目录下的所有 .feature 文件
74+
```
75+
76+
| 参数名 | 默认值 | 说明 |
77+
| ----------------------- | ------ | ------------------------------------------------------------ |
78+
| --name | | 运行的 scenario 名,可以使用正则让多个 scenario 一起运行 |
79+
| --tags | | 运行某些 @Tag 的 Scenario,可以用 ~ 排除某些标签,比如 --tags "@SmokeTest,~@WIP",则运行所有 @SmokeTest 标签的 Scenario,而不运行有 @WIP 标签的 |
80+
| --platform | chrome | 指定运行的平台,可以为 chrome、edge、safari、firefox、android、ios |
81+
| --script | . | 运行脚本目录,默认为当前目录,主要与 config 配置有关,配置错误会导致 config 找不到 |
82+
| --server | | 所连接的服务地址,app 测试时可以指定某个 appium 地址,chrome 测试可以指定 chromedriver 运行地址 |
83+
| --chromeDriver | | chromedriver 所在地址,如果设置了则不需要再设置 --server,运行时会自动运行该 driver。 |
84+
| --env | | 环境变量,格式为 "key:value key1:value1" |
85+
| --showProcess | | 无参数,该次是否显示执行过程,如 java -jar KoolTest.jar . --showProcess,则会以显示的方式执行本目录下的所有执行过程 |
86+
| --app | | app 测试专用,设置 apk 或 ipa 的路径 |
87+
| --udid | | app 测试专用,指定设备号 |
88+
| --logDir | target | log 的输出地址 |
89+
| --remote-debugging-port | | 本次运行打开 chrome 的调试端口,并且结束后不关闭 chrome,后面加端口号,如 9222 |
90+
91+
后续我们会逐步开源我们的 vscode 插件和 KoolTest运行平台 部分代码。欢迎大家继续关注。
92+
93+
94+
95+
## Thanks
96+
97+
KoolTest 的完成离不开社区的支持,此处特别感谢以下两个组织:
98+
99+
https://github.com/cucumber
100+
101+
https://github.com/appium
102+
103+
104+
105+
## License
106+
107+
```
108+
Copyright [2021] [Manycore Tech Inc.]
109+
110+
Licensed under the Apache License, Version 2.0 (the "License");
111+
you may not use this file except in compliance with the License.
112+
You may obtain a copy of the License at
113+
114+
http://www.apache.org/licenses/LICENSE-2.0
115+
116+
Unless required by applicable law or agreed to in writing, software
117+
distributed under the License is distributed on an "AS IS" BASIS,
118+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
119+
See the License for the specific language governing permissions and
120+
limitations under the License.
121+
```
122+

assets/selectors.crx

292 KB
Binary file not shown.

pom.xml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.qunhe</groupId>
8+
<artifactId>KoolTest</artifactId>
9+
<version>1.6.3</version>
10+
<build>
11+
<plugins>
12+
<plugin>
13+
<groupId>org.apache.maven.plugins</groupId>
14+
<artifactId>maven-compiler-plugin</artifactId>
15+
<version>3.8.0</version>
16+
<configuration>
17+
<source>1.8</source>
18+
<target>1.8</target>
19+
</configuration>
20+
</plugin>
21+
<plugin>
22+
<groupId>org.apache.maven.plugins</groupId>
23+
<artifactId>maven-jar-plugin</artifactId>
24+
<version>2.4</version>
25+
<executions>
26+
<execution>
27+
<goals>
28+
<goal>test-jar</goal>
29+
</goals>
30+
</execution>
31+
</executions>
32+
</plugin>
33+
<plugin>
34+
<groupId>org.apache.maven.plugins</groupId>
35+
<artifactId>maven-assembly-plugin</artifactId>
36+
<version>3.1.0</version>
37+
<configuration>
38+
<archive>
39+
<manifest>
40+
<mainClass>com.qunhe.avocado.RunCukesTest</mainClass>
41+
</manifest>
42+
</archive>
43+
<descriptors>
44+
<descriptor>src/main/assembly/fat.xml</descriptor>
45+
</descriptors>
46+
</configuration>
47+
<executions>
48+
<execution>
49+
<phase>package</phase>
50+
<goals>
51+
<goal>single</goal>
52+
</goals>
53+
</execution>
54+
</executions>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.jsoup</groupId>
61+
<artifactId>jsoup</artifactId>
62+
<version>1.8.3</version>
63+
<scope>compile</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>io.cucumber</groupId>
67+
<artifactId>cucumber-java</artifactId>
68+
<version>4.2.0</version>
69+
<scope>test</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>junit</groupId>
73+
<artifactId>junit</artifactId>
74+
<version>4.12</version>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>io.appium</groupId>
79+
<artifactId>java-client</artifactId>
80+
<version>7.2.0</version>
81+
<scope>test</scope>
82+
</dependency>
83+
<dependency>
84+
<groupId>io.github.bonigarcia</groupId>
85+
<artifactId>webdrivermanager</artifactId>
86+
<version>4.4.1</version>
87+
<scope>test</scope>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.yaml</groupId>
91+
<artifactId>snakeyaml</artifactId>
92+
<version>1.20</version>
93+
<scope>test</scope>
94+
</dependency>
95+
<dependency>
96+
<groupId>com.opencsv</groupId>
97+
<artifactId>opencsv</artifactId>
98+
<version>4.0</version>
99+
<scope>test</scope>
100+
</dependency>
101+
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
102+
<dependency>
103+
<groupId>com.squareup.okhttp3</groupId>
104+
<artifactId>okhttp</artifactId>
105+
<version>4.2.2</version>
106+
<scope>test</scope>
107+
</dependency>
108+
<dependency>
109+
<groupId>org.projectlombok</groupId>
110+
<artifactId>lombok</artifactId>
111+
<version>1.18.16</version>
112+
<scope>test</scope>
113+
</dependency>
114+
<dependency>
115+
<groupId>io.cucumber</groupId>
116+
<artifactId>cucumber-core</artifactId>
117+
<version>4.2.0</version>
118+
<scope>test</scope>
119+
</dependency>
120+
</dependencies>
121+
</project>

src/main/assembly/fat.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
4+
<id>fat</id>
5+
<formats>
6+
<format>jar</format>
7+
</formats>
8+
<includeBaseDirectory>false</includeBaseDirectory>
9+
<dependencySets>
10+
<dependencySet>
11+
<outputDirectory>/</outputDirectory>
12+
<useProjectArtifact>true</useProjectArtifact>
13+
<!-- we're creating the test-jar as an attachement -->
14+
<useProjectAttachments>true</useProjectAttachments>
15+
<unpack>true</unpack>
16+
<scope>test</scope>
17+
</dependencySet>
18+
</dependencySets>
19+
<fileSets>
20+
<fileSet>
21+
<directory>${project.build.directory}/test-classes</directory>
22+
<outputDirectory>/</outputDirectory>
23+
<includes>
24+
<include>**/*.class</include>
25+
</includes>
26+
<useDefaultExcludes>true</useDefaultExcludes>
27+
</fileSet>
28+
</fileSets>
29+
</assembly>

0 commit comments

Comments
 (0)