-
Notifications
You must be signed in to change notification settings - Fork 59
/
hooks.js
96 lines (79 loc) · 2.61 KB
/
hooks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const fs = require('fs');
const createTestCafe = require('testcafe');
const testControllerHolder = require('../support/testControllerHolder');
const {AfterAll, setDefaultTimeout, Before, After, Status} = require('cucumber');
const errorHandling = require('../support/errorHandling');
const TIMEOUT = 20000;
let isTestCafeError = false;
let attachScreenshotToReport = null;
let cafeRunner = null;
let n = 0;
function createTestFile() {
fs.writeFileSync('test.js',
'import errorHandling from "./features/support/errorHandling.js";\n' +
'import testControllerHolder from "./features/support/testControllerHolder.js";\n\n' +
'fixture("fixture")\n' +
'test\n' +
'("test", testControllerHolder.capture)')
}
function runTest(iteration, browser) {
createTestCafe('localhost', 1338 + iteration, 1339 + iteration)
.then(function(tc) {
cafeRunner = tc;
const runner = tc.createRunner();
return runner
.src('./test.js')
.screenshots('reports/screenshots/', true)
.browsers(browser)
.run()
.catch(function(error) {
console.error(error);
});
})
.then(function(report) {
});
}
setDefaultTimeout(TIMEOUT);
Before(function() {
runTest(n, this.setBrowser());
createTestFile();
n += 2;
return this.waitForTestController.then(function(testController) {
return testController.maximizeWindow();
});
});
After(function() {
fs.unlinkSync('test.js');
testControllerHolder.free();
});
After(async function(testCase) {
const world = this;
if (testCase.result.status === Status.FAILED) {
isTestCafeError = true;
attachScreenshotToReport = world.attachScreenshotToReport;
errorHandling.addErrorToController();
await errorHandling.ifErrorTakeScreenshot(testController)
}
});
AfterAll(function() {
let intervalId = null;
function waitForTestCafe() {
intervalId = setInterval(checkLastResponse, 500);
}
function checkLastResponse() {
if (testController.testRun.lastDriverStatusResponse === 'test-done-confirmation') {
cafeRunner.close();
process.exit();
clearInterval(intervalId);
}
}
waitForTestCafe();
});
const getIsTestCafeError = function() {
return isTestCafeError;
};
const getAttachScreenshotToReport = function(path) {
return attachScreenshotToReport(path);
};
exports.getIsTestCafeError = getIsTestCafeError;
exports.getAttachScreenshotToReport = getAttachScreenshotToReport;