Skip to content

Commit

Permalink
fix(e2e): switchTab兼容windows;利用peerDependencies简化依赖安装步骤
Browse files Browse the repository at this point in the history
re #80
  • Loading branch information
fanniehuang committed Apr 22, 2021
1 parent de9356c commit 4011b2d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
24 changes: 12 additions & 12 deletions packages/wxa-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
# 使用手册

### 安装
* 任意目录执行命令 `npm i -g wxa-cli2-apple`
* 先安装项目依赖 `npm i`
* 项目目录下执行命令 `npm i -DE miniprogram-automator looks-same jest`
* 先安装项目依赖 `wnpm i`
* 项目目录下执行命令 `wnpm i @webank/wxa-cli2-apple`

### python 及依赖安装
* [Python官网](https://www.python.org/)网下载Python安装包(python-3.X.X.exe)
### python 及依赖安装(可选,带参数--py-diff时需要安装)
* [Python官网](https://www.python.org/)下载Python安装包(python-3.X.X.exe)
* 全局安装PIL `pip install pillow`

### 测试脚本录制
Expand Down Expand Up @@ -86,22 +85,19 @@

```

3. 项目目录下执行`wxa2-apple test --e2e -r`,开启录制模式
3. 项目目录下执行`npx wxa2-apple test --e2e -r`,开启录制模式
* 用开发者工具打开项目,页面左上角有`结束录制`button,说明已成功开启录制模式
* 此时与小程序的每一步交互都会录制为脚本,完成操作后,点击`结束录制`,输入用例名,对应脚本保存在`__wxa_e2e_test__`目录下

### 进行基准截屏
脚本录制过程中不会截屏,需要跑一次case脚本,完成基准截屏。若无基准截屏,用例回归时就不知道测试结果是否正确,所以这一步骤是必须的

* 脚本录制完毕后,需执行`wxa2-apple test --e2e --base ` 回放用例,检查录制操作是否正确,且此次回放的截屏会作为后续回放用例的比较基准,用于判断测试是否通过
* 脚本录制完毕后,需执行`npx wxa2-apple test --e2e --base ` 回放用例,检查录制操作是否正确,且此次回放的截屏会作为后续回放用例的比较基准,用于判断测试是否通过
* 基准截屏存放在`__wxa_e2e_test__/用例名/base_screenshot`中(`--test=test1,test2`可指定要回放的用例,多个用例逗号分隔)

### 测试脚本回放
* `wxa2-apple test --e2e` 进入测试用例回放模式,操作截屏以时间命名保存在测试用例目录中(`--test=test1,test2`指定执行用例,多个用例逗号分隔)

### 测试结果校准

* 进入项目根目录,执行`wxa2-apple test-diff`
* `npx wxa2-apple test --e2e` 进入测试用例回放模式,操作截屏以时间命名保存在测试用例目录中(`--test=test1,test2`指定执行用例,多个用例逗号分隔)
* `npx wxa2-apple test --e2e --py-diff` 结果截屏进行相似度比对,不需要每个像素点一摸一样,需安装python3

### 二次开发录制好的测试用例
通过修改`测试用例/record.js`,可以进行用例二次开发
Expand All @@ -117,6 +113,10 @@ record.js是一个数组,每一项Object对应用户一次操作(点击、
* `--no-mock` `wxa2-apple test --e2e --no-mock`此次用例回归,不mock api,直连真实接口(默认会用录制时的api数据来mock)
* `--screenshot-diff` `wxa2-apple test --e2e --screenshot-diff=fasle` 此次用例回归,截屏是否要和base_screenshot目录下的首次截屏进行比对(不传值默认会比对,false不比对)
* `--custom-expect` 进行自定义期望匹配,需要record.js里每一步的customExpect函数编写期望代码
* `--py-diff` 结果截屏进行相似度比对,不需要每个像素点一摸一样,需安装python3




```
module.exports = [
Expand Down
7 changes: 6 additions & 1 deletion packages/wxa-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webank/wxa-cli2-apple",
"version": "1.0.51",
"version": "1.0.57",
"description": "cli for wxa development",
"main": "dist/wxa.js",
"scripts": {
Expand All @@ -20,6 +20,11 @@
},
"repository": "https://github.com/wxajs/wxa.git",
"homepage": "https://wxajs.github.io/wxa/",
"peerDependencies": {
"miniprogram-automator": "^0.10.0",
"looks-same": "^7.3.0",
"jest": "^26.6.3"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/wxa-cli/src/tester/imageSimilarity/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def GetDirList(self, cur_path, cur_type):
生成结果
'''
def WriteFile(self, out_dir):
json_path = target_path + "\\.replay_result\\" + out_dir + "\\diff_result.json"
json_path = os.path.join(target_path, ".replay_result", out_dir, "diff_result.json")
if os.path.exists(json_path):
os.remove(json_path)
with open(json_path, 'xt', encoding='utf-8') as f:
Expand Down
17 changes: 12 additions & 5 deletions packages/wxa-cli/src/tester/wxa-e2eTest/e2eTestCaseTpl.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ for (let j = 0; j < testCaseNameArr.length; j++) {
break;
} else if (page.path === (recordAction.page || recordAction.appStartPage).split('?')[0]) {
if (!lastRecordAction) break;
let lastPagePath = (lastRecordAction.page || lastRecordAction.appStartPage).split('?')[0]
if (page.path !== lastPagePath) {
// 和上一步的页面path不一致,说明页面切换了,需要等久一点让页面ready
await sleep(6000);
try {
let lastPagePath = (lastRecordAction.page || lastRecordAction.appStartPage || lastRecordAction.path).split('?')[0]
if (page.path !== lastPagePath) {
// 和上一步的页面path不一致,说明页面切换了,需要等久一点让页面ready
await sleep(6000);
}
} catch(err) {
await sleep(2000);
}
break;
}
Expand Down Expand Up @@ -159,7 +163,10 @@ for (let j = 0; j < testCaseNameArr.length; j++) {
} else if (!!~['input'].indexOf(recordAction.event)) {
await element[recordAction.event](recordAction.detail.value);
} else if (!!~['switchTab'].indexOf(recordAction.event)) {
await miniProgram.switchTab(path.resolve('/', recordAction.path))
if (recordAction.path[0] !== '/') {
recordAction.path = '/' + recordAction.path;
}
await miniProgram.switchTab(recordAction.path)
} else if (!!~['touchstart', 'touchmove', 'touchend'].indexOf(recordAction.event)) {
await element[recordAction.event]({
touches: recordAction.touches,
Expand Down
2 changes: 1 addition & 1 deletion packages/wxa-cli/src/tester/wxa-e2eTest/e2eTestSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const hjSwitchTab = () => {
if (e.openType === 'switchTab') {
let action = {
event: 'switchTab',
path: e.path,
path: '/' + e.path,
query: e.query
};
if (state.record.length === 0) {
Expand Down

0 comments on commit 4011b2d

Please sign in to comment.