-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
110 lines (100 loc) · 3.11 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/** @module utils */
const R = require('./ramda.custom.js');
let defaultPath = './';
// var addFour = a => b => c => d => a + b + c + d;
// var uncurriedAddFour = R.uncurryN(4, addFour);
// uncurriedAddFour(1, 2, 3, 4); //=> 10
/**
* | function | result |
* | ----------------------- | -------------------------------------- |
* | R.uncurryN(2, | R.pipe( |
* | R.pipe( | R.tap(login.gotoLogin), |
* | R.map(R.tap), | R.tap(login.typeId), |
* | R.apply(R.pipe) | R.tap(login.clickPassword) |
* | )); | );
*/
exports.runPipe = R.uncurryN(2,
R.pipe(
R.map(R.tap),
R.apply(R.pipe)
)
);
// pipe的輸入等於上一個的輸出
// tap的輸入什麼就輸出什麼
// map輸入array輸出為Array
//
// step1:
// R.map =>
// [R.tap(login.gotoLogin),
// R.tap(login.typeId),
// R.tap(login.clickPassword),
// R.tap(login.typePassword),
// R.tap(login.waitItembox),
// R.tap(login.clickLogin),
// R.tap(tutorial.clickSkip),
// R.tap(login.getCookie)]
// step2:
// R.pipe(
// R.tap(login.gotoLogin),
// R.tap(login.typeId),
// R.tap(login.clickPassword),
// R.tap(login.typePassword),
// R.tap(login.waitItembox),
// R.tap(login.clickLogin),
// R.tap(tutorial.clickSkip),
// R.tap(login.getCookie)
//)
// step3:
// SC001(nightmare);
// R.tap(login.gotoLogin('http://172.17.28.213', '8082'))(nightmare) -> 輸出 nightmare
// 輸入 nightmare -> R.tap(login.typeId('admin')(nightmare) -> 輸出 nightmare,
// step4
// exports.gotoLogin = (url, port) => runTask({
// name: `前往${url}:${port}`,
// action: (nightmare) => nightmare.goto(`${url}:${port}/ns/login`),
// })
class CatchThenError {
constructor(e){
this.origin = e;
}
}
/**
* options -> nightmare -> it
* @param {Object} taskOptions
*
* | options | args |
* | ----------------------- | -------------------------------------- |
* | name | it(name) |
* | action | nightmare.wait or nightmare.click |
* | catch | default nightmare.screenshot |
* | catchThen | self invoking function |
*/
exports.runTask = (taskOptions) => (nightmare) => it(taskOptions.name, (done) => {
const c = taskOptions.catch ?
(e) => taskOptions.catch(done, e, nightmare) :
(e) =>
nightmare
.html(`${defaultPath}${taskOptions.name}.mhtml`, 'MHTML')
.screenshot(`${defaultPath}${taskOptions.name}.png`)
.then(() => taskOptions.catchThen ?
Promise.reject(new CatchThenError(e)) :
done(e)
)
taskOptions
.action(nightmare)
.then(() => done())
.catch(c)
.catch((e) => {
if (e instanceof CatchThenError) {
taskOptions.catchThen(done, e.origin, nightmare)
} else {
throw e
}
});
})
/**
* It is to set your snapshot path
*/
exports.setSnapshotPath = (path) => {
defaultPath = path;
}