This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathtests-api.js
More file actions
141 lines (118 loc) Β· 4.27 KB
/
Copy pathtests-api.js
File metadata and controls
141 lines (118 loc) Β· 4.27 KB
<
F543
div class="codeBlobInner__L_BQg_">
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
'use strict';
var Suite = require('./suite'),
State = require('./state');
function nothing() {}
function makeSkipBrowser(browser) {
if (typeof browser === 'string') {
return {browserName: browser};
}
if (typeof browser !== 'object' || browser === null) {
throw new TypeError('suite.skip browsers must be strings or object');
}
if (!browser.browserName) {
throw new Error('browserName is not specified');
}
if (typeof browser.browserName !== 'string') {
throw new TypeError('browserName must be a string');
}
if ('version' in browser && typeof browser.version !== 'string') {
throw new TypeError('version must be a string');
}
return browser;
}
function notString(arg) {
return typeof arg !== 'string';
}
function SuiteBuilder(suite) {
this.setCaptureElements = function() {
var selectors;
if (arguments.length === 1 && Array.isArray(arguments[0])) {
selectors = arguments[0];
} else {
selectors = Array.prototype.slice.call(arguments);
}
if (selectors.some(notString)) {
throw new TypeError('suite.captureElements accepts only strings or array of strings');
}
suite.captureSelectors = selectors;
return this;
};
this.before = function(hook) {
if (typeof hook !== 'function') {
throw new TypeError('before hook must be a function');
}
suite.beforeHook = hook;
return this;
};
this.after = function(hook) {
if (typeof hook !== 'function') {
throw new TypeError('after hook must be a function');
}
suite.afterHook = hook;
return this;
};
this.setUrl = function setUrl(url) {
if (typeof url !== 'string') {
throw new TypeError('URL must be string');
}
suite.url = url;
return this;
};
this.capture = function capture(name, cb) {
if (typeof name !== 'string') {
throw new TypeError('State name should be string');
}
cb = cb || nothing;
if (typeof cb !== 'function') {
throw new TypeError('Second argument of suite.capture must be a function');
}
if (suite.hasStateNamed(name)) {
throw new Error('State "' + name + '" already exists in suite "' + suite.name + '". ' +
'Choose different name');
}
suite.addState(new State(suite, name, cb));
return this;
};
this.skip = function skip(browser) {
if (!browser) {
suite.skip();
} else if (Array.isArray(browser)) {
suite.skip(browser.map(makeSkipBrowser));
} else if (typeof browser === 'string' || typeof browser === 'object') {
suite.skip([makeSkipBrowser(browser)]);
} else {
throw new TypeError('Unacceptable value for suite.skip method: ' + browser);
}
return this;
};
}
module.exports = function(context, rootSuite) {
var suiteId = 1;
context.suite = function suite(name, callback) {
if (typeof name !== 'string') {
throw new TypeError('First argument of the gemini.suite must be a string');
}
if (typeof callback !== 'function') {
throw new TypeError('Second argument of the gemini.suite must be a function');
}
if (rootSuite.hasChildNamed(name)) {
throw new Error('Suite ' + name + ' already exists at this level. Choose different name');
}
rootSuite = Suite.create(name, rootSuite);
rootSuite.id = suiteId++;
callback(new SuiteBuilder(rootSuite));
if (rootSuite.hasStates) {
if (!rootSuite.url) {
throw new Error('URL is required to capture screenshots. ' +
'Call suite.setUrl(<DESIRED PATH>) on "' + rootSuite.name +
'" suite or one of its parents');
}
if (!rootSuite.captureSelectors) {
throw new Error('Capture region is required to capture screenshots. ' +
'Call suite.setCaptureElements(<CSS SELECTORS>) on "' + rootSuite.name +
'" suite or one of its parents');
}
}
rootSuite = rootSuite.parent;
};
};