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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 | 1
1
1
1
1
1
1
1
1
1
1
1
1
1
168
168
168
168
1
1
1
84
1
1
1
84
1
1
1
1
186
1
186
186
186
186
1
1
81
165
165
165
165
1
1
16
21
21
21
21
21
21
21
1
1
1
1
84
84
1
1
1
84
1
1
1
1
1
1
168
1
1
1
1
1
| (function() {
var $, Driver, argv, color, _,
__slice = [].slice;
Driver = require('selenium-webdriver');
$ = Driver.promise;
argv = require('minimist')(process.argv);
_ = require('lodash');
color = require('colors');
global.timeout = 5000;
module.exports = function() {
var flowStep, shouldPreventBrowserReload, terminateDriver, _After, _Before;
this.Driver = Driver;
_Before = this.Before;
_After = this.After;
this._inFlow = function(code, callback) {
return $.createFlow((function(_this) {
return function(flow) {
return flow.execute(function() {
return code.call(_this);
});
};
})(this)).then(_.partial(callback, null), function(err) {
throw err;
});
};
this.Before = function(code) {
return _Before((function(_this) {
return function(callback) {
return _this._inFlow(code, callback);
};
})(this));
};
this.After = function(code) {
return _After((function(_this) {
return function(callback) {
return _this._inFlow(code, callback);
};
})(this));
};
this.BeforeAll = function(code) {
if (!this._ranBeforeAll) {
this._ranBeforeAll = true;
return this.Before(code);
}
};
this.AfterAll = function(code) {
if (!this._ranAfterAll) {
this._ranAfterAll = true;
return this.After(code);
}
};
flowStep = (function(_this) {
return function(code, args, pending, successCallback, errCallback) {
_this.Pending = function(reason) {
return successCallback = _.partial(pending, reason);
};
return $.createFlow(function(flow) {
return flow.execute(function() {
return code.apply(_this, args);
});
}).then(function(result) {
return successCallback(null, result);
}, errCallback);
};
})(this);
this.Given = this.When = (function(_this) {
return function(pattern, code) {
return _this.defineStep(pattern, function() {
var args, callback, _i;
args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), callback = arguments[_i++];
_this.lastStepType = 'Given';
return flowStep(code, args, callback.pending, callback, callback);
});
};
})(this);
this.Then = (function(_this) {
return function(pattern, code) {
return _this.defineStep(pattern, function() {
var args, callback, callforth, start, _i;
args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), callback = arguments[_i++];
_this.lastStepType = 'Then';
start = new Date;
callforth = function() {
return flowStep(code, args, callback.pending, callback, function(error) {
if (new Date - start > timeout) {
return callback(error);
} else {
return $.delayed(1000).then(function() {
return callforth();
});
}
});
};
return callforth();
});
};
})(this);
this.And = (function(_this) {
return function(pattern, code) {
return _this[_this.lastStepType](pattern, code);
};
})(this);
this.Freeze = function() {
var keyPress, stdin;
keyPress = false;
stdin = process.stdin;
stdin.setRawMode(true);
stdin.resume();
stdin.setEncoding('utf8');
console.log('Press any key to continue...'.yellow.inverse);
process.stdin.on('data', (function(key) {
return keyPress = true;
}));
return this.driver.wait((function() {
return keyPress;
}), Infinity).then(function() {
return process.stdin.pause();
});
};
this.Before(function() {
this.lastStepType = 'Given';
if (!this.driver || !shouldPreventBrowserReload()) {
this.driver = new Driver.Builder().withCapabilities(Driver.Capabilities[argv.driver || 'chrome']()).build();
return this.driver.visit = this.driver.get;
}
});
this.After(function() {
Iif (!shouldPreventBrowserReload()) {
return terminateDriver();
}
});
this.registerHandler("AfterFeatures", (function(_this) {
return function(event, callback) {
Eif (shouldPreventBrowserReload()) {
return terminateDriver().then(function() {
return callback();
});
} else {
return callback();
}
};
})(this));
shouldPreventBrowserReload = function() {
return argv['prevent-browser-reload'] != null;
};
terminateDriver = (function(_this) {
return function() {
_this.driver.close();
return _this.driver.quit();
};
})(this);
return this.When(/^I Freeze$/, this.Freeze);
};
}).call(this);
|