codeceptjs 2.1.3 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +125 -37
- package/README.md +15 -22
- package/bin/codecept.js +4 -1
- package/docs/acceptance.md +44 -1
- package/docs/advanced.md +1 -1
- package/docs/angular.md +6 -9
- package/docs/basics.md +388 -75
- package/docs/bdd.md +4 -3
- package/docs/best.md +1 -1
- package/docs/books.md +31 -0
- package/docs/build/Appium.js +215 -176
- package/docs/build/Nightmare.js +618 -489
- package/docs/build/Polly.js +189 -0
- package/docs/build/Protractor.js +747 -608
- package/docs/build/Puppeteer.js +914 -633
- package/docs/build/REST.js +1 -1
- package/docs/build/TestCafe.js +1835 -0
- package/docs/build/WebDriver.js +861 -805
- package/docs/build/WebDriverIO.js +616 -617
- package/docs/changelog.md +410 -316
- package/docs/commands.md +6 -6
- package/docs/community-helpers.md +2 -0
- package/docs/detox.md +235 -0
- package/docs/examples.md +23 -0
- package/docs/helpers/ApiDataFactory.md +11 -10
- package/docs/helpers/Appium.md +130 -61
- package/docs/helpers/Detox.md +579 -0
- package/docs/helpers/FileSystem.md +2 -1
- package/docs/helpers/Mochawesome.md +1 -0
- package/docs/helpers/Nightmare.md +348 -128
- package/docs/helpers/Polly.md +85 -0
- package/docs/helpers/Protractor.md +451 -184
- package/docs/helpers/Puppeteer-firefox.md +55 -0
- package/docs/helpers/Puppeteer.md +619 -183
- package/docs/helpers/REST.md +17 -16
- package/docs/helpers/SeleniumWebdriver.md +9 -8
- package/docs/helpers/TestCafe.md +1168 -0
- package/docs/helpers/WebDriver.md +600 -291
- package/docs/helpers/WebDriverIO.md +393 -278
- package/docs/helpers.md +37 -18
- package/docs/locators.md +2 -0
- package/docs/mobile-react-native-locators.md +64 -0
- package/docs/mobile.md +5 -0
- package/docs/plugins.md +54 -13
- package/docs/puppeteer.md +74 -26
- package/docs/quickstart.md +47 -12
- package/docs/react.md +67 -0
- package/docs/reports.md +1 -1
- package/docs/{webapi/_keys.mustache → shared/keys.mustache} +0 -0
- package/docs/shared/react.mustache +1 -0
- package/docs/testcafe.md +157 -0
- package/docs/videos.md +19 -0
- package/docs/webapi/amOnPage.mustache +1 -1
- package/docs/webapi/appendField.mustache +2 -2
- package/docs/webapi/attachFile.mustache +2 -2
- package/docs/webapi/checkOption.mustache +2 -2
- package/docs/webapi/clearCookie.mustache +1 -1
- package/docs/webapi/clearField.mustache +1 -1
- package/docs/webapi/click.mustache +2 -2
- package/docs/webapi/clickLink.mustache +3 -3
- package/docs/webapi/dontSee.mustache +6 -3
- package/docs/webapi/dontSeeCheckboxIsChecked.mustache +7 -1
- package/docs/webapi/dontSeeCookie.mustache +5 -1
- package/docs/webapi/dontSeeCurrentUrlEquals.mustache +6 -1
- package/docs/webapi/dontSeeElement.mustache +5 -1
- package/docs/webapi/dontSeeElementInDOM.mustache +5 -1
- package/docs/webapi/dontSeeInCurrentUrl.mustache +1 -1
- package/docs/webapi/dontSeeInField.mustache +7 -2
- package/docs/webapi/dontSeeInSource.mustache +5 -1
- package/docs/webapi/dontSeeInTitle.mustache +5 -1
- package/docs/webapi/doubleClick.mustache +2 -2
- package/docs/webapi/downloadFile.mustache +2 -2
- package/docs/webapi/dragAndDrop.mustache +2 -2
- package/docs/webapi/dragSlider.mustache +2 -2
- package/docs/webapi/executeAsyncScript.mustache +1 -1
- package/docs/webapi/executeScript.mustache +1 -1
- package/docs/webapi/fillField.mustache +2 -2
- package/docs/webapi/grabAttributeFrom.mustache +3 -2
- package/docs/webapi/grabBrowserLogs.mustache +3 -1
- package/docs/webapi/grabCookie.mustache +2 -1
- package/docs/webapi/grabCssPropertyFrom.mustache +3 -2
- package/docs/webapi/grabCurrentUrl.mustache +3 -1
- package/docs/webapi/grabDataFromPerformanceTiming.mustache +19 -0
- package/docs/webapi/grabHTMLFrom.mustache +2 -1
- package/docs/webapi/grabNumberOfOpenTabs.mustache +4 -2
- package/docs/webapi/grabNumberOfVisibleElements.mustache +3 -2
- package/docs/webapi/grabPageScrollPosition.mustache +3 -1
- package/docs/webapi/grabSource.mustache +3 -1
- package/docs/webapi/grabTextFrom.mustache +2 -1
- package/docs/webapi/grabTitle.mustache +3 -1
- package/docs/webapi/grabValueFrom.mustache +2 -1
- package/docs/webapi/moveCursorTo.mustache +3 -3
- package/docs/webapi/pressKey.mustache +1 -1
- package/docs/webapi/resizeWindow.mustache +2 -2
- package/docs/webapi/rightClick.mustache +2 -2
- package/docs/webapi/saveScreenshot.mustache +3 -3
- package/docs/webapi/say.mustache +2 -2
- package/docs/webapi/scrollPageToBottom.mustache +1 -1
- package/docs/webapi/scrollPageToTop.mustache +1 -1
- package/docs/webapi/scrollTo.mustache +3 -3
- package/docs/webapi/see.mustache +2 -2
- package/docs/webapi/seeAttributesOnElements.mustache +3 -3
- package/docs/webapi/seeCheckboxIsChecked.mustache +2 -1
- package/docs/webapi/seeCookie.mustache +1 -1
- package/docs/webapi/seeCssPropertiesOnElements.mustache +2 -2
- package/docs/webapi/seeCurrentUrlEquals.mustache +1 -1
- package/docs/webapi/seeElement.mustache +1 -1
- package/docs/webapi/seeElementInDOM.mustache +1 -1
- package/docs/webapi/seeInCurrentUrl.mustache +1 -1
- package/docs/webapi/seeInField.mustache +2 -2
- package/docs/webapi/seeInSource.mustache +1 -1
- package/docs/webapi/seeInTitle.mustache +5 -1
- package/docs/webapi/seeNumberOfElements.mustache +10 -0
- package/docs/webapi/seeNumberOfVisibleElements.mustache +2 -2
- package/docs/webapi/selectOption.mustache +2 -2
- package/docs/webapi/setCookie.mustache +1 -1
- package/docs/webapi/switchTo.mustache +6 -1
- package/docs/webapi/uncheckOption.mustache +2 -2
- package/docs/webapi/wait.mustache +1 -2
- package/docs/webapi/waitForDetached.mustache +3 -3
- package/docs/webapi/waitForElement.mustache +2 -2
- package/docs/webapi/waitForEnabled.mustache +1 -1
- package/docs/webapi/waitForFunction.mustache +3 -3
- package/docs/webapi/waitForInvisible.mustache +3 -3
- package/docs/webapi/waitForText.mustache +3 -3
- package/docs/webapi/waitForValue.mustache +3 -3
- package/docs/webapi/waitForVisible.mustache +3 -3
- package/docs/webapi/waitInUrl.mustache +2 -2
- package/docs/webapi/waitNumberOfVisibleElements.mustache +3 -3
- package/docs/webapi/waitToHide.mustache +3 -3
- package/docs/webapi/waitUntil.mustache +3 -3
- package/docs/webapi/waitUrlEquals.mustache +2 -2
- package/docs/webdriver.md +453 -0
- package/lib/codecept.js +11 -9
- package/lib/command/definitions.js +183 -30
- package/lib/command/gherkin/snippets.js +29 -9
- package/lib/command/init.js +31 -9
- package/lib/command/run-multiple.js +46 -59
- package/lib/command/utils.js +1 -1
- package/lib/container.js +30 -4
- package/lib/data/dataScenarioConfig.js +18 -0
- package/lib/helper/Appium.js +24 -24
- package/lib/helper/Nightmare.js +81 -84
- package/lib/helper/Polly.js +189 -0
- package/lib/helper/Protractor.js +96 -86
- package/lib/helper/Puppeteer.js +238 -113
- package/lib/helper/REST.js +1 -1
- package/lib/helper/TestCafe.js +1257 -0
- package/lib/helper/WebDriver.js +217 -277
- package/lib/helper/WebDriverIO.js +75 -75
- package/lib/helper/clientscripts/nightmare.js +8 -0
- package/lib/helper/extras/React.js +55 -0
- package/lib/helper/testcafe/testControllerHolder.js +42 -0
- package/lib/helper/testcafe/testcafe-utils.js +63 -0
- package/lib/history.js +39 -0
- package/lib/hooks.js +25 -1
- package/lib/interfaces/gherkin.js +17 -1
- package/lib/interfaces/scenarioConfig.js +2 -2
- package/lib/listener/config.js +3 -3
- package/lib/locator.js +6 -0
- package/lib/pause.js +22 -1
- package/lib/plugin/allure.js +63 -0
- package/lib/plugin/autoLogin.js +65 -16
- package/lib/plugin/puppeteerCoverage.js +6 -1
- package/lib/plugin/stepByStepReport.js +4 -3
- package/lib/scenario.js +23 -17
- package/lib/step.js +5 -2
- package/lib/ui.js +1 -1
- package/lib/utils.js +70 -20
- package/package.json +20 -19
- package/translations/de-DE.js +69 -0
- package/translations/index.js +1 -0
- package/docs/video.md +0 -26
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
const Helper = require('../helper');
|
|
2
|
+
const requireg = require('requireg');
|
|
3
|
+
const { appendBaseUrl } = require('../utils');
|
|
4
|
+
|
|
5
|
+
let PollyJS;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This helper allows to **mock requests while running tests in Puppeteer**.
|
|
9
|
+
* For instance, you can block calls to 3rd-party services like Google Analytics, CDNs.
|
|
10
|
+
* Another way of using is to emulate requests from server by passing prepared data.
|
|
11
|
+
*
|
|
12
|
+
* ### Installations
|
|
13
|
+
*
|
|
14
|
+
* Requires [Polly.js](https://netflix.github.io/pollyjs/#/) library by Netflix installed
|
|
15
|
+
*
|
|
16
|
+
* ```
|
|
17
|
+
* npm i @pollyjs/core @pollyjs/adapter-puppeteer --save-dev
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Requires Puppeteer helper enabled
|
|
21
|
+
*
|
|
22
|
+
* ### Configuration
|
|
23
|
+
*
|
|
24
|
+
* Just enable helper in config file:
|
|
25
|
+
*
|
|
26
|
+
* ```js
|
|
27
|
+
* helpers: {
|
|
28
|
+
* Puppeteer: {
|
|
29
|
+
* // regular Puppeteer config here
|
|
30
|
+
* },
|
|
31
|
+
* Polly: {}
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* ### Usage
|
|
36
|
+
*
|
|
37
|
+
* Use `I.mockRequest` to intercept and mock requests.
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
class Polly extends Helper {
|
|
41
|
+
constructor(config) {
|
|
42
|
+
super(config);
|
|
43
|
+
this._setConfig(config);
|
|
44
|
+
PollyJS = requireg('@pollyjs/core').Polly;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static _checkRequirements() {
|
|
48
|
+
try {
|
|
49
|
+
requireg('@pollyjs/core');
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return ['@pollyjs/core@^2.5.0'];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async _after() {
|
|
56
|
+
await this.stopMocking();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Start mocking network requests/responses
|
|
60
|
+
async _startMocking(title = 'Test') {
|
|
61
|
+
if (!(this.helpers && this.helpers.Puppeteer)) {
|
|
62
|
+
throw new Error('Puppeteer is the only supported helper right now');
|
|
63
|
+
}
|
|
64
|
+
await this._connectPuppeteer(title);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Connect Puppeteer helper to mock future requests.
|
|
68
|
+
async _connectPuppeteer(title) {
|
|
69
|
+
const adapter = require('@pollyjs/adapter-puppeteer');
|
|
70
|
+
PollyJS.register(adapter);
|
|
71
|
+
|
|
72
|
+
const { page } = this.helpers.Puppeteer;
|
|
73
|
+
if (!page) {
|
|
74
|
+
throw new Error('Looks like, there is no open tab');
|
|
75
|
+
}
|
|
76
|
+
await page.setRequestInterception(true);
|
|
77
|
+
|
|
78
|
+
this.polly = new PollyJS(title, {
|
|
79
|
+
mode: 'passthrough',
|
|
80
|
+
adapters: ['puppeteer'],
|
|
81
|
+
adapterOptions: {
|
|
82
|
+
puppeteer: { page },
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Mock response status
|
|
89
|
+
*
|
|
90
|
+
* ```js
|
|
91
|
+
* I.mockRequest('GET', '/api/users', 200);
|
|
92
|
+
* I.mockRequest('ANY', '/secretsRoutes/*', 403);
|
|
93
|
+
* I.mockRequest('POST', '/secrets', { secrets: 'fakeSecrets' });
|
|
94
|
+
* I.mockRequest('GET', '/api/users/1', 404, 'User not found');
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* Multiple requests
|
|
98
|
+
*
|
|
99
|
+
* ```js
|
|
100
|
+
* I.mockRequest('GET', ['/secrets', '/v2/secrets'], 403);
|
|
101
|
+
* ```
|
|
102
|
+
* @param {string} method request method. Can be `GET`, `POST`, `PUT`, etc or `ANY`.
|
|
103
|
+
* @param {string|array} oneOrMoreUrls url(s) to mock. Can be exact URL, a pattern, or an array of URLs.
|
|
104
|
+
* @param {number|string|object} dataOrStatusCode status code when number provided. A response body otherwise
|
|
105
|
+
* @param {string|object} additionalData response body when a status code is set by previous parameter.
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
async mockRequest(method, oneOrMoreUrls, dataOrStatusCode, additionalData = null) {
|
|
109
|
+
await this._checkAndStartMocking();
|
|
110
|
+
const puppeteerConfigUrl = this.helpers.Puppeteer && this.helpers.Puppeteer.options.url;
|
|
111
|
+
|
|
112
|
+
const handler = this._getRouteHandler(
|
|
113
|
+
method,
|
|
114
|
+
oneOrMoreUrls,
|
|
115
|
+
this.options.url || puppeteerConfigUrl,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
if (typeof dataOrStatusCode === 'number') {
|
|
119
|
+
const statusCode = dataOrStatusCode;
|
|
120
|
+
if (additionalData) {
|
|
121
|
+
return handler.intercept((_, res) => res.status(statusCode).send(additionalData));
|
|
122
|
+
}
|
|
123
|
+
return handler.intercept((_, res) => res.sendStatus(statusCode));
|
|
124
|
+
}
|
|
125
|
+
const data = dataOrStatusCode;
|
|
126
|
+
return handler.intercept((_, res) => res.send(data));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
_checkIfMockingStarted() {
|
|
130
|
+
return this.polly && this.polly.server;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Starts mocking if it's not started yet.
|
|
135
|
+
*/
|
|
136
|
+
async _checkAndStartMocking() {
|
|
137
|
+
if (!this._checkIfMockingStarted()) {
|
|
138
|
+
await this._startMocking();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Get route-handler of Polly for different HTTP methods
|
|
143
|
+
// @param {string} method HTTP request methods(e.g., 'GET', 'POST')
|
|
144
|
+
// @param {string|array} oneOrMoreUrls URL or array of URLs
|
|
145
|
+
// @param {string} baseUrl hostURL
|
|
146
|
+
_getRouteHandler(method, oneOrMoreUrls, baseUrl) {
|
|
147
|
+
const { server } = this.polly;
|
|
148
|
+
|
|
149
|
+
oneOrMoreUrls = appendBaseUrl(baseUrl, oneOrMoreUrls);
|
|
150
|
+
method = method.toLowerCase();
|
|
151
|
+
|
|
152
|
+
if (httpMethods.includes(method)) {
|
|
153
|
+
return server[method](oneOrMoreUrls);
|
|
154
|
+
}
|
|
155
|
+
return server.any(oneOrMoreUrls);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Stops mocking requests.
|
|
160
|
+
*/
|
|
161
|
+
async stopMocking() {
|
|
162
|
+
if (!this._checkIfMockingStarted()) return;
|
|
163
|
+
await this._disconnectPuppeteer();
|
|
164
|
+
|
|
165
|
+
const { polly } = this;
|
|
166
|
+
if (!polly) return;
|
|
167
|
+
await polly.flush();
|
|
168
|
+
await polly.stop();
|
|
169
|
+
delete this.polly;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async _disconnectPuppeteer() {
|
|
173
|
+
const { page } = this.helpers.Puppeteer;
|
|
174
|
+
if (page) await page.setRequestInterception(false);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const httpMethods = [
|
|
179
|
+
'get',
|
|
180
|
+
'put',
|
|
181
|
+
'post',
|
|
182
|
+
'patch',
|
|
183
|
+
'delete',
|
|
184
|
+
'merge',
|
|
185
|
+
'head',
|
|
186
|
+
'options',
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
module.exports = Polly;
|