Skip to content

Commit 207d223

Browse files
xudafengpopomore
authored andcommitted
feat: support macaca ui test (eggjs#71)
1 parent 7a36543 commit 207d223

File tree

6 files changed

+92
-3
lines changed

6 files changed

+92
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ coverage
44
npm-debug.log
55
.logs
66
logs
7-
*.swp
7+
*.sw*
88
run
99
*-run
1010
.idea
@@ -19,4 +19,6 @@ assets-with-umi/config/manifest.json
1919
.umi
2020
.umi-production
2121
dist
22+
screenshots
23+
reports
2224
.history

view-nunjucks/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
},
77
"devDependencies": {
88
"egg-bin": "^4.3.5",
9-
"egg-mock": "^3.13.1"
9+
"egg-mock": "^3.13.1",
10+
"macaca-electron": "^1.1.19",
11+
"macaca-wd": "^1.0.37"
1012
},
1113
"scripts": {
1214
"dev": "egg-bin dev",
1315
"test": "egg-bin test",
16+
"test:ui": "macaca run -d ./uitest --reporter macaca-reporter",
1417
"cov": "egg-bin cov"
1518
},
1619
"private": true

view-nunjucks/test/index.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
43
const mm = require('egg-mock');
54

65
describe('example view-nunjucks test', () => {

view-nunjucks/uitest/helper.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
const wd = require('macaca-wd');
4+
const {
5+
extendsMixIn,
6+
} = require('macaca-wd/lib/helper');
7+
8+
extendsMixIn(wd);
9+
10+
const port = 7001;
11+
12+
const BASE_URL = `http://127.0.0.1:${port}`;
13+
14+
wd.addPromiseChainMethod('initWindow', function(options = {}) {
15+
return this
16+
.init(Object.assign({
17+
platformName: 'desktop',
18+
browserName: 'electron',
19+
deviceScaleFactor: 2,
20+
}, options))
21+
.setWindowSize(options.width, options.height);
22+
});
23+
24+
const driver = wd.promiseChainRemote({
25+
host: 'localhost',
26+
port: process.env.MACACA_SERVER_PORT || 3456,
27+
});
28+
29+
exports.driver = driver;
30+
exports.BASE_URL = BASE_URL;

view-nunjucks/uitest/homepage.test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
5+
const {
6+
driver,
7+
BASE_URL,
8+
} = require('./helper');
9+
10+
describe('test/homepage.test.js', () => {
11+
describe('home page UI testing', () => {
12+
13+
before(function() {
14+
this.timeout(5 * 1000);
15+
return driver
16+
.initWindow({
17+
width: 800,
18+
height: 600,
19+
deviceScaleFactor: 2,
20+
});
21+
});
22+
23+
beforeEach(() => {
24+
return driver
25+
.getUrl(`${BASE_URL}`);
26+
});
27+
28+
afterEach(function() {
29+
return driver
30+
.saveScreenshots(this);
31+
});
32+
33+
after(() => {
34+
return driver
35+
.openReporter(false)
36+
.quit();
37+
});
38+
39+
it('page render success', () => {
40+
return driver
41+
.setWindowSize(800, 600)
42+
.title()
43+
.then(title => {
44+
assert.equal(title, 'egg view example');
45+
})
46+
.source()
47+
.then(html => {
48+
assert.ok(html.includes('egg view example here, welcome foobar'));
49+
});
50+
});
51+
});
52+
});

view-nunjucks/uitest/mocha.opts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--require babel-register
2+
--recursive
3+
--timeout 60000

0 commit comments

Comments
 (0)