@wdio/webdriver-mock-service 7.20.9 → 8.0.0-alpha.213
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/build/WebDriverMock.js +6 -12
- package/build/constants.js +1 -4
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +20 -24
- package/build/mocks/newSession.js +2 -5
- package/package.json +13 -11
package/build/WebDriverMock.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const nock_1 = __importDefault(require("nock"));
|
|
7
|
-
const protocols_1 = require("@wdio/protocols");
|
|
1
|
+
import nock from 'nock';
|
|
2
|
+
import { WebDriverProtocol, MJsonWProtocol, JsonWProtocol, AppiumProtocol, ChromiumProtocol, SauceLabsProtocol, SeleniumProtocol } from '@wdio/protocols';
|
|
8
3
|
const REGEXP_SESSION_ID = /\/[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}/;
|
|
9
4
|
const SESSION_ID = 'XXX';
|
|
10
5
|
const protocols = [
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
JsonWProtocol, WebDriverProtocol, MJsonWProtocol, AppiumProtocol,
|
|
7
|
+
ChromiumProtocol, SauceLabsProtocol, SeleniumProtocol
|
|
13
8
|
];
|
|
14
9
|
const protocolFlattened = new Map();
|
|
15
10
|
for (const protocol of protocols) {
|
|
@@ -19,10 +14,10 @@ for (const protocol of protocols) {
|
|
|
19
14
|
}
|
|
20
15
|
}
|
|
21
16
|
}
|
|
22
|
-
class WebDriverMock {
|
|
17
|
+
export default class WebDriverMock {
|
|
23
18
|
constructor(host = 'localhost', port = 4444, path = '/') {
|
|
24
19
|
this.path = path;
|
|
25
|
-
this.scope = (
|
|
20
|
+
this.scope = nock(`http://${host}:${port}`, { 'encodedQueryParams': true });
|
|
26
21
|
this.command = new Proxy({}, { get: this.get.bind(this) });
|
|
27
22
|
}
|
|
28
23
|
/**
|
|
@@ -85,4 +80,3 @@ class WebDriverMock {
|
|
|
85
80
|
};
|
|
86
81
|
}
|
|
87
82
|
}
|
|
88
|
-
exports.default = WebDriverMock;
|
package/build/constants.js
CHANGED
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Services } from '@wdio/types';
|
|
2
2
|
import type { Browser, MultiRemoteBrowser } from 'webdriverio';
|
|
3
|
-
import WebDriverMock from './WebDriverMock';
|
|
3
|
+
import WebDriverMock from './WebDriverMock.js';
|
|
4
4
|
export default class WebdriverMockService implements Services.ServiceInstance {
|
|
5
5
|
private _browser?;
|
|
6
6
|
private _mock;
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAE9D,OAAO,aAAa,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAE9D,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAW9C,MAAM,CAAC,OAAO,OAAO,oBAAqB,YAAW,QAAQ,CAAC,eAAe;IACzE,OAAO,CAAC,QAAQ,CAAC,CAAgD;IACjE,OAAO,CAAC,KAAK,CAAsB;;IAMnC,IAAI;IAgBJ,MAAM,CACF,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC;IAuB3D,aAAa;IAQb,kBAAkB;IASlB,qBAAqB;IAKrB,sBAAsB;IAYtB,wBAAwB;IAUxB,6BAA6B;IAU7B,2BAA2B;IA+B3B,sBAAsB;IAOtB,iCAAiC;IAQjC,gBAAgB;IAShB,qBAAqB,CAAC,KAAK,SAAI;IAa/B,sBAAsB;IAUtB,wBAAwB;IASxB,gBAAgB;IAShB,SAAS;CAIZ;AAED;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,32 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.WebDriverMock = void 0;
|
|
7
|
-
const nock_1 = __importDefault(require("nock"));
|
|
8
|
-
const uuid_1 = require("uuid");
|
|
9
|
-
const WebDriverMock_1 = __importDefault(require("./WebDriverMock"));
|
|
10
|
-
exports.WebDriverMock = WebDriverMock_1.default;
|
|
11
|
-
const constants_1 = require("./constants");
|
|
12
|
-
const newSession_1 = require("./mocks/newSession");
|
|
1
|
+
import nock from 'nock';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import WebDriverMock from './WebDriverMock.js';
|
|
4
|
+
import { NO_SUCH_ELEMENT } from './constants.js';
|
|
5
|
+
import { newSession, deleteSession } from './mocks/newSession.js';
|
|
13
6
|
const ELEMENT_ID = '401c0039-3306-6a46-a98d-f5939870a249';
|
|
14
7
|
const ELEMENT_REFETCHED = '80d860d0-b829-f540-812e-7078eb983795';
|
|
15
8
|
const ELEMENT_ALT = '8bf4d107-a363-40d1-b823-d94bdbc58afb';
|
|
16
9
|
const ELEM_PROP = 'element-6066-11e4-a52e-4f735466cecf';
|
|
17
|
-
class WebdriverMockService {
|
|
10
|
+
export default class WebdriverMockService {
|
|
18
11
|
constructor() {
|
|
19
|
-
this._mock = new
|
|
12
|
+
this._mock = new WebDriverMock();
|
|
20
13
|
this.init();
|
|
21
14
|
}
|
|
22
15
|
init() {
|
|
23
16
|
// define required responses
|
|
24
17
|
this._mock.command.status().times(Infinity).reply(200, { value: {} });
|
|
25
18
|
this._mock.command.newSession().times(Infinity).reply(200, () => {
|
|
26
|
-
|
|
27
|
-
return
|
|
19
|
+
newSession.value.sessionId = uuidv4();
|
|
20
|
+
return newSession;
|
|
28
21
|
});
|
|
29
|
-
this._mock.command.deleteSession().times(2).reply(200,
|
|
22
|
+
this._mock.command.deleteSession().times(2).reply(200, deleteSession);
|
|
30
23
|
this._mock.command.getTitle().times(Infinity).reply(200, { value: 'Mock Page Title' });
|
|
31
24
|
this._mock.command.getUrl().times(Infinity).reply(200, { value: 'https://mymockpage.com' });
|
|
32
25
|
this._mock.command.getElementRect(ELEMENT_ID).times(2).reply(200, { value: { width: 1, height: 2, x: 3, y: 4 } });
|
|
@@ -69,12 +62,12 @@ class WebdriverMockService {
|
|
|
69
62
|
}
|
|
70
63
|
isNotExistingScenario() {
|
|
71
64
|
this.nockReset();
|
|
72
|
-
this._mock.command.findElement().reply(404,
|
|
65
|
+
this._mock.command.findElement().reply(404, NO_SUCH_ELEMENT);
|
|
73
66
|
}
|
|
74
67
|
waitForElementScenario() {
|
|
75
68
|
this.nockReset();
|
|
76
69
|
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
77
|
-
this._mock.command.findElement().once().reply(404,
|
|
70
|
+
this._mock.command.findElement().once().reply(404, NO_SUCH_ELEMENT);
|
|
78
71
|
this._mock.command.findElement().times(2).reply(200, { value: elemResponse });
|
|
79
72
|
this._mock.command.findElements().times(5).reply(200, { value: [] });
|
|
80
73
|
this._mock.command.findElements().reply(200, { value: [elemResponse] });
|
|
@@ -83,14 +76,14 @@ class WebdriverMockService {
|
|
|
83
76
|
isNeverDisplayedScenario() {
|
|
84
77
|
this.nockReset();
|
|
85
78
|
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
86
|
-
this._mock.command.findElement().times(2).reply(404,
|
|
79
|
+
this._mock.command.findElement().times(2).reply(404, NO_SUCH_ELEMENT);
|
|
87
80
|
this._mock.command.findElement().times(2).reply(200, { value: elemResponse });
|
|
88
81
|
this._mock.command.isElementDisplayed(ELEMENT_ID).once().reply(200, { value: true });
|
|
89
82
|
}
|
|
90
83
|
isEventuallyDisplayedScenario() {
|
|
91
84
|
this.nockReset();
|
|
92
85
|
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
93
|
-
this._mock.command.findElement().times(1).reply(404,
|
|
86
|
+
this._mock.command.findElement().times(1).reply(404, NO_SUCH_ELEMENT);
|
|
94
87
|
this._mock.command.findElement().times(2).reply(200, { value: elemResponse });
|
|
95
88
|
this._mock.command.isElementDisplayed(ELEMENT_ID).once().reply(200, { value: true });
|
|
96
89
|
}
|
|
@@ -101,7 +94,7 @@ class WebdriverMockService {
|
|
|
101
94
|
//Found initially
|
|
102
95
|
this._mock.command.findElement().once().reply(200, { value: elemResponse });
|
|
103
96
|
//Initiate refetch, but its not ready
|
|
104
|
-
this._mock.command.findElement().once().reply(404,
|
|
97
|
+
this._mock.command.findElement().once().reply(404, NO_SUCH_ELEMENT);
|
|
105
98
|
//Always return the new element after
|
|
106
99
|
this._mock.command.findElement().times(4).reply(200, { value: elem2Response });
|
|
107
100
|
//First click works
|
|
@@ -173,8 +166,11 @@ class WebdriverMockService {
|
|
|
173
166
|
this._mock.command.elementClick(ELEMENT_ID).reply(200, { value: null });
|
|
174
167
|
}
|
|
175
168
|
nockReset() {
|
|
176
|
-
|
|
169
|
+
nock.cleanAll();
|
|
177
170
|
this.init();
|
|
178
171
|
}
|
|
179
172
|
}
|
|
180
|
-
|
|
173
|
+
/**
|
|
174
|
+
* export for 3rd party usage
|
|
175
|
+
*/
|
|
176
|
+
export { WebDriverMock };
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteSession = exports.newSession = void 0;
|
|
4
|
-
exports.newSession = {
|
|
1
|
+
export const newSession = {
|
|
5
2
|
value: {
|
|
6
3
|
sessionId: 'undefined',
|
|
7
4
|
capabilities: {
|
|
@@ -26,6 +23,6 @@ exports.newSession = {
|
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
};
|
|
29
|
-
|
|
26
|
+
export const deleteSession = {
|
|
30
27
|
value: null
|
|
31
28
|
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdio/webdriver-mock-service",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-alpha.213+c5fb6d57e",
|
|
4
4
|
"description": "A WebdriverIO service to stub all endpoints for internal testing purposes.",
|
|
5
5
|
"author": "Christian Bromann <mail@bromann.dev>",
|
|
6
6
|
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-webdriver-mock-service",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"main": "./build/index",
|
|
9
8
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
9
|
+
"node": "^16.13 || >=18"
|
|
11
10
|
},
|
|
12
11
|
"repository": {
|
|
13
12
|
"type": "git",
|
|
@@ -17,17 +16,20 @@
|
|
|
17
16
|
"bugs": {
|
|
18
17
|
"url": "https://github.com/webdriverio/webdriverio/issues"
|
|
19
18
|
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": "./build/index.js",
|
|
21
|
+
"types": "./build/index.d.ts",
|
|
22
|
+
"typeScriptVersion": "3.8.3",
|
|
20
23
|
"dependencies": {
|
|
21
|
-
"@types/uuid": "^8.3.
|
|
22
|
-
"@wdio/protocols": "
|
|
23
|
-
"@wdio/types": "
|
|
24
|
-
"nock": "^13.
|
|
25
|
-
"uuid": "^8.
|
|
26
|
-
"webdriverio": "
|
|
24
|
+
"@types/uuid": "^8.3.4",
|
|
25
|
+
"@wdio/protocols": "8.0.0-alpha.213+c5fb6d57e",
|
|
26
|
+
"@wdio/types": "8.0.0-alpha.213+c5fb6d57e",
|
|
27
|
+
"nock": "^13.2.4",
|
|
28
|
+
"uuid": "^8.3.2",
|
|
29
|
+
"webdriverio": "8.0.0-alpha.213+c5fb6d57e"
|
|
27
30
|
},
|
|
28
31
|
"publishConfig": {
|
|
29
32
|
"access": "public"
|
|
30
33
|
},
|
|
31
|
-
"
|
|
32
|
-
"gitHead": "4de5ffd553e64ac129980cbb0a374d061f884fa7"
|
|
34
|
+
"gitHead": "c5fb6d57e168d8bf939a5aa5c2ada5abaceec5eb"
|
|
33
35
|
}
|