Skip to content

Commit 61e852a

Browse files
author
fanniehuang
committed
fix(e2e): 兼容windows
re #80
1 parent 8bf1711 commit 61e852a

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

packages/wxa-cli/README.md

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

19-
2020年3月10日
21+
2020年3月11日
2022
# 使用手册
2123

2224
### 安装
@@ -25,12 +27,13 @@
2527
* 项目目录下执行命令 `npm i -DE miniprogram-automator looks-same jest`
2628

2729
### 测试脚本录制
30+
1. 微信开发者工具 - 设置 - 安全设置 - 打开服务端口
2831
1. 微信开发者工具,打开对应项目,勾选`不校验合法域名`(src/project.config.json需同步修改urlCheck:false
2932
2. windows系统,wxa.config.js里增加属性`wechatwebdevtools `,配置微信开发者工具的安装目录
3033

3134
```
3235
module.exports = {
33-
wechatwebdevtools: "D:\....(开发者工具安装目录)"
36+
wechatwebdevtools: "C:/Program Files (x86)/Tencent/微信web开发者工具"
3437
.....
3538
}
3639

packages/wxa-cli/src/tester/wxa-e2eTest/e2eTestCaseTpl.ejs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import looksSame from 'looks-same';
88
let miniProgram;
99
let page;
1010
let testCaseNameArr = JSON.parse('<%- testCaseNameArr %>')
11-
let testDir = '<%- testDir %>';
11+
let testDir = '<%= testDir %>';
1212
let screenshotDirname = '<%- screenshotPath %>'
1313
let screenshotDiff = <%- screenshotDiff %>;
1414
let base = <%- base %>;
@@ -56,14 +56,18 @@ for (let j = 0; j < testCaseNameArr.length; j++) {
5656
if (base) {
5757
try {
5858
fs.rmdirSync(screenshotDir);
59-
} catch (err) {}
59+
} catch (err) {
60+
console.log(err)
61+
}
6062
}
6163
try {
6264
fs.mkdirSync(screenshotDir)
6365
if (!base) {
6466
fs.mkdirSync(diffDir);
6567
}
66-
} catch(err) {}
68+
} catch(err) {
69+
console.log(err);
70+
}
6771

6872
let record = require(path.join(testDir, testName, `./record.js`));
6973
let screenCount = 0;
@@ -142,7 +146,7 @@ for (let j = 0; j < testCaseNameArr.length; j++) {
142146
// await miniprogram.restoreWxMethod('request');
143147
let same = await screenShot({
144148
screenshotDir,
145-
screenCount: ++screenCount,
149+
screenCount: screenCount,
146150
diff: screenshotDiff || record[record.length - 1].sceeenshotDiff
147151
})
148152
// 无diff图片,则比对通过

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default async function(cmd, wxaConfigs) {
3838
// 开发者工具clipath
3939
let clipath = {
4040
darwin: '/Contents/MacOS/cli',
41-
win32: '/cli.bat',
41+
win32: `/cli.bat`,
4242
};
4343
let {cliPath} = cmd;
4444
let cli = cliPath || path.join(wxaConfigs.wechatwebdevtools, clipath[process.platform]);
@@ -65,10 +65,10 @@ export default async function(cmd, wxaConfigs) {
6565
}
6666

6767
let recordString = await testCase2js({
68-
cliPath: cli,
68+
cliPath: cli.split(path.sep).join('/'),
6969
testCaseNameArr: JSON.stringify(testCaseNameArr),
70-
testDir,
71-
screenshotPath,
70+
testDir: testDir.split(path.sep).join('/'),
71+
screenshotPath: screenshotPath.replace(' ', '_').replace(/:/g, '.'),
7272
base: !!cmd.base,
7373
screenshotDiff: screenshotDiff,
7474
noMockApi: !!cmd.noMock,
@@ -83,7 +83,7 @@ export default async function(cmd, wxaConfigs) {
8383

8484

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

0 commit comments

Comments
 (0)