Skip to content

Commit 8bf1711

Browse files
author
fanniehuang
committed
fix(e2e): dcp & windows os bug
re #80
1 parent 2bceed3 commit 8bf1711

File tree

4 files changed

+63
-51
lines changed

4 files changed

+63
-51
lines changed

packages/wxa-cli/README.md

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,76 +8,88 @@
88
* 已知bug:
99
* 暂无
1010
* 待优化&计划:
11+
* 截屏用的图片比对条件过于苛刻,稍微有些偏移就报错;理想情况:整体页面稍微有些偏移不应报错,因小程序rpx单位渲染,有小数点的时候,每次渲染不能保证位置一致,导致整体页面有位移,想调整下图片比对调节,时下能不能忽略偏移。
1112
* 不带-r参数时,即回放模式,仅添加元素id(回放测试用例时能找到对应元素),不侵入过多代码(现在会劫持各种tap等事件,植入全局按钮组件)
1213
* 高大上网页版测试报告
1314
* 【用例复用】:支持用例复用-公共用例不用重复录制(如:登陆模块只需要录制一次,其他用例复用,当登录模块更改时,只需要重新录制一次登录,不需要每个用例都重新录制)
1415
* 【真机】:支持真机
1516
* 【服务器】:有个公共服务器解决用例执行的问题
1617
* 各种未知bug
1718

18-
2020年3月2日
19+
2020年3月10日
1920
# 使用手册
2021

2122
### 安装
22-
* 项目下安装 `npm i -DE miniprogram-automator looks-same wxa-cli2-apple jest`
23+
* 任意目录执行命令 `npm i -g wxa-cli2-apple`
24+
* 先安装项目依赖 `npm i`
25+
* 项目目录下执行命令 `npm i -DE miniprogram-automator looks-same jest`
2326

2427
### 测试脚本录制
25-
1. 微信开发者工具,打开对应项目,勾选`不校验合法域名`
28+
1. 微信开发者工具,打开对应项目,勾选`不校验合法域名`(src/project.config.json需同步修改urlCheck:false
2629
2. windows系统,wxa.config.js里增加属性`wechatwebdevtools `,配置微信开发者工具的安装目录
30+
31+
```
32+
module.exports = {
33+
wechatwebdevtools: "D:\....(开发者工具安装目录)"
34+
.....
35+
}
36+
37+
```
38+
3. 开发者工具修改调试基础库 2.7.3以上(src/project.config.json需同步修改libVersion)
39+
4. 项目根目录下添加文件`babel.config.js`(如果根目录下已有.babelrc,会有冲突,需将.babelrc中的配置合并到babel.config.js里)
40+
41+
```
42+
const path = require('path');
43+
const existsSync = require('fs').existsSync;
44+
45+
46+
// try to find @babel/runtime to decide whether add @babel/plugin-transform-runtime.
47+
const cwd = process.cwd();
48+
const babelRuntime = path.join(cwd, 'node_modules', '@babel/runtime/package.json');
49+
let hasRuntime = existsSync(babelRuntime);
50+
51+
const commonConfigs = {
52+
53+
'plugins': [
54+
['@babel/plugin-proposal-decorators', {'decoratorsBeforeExport': true}],
55+
['@babel/plugin-proposal-class-properties'],
56+
],
57+
'presets': ['@babel/preset-env'],
58+
59+
};
60+
if (hasRuntime) {
61+
const pkg = require(babelRuntime);
62+
63+
commonConfigs.plugins.unshift(['@babel/plugin-transform-runtime', {'version': pkg.version || '7.2.0'}]);
64+
}
65+
66+
module.exports = {
67+
'sourceMap': false,
68+
'ignore': [],
69+
overrides: [{
70+
exclude: [/node_modules/, /wxa-cli/],
71+
...commonConfigs
72+
},
73+
{
74+
test: /wxa-e2eTest/,
75+
...commonConfigs
76+
}
77+
]
78+
};
79+
80+
```
81+
2782
3. 项目目录下执行`wxa2-apple test --e2e -r`,开启录制模式
2883
* 用开发者工具打开项目,页面左上角有`结束录制`button,说明已成功开启录制模式
2984
* 此时与小程序的每一步交互都会录制为脚本,完成操作后,点击`结束录制`,输入用例名,对应脚本保存在`__wxa_e2e_test__`目录下
3085

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

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

3792
### 测试脚本回放
38-
* 开发者工具修改调试基础库 2.7.3以上(src/project.config.json需同步修改libVersion)
39-
* 项目根目录下添加文件`babel.config.js`
40-
41-
```
42-
const path = require('path');
43-
const existsSync = require('fs').existsSync;
44-
45-
46-
// try to find @babel/runtime to decide whether add @babel/plugin-transform-runtime.
47-
const cwd = process.cwd();
48-
const babelRuntime = path.join(cwd, 'node_modules', '@babel/runtime/package.json');
49-
let hasRuntime = existsSync(babelRuntime);
50-
51-
const commonConfigs = {
52-
53-
'plugins': [
54-
['@babel/plugin-proposal-decorators', {'decoratorsBeforeExport': true}],
55-
['@babel/plugin-proposal-class-properties'],
56-
],
57-
'presets': ['@babel/preset-env'],
58-
59-
};
60-
if (hasRuntime) {
61-
const pkg = require(babelRuntime);
62-
63-
commonConfigs.plugins.unshift(['@babel/plugin-transform-runtime', {'version': pkg.version || '7.2.0'}]);
64-
}
65-
66-
module.exports = {
67-
'sourceMap': false,
68-
'ignore': [],
69-
overrides: [{
70-
exclude: [/node_modules/, /wxa-cli/],
71-
...commonConfigs
72-
},
73-
{
74-
test: /wxa-e2eTest/,
75-
...commonConfigs
76-
}
77-
]
78-
};
79-
80-
```
8193
* `wxa2-apple test --e2e` 进入测试用例回放模式,操作截屏以时间命名保存在测试用例目录中(`--test=test1,test2`指定执行用例,多个用例逗号分隔)
8294

8395

packages/wxa-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wxa-cli2-apple",
3-
"version": "1.0.0",
3+
"version": "1.0.9",
44
"description": "cli for wxa development",
55
"main": "dist/wxa.js",
66
"scripts": {

packages/wxa-cli/src/tester/wxa-e2eTest/mockWxMethodConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export default [
3030
name: 'request',
3131
recordStringify(config) {
3232
console.log(getKey.call(this, [
33-
config.url, config.method, Object.keys(config.data).join(',')
33+
config.url, config.method, Object.keys(config.data || {}).join(',')
3434
]));
3535
return getKey.call(this, [
36-
config.url, config.method, Object.keys(config.data).join(',')
36+
config.url, config.method, Object.keys(config.data || {}).join(',')
3737
])
3838
},
3939
tpl: (() => {

packages/wxa-cli/src/tester/wxa-e2eTest/runTestCase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default async function(cmd, wxaConfigs) {
8383

8484

8585
try {
86-
execSync(`./node_modules/.bin/jest ${path.join(testDir, '.cache', 'index.test.js')}`, {
86+
execSync(`npx jest ${path.join(testDir, '.cache', 'index.test.js')}`, {
8787
stdio: 'inherit'
8888
});
8989
process.exit(0);

0 commit comments

Comments
 (0)