@wdio/webdriver-mock-service 7.17.0 → 7.18.0
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.d.ts +20 -0
- package/build/WebDriverMock.d.ts.map +1 -0
- package/build/WebDriverMock.js +88 -0
- package/build/constants.d.ts +8 -0
- package/build/constants.d.ts.map +1 -0
- package/build/constants.js +10 -0
- package/build/index.d.ts +30 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +180 -0
- package/build/mocks/newSession.d.ts +29 -0
- package/build/mocks/newSession.d.ts.map +1 -0
- package/build/mocks/newSession.js +31 -0
- package/package.json +5 -5
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import nock from 'nock';
|
|
2
|
+
export interface CommandMock {
|
|
3
|
+
[commandName: string]: (...args: any[]) => nock.Interceptor;
|
|
4
|
+
}
|
|
5
|
+
export default class WebDriverMock {
|
|
6
|
+
path: string;
|
|
7
|
+
command: CommandMock;
|
|
8
|
+
scope: nock.Scope;
|
|
9
|
+
constructor(host?: string, port?: number, path?: string);
|
|
10
|
+
/**
|
|
11
|
+
* To allow random session IDs in url paths we have to set up a custom
|
|
12
|
+
* matcher that strips out the sessionID part from the expected url
|
|
13
|
+
* and actual url and replaces it with a constant session id
|
|
14
|
+
* @param {String} expectedPath path to match against
|
|
15
|
+
* @returns {Function} to be called by Nock to match actual path
|
|
16
|
+
*/
|
|
17
|
+
static pathMatcher(expectedPath: string): (path: string) => boolean;
|
|
18
|
+
get(obj: any, commandName: string): (...args: any[]) => nock.Interceptor;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=WebDriverMock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebDriverMock.d.ts","sourceRoot":"","sources":["../src/WebDriverMock.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAmBvB,MAAM,WAAW,WAAW;IACxB,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,WAAW,CAAA;CAC9D;AAUD,MAAM,CAAC,OAAO,OAAO,aAAa;IAGsC,IAAI,EAAE,MAAM;IAFhF,OAAO,EAAE,WAAW,CAAA;IACpB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAA;gBACL,IAAI,GAAE,MAAoB,EAAE,IAAI,GAAE,MAAa,EAAS,IAAI,GAAE,MAAY;IAKtF;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,CAAC,IAAI,EAAC,MAAM,KAAI,OAAO;IAqBjE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,aAIZ,GAAG,EAAE;CAoC7B"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
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");
|
|
8
|
+
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
|
+
const SESSION_ID = 'XXX';
|
|
10
|
+
const protocols = [
|
|
11
|
+
protocols_1.JsonWProtocol, protocols_1.WebDriverProtocol, protocols_1.MJsonWProtocol, protocols_1.AppiumProtocol,
|
|
12
|
+
protocols_1.ChromiumProtocol, protocols_1.SauceLabsProtocol, protocols_1.SeleniumProtocol
|
|
13
|
+
];
|
|
14
|
+
const protocolFlattened = new Map();
|
|
15
|
+
for (const protocol of protocols) {
|
|
16
|
+
for (const [endpoint, methods] of Object.entries(protocol)) {
|
|
17
|
+
for (const [method, commandData] of Object.entries(methods)) {
|
|
18
|
+
protocolFlattened.set(commandData.command, { method, endpoint, commandData });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
class WebDriverMock {
|
|
23
|
+
constructor(host = 'localhost', port = 4444, path = '/') {
|
|
24
|
+
this.path = path;
|
|
25
|
+
this.scope = (0, nock_1.default)(`http://${host}:${port}`, { 'encodedQueryParams': true });
|
|
26
|
+
this.command = new Proxy({}, { get: this.get.bind(this) });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* To allow random session IDs in url paths we have to set up a custom
|
|
30
|
+
* matcher that strips out the sessionID part from the expected url
|
|
31
|
+
* and actual url and replaces it with a constant session id
|
|
32
|
+
* @param {String} expectedPath path to match against
|
|
33
|
+
* @returns {Function} to be called by Nock to match actual path
|
|
34
|
+
*/
|
|
35
|
+
static pathMatcher(expectedPath) {
|
|
36
|
+
return (path) => {
|
|
37
|
+
const sessionId = path.match(REGEXP_SESSION_ID);
|
|
38
|
+
/**
|
|
39
|
+
* no session ID found so we can check against expected path directly
|
|
40
|
+
*/
|
|
41
|
+
if (!sessionId) {
|
|
42
|
+
return path === expectedPath;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* remove the session ID from expected and actual path
|
|
46
|
+
* to only compare non arbitrary parts
|
|
47
|
+
*/
|
|
48
|
+
expectedPath = expectedPath.replace(':sessionId', SESSION_ID);
|
|
49
|
+
path = path.replace(`${sessionId[0].slice(1)}`, SESSION_ID);
|
|
50
|
+
return path === expectedPath;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
get(obj, commandName) {
|
|
54
|
+
const { method, endpoint, commandData } = protocolFlattened.get(commandName);
|
|
55
|
+
return (...args) => {
|
|
56
|
+
let urlPath = endpoint;
|
|
57
|
+
for (const [i, param] of Object.entries(commandData.variables || [])) {
|
|
58
|
+
urlPath = urlPath.replace(`:${param.name}`, args[parseInt(i)]);
|
|
59
|
+
}
|
|
60
|
+
if (method === 'POST') {
|
|
61
|
+
const reqMethod = method.toLowerCase();
|
|
62
|
+
return this.scope[reqMethod](WebDriverMock.pathMatcher(urlPath), (body) => {
|
|
63
|
+
for (const param of commandData.parameters) {
|
|
64
|
+
/**
|
|
65
|
+
* check if parameter was set
|
|
66
|
+
*/
|
|
67
|
+
if (!body[param.name]) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* check if parameter has correct type
|
|
72
|
+
*/
|
|
73
|
+
if (param.required && typeof body[param.name] === 'undefined') {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* all parameters are valid
|
|
79
|
+
*/
|
|
80
|
+
return true;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const reqMethod = method.toLowerCase();
|
|
84
|
+
return this.scope[reqMethod](WebDriverMock.pathMatcher(urlPath));
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.default = WebDriverMock;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;;;;;CAM3B,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NO_SUCH_ELEMENT = void 0;
|
|
4
|
+
exports.NO_SUCH_ELEMENT = {
|
|
5
|
+
value: {
|
|
6
|
+
error: 'no such element',
|
|
7
|
+
message: 'Unable to locate element: bodys',
|
|
8
|
+
stacktrace: 'WebDriverError@chrome://marionette/content/error.js:179:5\nNoSuchElementError@chrome://marionette/content/error.js:389:5\nelement.find/</<@chrome://marionette/content/element.js:339:16\n'
|
|
9
|
+
}
|
|
10
|
+
};
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Services } from '@wdio/types';
|
|
2
|
+
import type { Browser, MultiRemoteBrowser } from 'webdriverio';
|
|
3
|
+
import WebDriverMock from './WebDriverMock';
|
|
4
|
+
export default class WebdriverMockService implements Services.ServiceInstance {
|
|
5
|
+
private _browser?;
|
|
6
|
+
private _mock;
|
|
7
|
+
constructor();
|
|
8
|
+
init(): void;
|
|
9
|
+
before(caps: unknown, specs: unknown, browser: Browser<'async'> | MultiRemoteBrowser<'async'>): void;
|
|
10
|
+
clickScenario(): void;
|
|
11
|
+
isExistingScenario(): void;
|
|
12
|
+
isNotExistingScenario(): void;
|
|
13
|
+
waitForElementScenario(): void;
|
|
14
|
+
isNeverDisplayedScenario(): void;
|
|
15
|
+
isEventuallyDisplayedScenario(): void;
|
|
16
|
+
staleElementRefetchScenario(): void;
|
|
17
|
+
asyncIterationScenario(): string[];
|
|
18
|
+
parentNextPreviousElementChaining(): void;
|
|
19
|
+
multiremoteFetch(): void;
|
|
20
|
+
customCommandScenario(times?: number): void;
|
|
21
|
+
customSelectorScenario(): void;
|
|
22
|
+
waitForDisplayedScenario(): void;
|
|
23
|
+
cucumberScenario(): void;
|
|
24
|
+
nockReset(): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* export for 3rd party usage
|
|
28
|
+
*/
|
|
29
|
+
export { WebDriverMock };
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,iBAAiB,CAAA;AAW3C,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
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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");
|
|
13
|
+
const ELEMENT_ID = '401c0039-3306-6a46-a98d-f5939870a249';
|
|
14
|
+
const ELEMENT_REFETCHED = '80d860d0-b829-f540-812e-7078eb983795';
|
|
15
|
+
const ELEMENT_ALT = '8bf4d107-a363-40d1-b823-d94bdbc58afb';
|
|
16
|
+
const ELEM_PROP = 'element-6066-11e4-a52e-4f735466cecf';
|
|
17
|
+
class WebdriverMockService {
|
|
18
|
+
constructor() {
|
|
19
|
+
this._mock = new WebDriverMock_1.default();
|
|
20
|
+
this.init();
|
|
21
|
+
}
|
|
22
|
+
init() {
|
|
23
|
+
// define required responses
|
|
24
|
+
this._mock.command.status().times(Infinity).reply(200, { value: {} });
|
|
25
|
+
this._mock.command.newSession().times(Infinity).reply(200, () => {
|
|
26
|
+
newSession_1.newSession.value.sessionId = (0, uuid_1.v4)();
|
|
27
|
+
return newSession_1.newSession;
|
|
28
|
+
});
|
|
29
|
+
this._mock.command.deleteSession().times(2).reply(200, newSession_1.deleteSession);
|
|
30
|
+
this._mock.command.getTitle().times(Infinity).reply(200, { value: 'Mock Page Title' });
|
|
31
|
+
this._mock.command.getUrl().times(Infinity).reply(200, { value: 'https://mymockpage.com' });
|
|
32
|
+
this._mock.command.getElementRect(ELEMENT_ID).times(2).reply(200, { value: { width: 1, height: 2, x: 3, y: 4 } });
|
|
33
|
+
this._mock.command.getElementRect(ELEMENT_ALT).times(3).reply(200, { value: { width: 10, height: 20, x: 30, y: 40 } });
|
|
34
|
+
this._mock.command.getElementRect(ELEMENT_REFETCHED).times(1).reply(200, { value: { width: 1, height: 2, x: 3, y: 4 } });
|
|
35
|
+
this._mock.command.getLogTypes().reply(200, { value: [] });
|
|
36
|
+
}
|
|
37
|
+
before(caps, specs, browser) {
|
|
38
|
+
this._browser = browser;
|
|
39
|
+
/**
|
|
40
|
+
* register request interceptors for specific scenarios
|
|
41
|
+
*/
|
|
42
|
+
this._browser.addCommand('waitForElementScenario', this.waitForElementScenario.bind(this));
|
|
43
|
+
this._browser.addCommand('isNeverDisplayedScenario', this.isNeverDisplayedScenario.bind(this));
|
|
44
|
+
this._browser.addCommand('isEventuallyDisplayedScenario', this.isEventuallyDisplayedScenario.bind(this));
|
|
45
|
+
this._browser.addCommand('staleElementRefetchScenario', this.staleElementRefetchScenario.bind(this));
|
|
46
|
+
this._browser.addCommand('customCommandScenario', this.customCommandScenario.bind(this));
|
|
47
|
+
this._browser.addCommand('customSelectorScenario', this.customSelectorScenario.bind(this));
|
|
48
|
+
this._browser.addCommand('waitForDisplayedScenario', this.waitForDisplayedScenario.bind(this));
|
|
49
|
+
this._browser.addCommand('cucumberScenario', this.cucumberScenario.bind(this));
|
|
50
|
+
this._browser.addCommand('clickScenario', this.clickScenario.bind(this));
|
|
51
|
+
this._browser.addCommand('isExistingScenario', this.isExistingScenario.bind(this));
|
|
52
|
+
this._browser.addCommand('isNotExistingScenario', this.isNotExistingScenario.bind(this));
|
|
53
|
+
this._browser.addCommand('multiremoteFetch', this.multiremoteFetch.bind(this));
|
|
54
|
+
this._browser.addCommand('asyncIterationScenario', this.asyncIterationScenario.bind(this));
|
|
55
|
+
this._browser.addCommand('parentElementChaining', this.parentNextPreviousElementChaining.bind(this));
|
|
56
|
+
}
|
|
57
|
+
clickScenario() {
|
|
58
|
+
this.nockReset();
|
|
59
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
60
|
+
this._mock.command.findElement().times(2).reply(200, { value: elemResponse });
|
|
61
|
+
this._mock.command.elementClick(ELEMENT_ID).once().reply(200, { value: null });
|
|
62
|
+
}
|
|
63
|
+
isExistingScenario() {
|
|
64
|
+
this.nockReset();
|
|
65
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
66
|
+
this._mock.command.findElement().times(1).reply(200, { value: elemResponse });
|
|
67
|
+
this._mock.command.findElementFromElement(ELEMENT_ID).times(2).reply(200, { value: elemResponse });
|
|
68
|
+
this._mock.command.findElementsFromElement(ELEMENT_ID).times(2).reply(200, { value: [elemResponse] });
|
|
69
|
+
}
|
|
70
|
+
isNotExistingScenario() {
|
|
71
|
+
this.nockReset();
|
|
72
|
+
this._mock.command.findElement().reply(404, constants_1.NO_SUCH_ELEMENT);
|
|
73
|
+
}
|
|
74
|
+
waitForElementScenario() {
|
|
75
|
+
this.nockReset();
|
|
76
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
77
|
+
this._mock.command.findElement().once().reply(404, constants_1.NO_SUCH_ELEMENT);
|
|
78
|
+
this._mock.command.findElement().times(2).reply(200, { value: elemResponse });
|
|
79
|
+
this._mock.command.findElements().times(5).reply(200, { value: [] });
|
|
80
|
+
this._mock.command.findElements().reply(200, { value: [elemResponse] });
|
|
81
|
+
this._mock.command.elementClick(ELEMENT_ID).once().reply(200, { value: null });
|
|
82
|
+
}
|
|
83
|
+
isNeverDisplayedScenario() {
|
|
84
|
+
this.nockReset();
|
|
85
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
86
|
+
this._mock.command.findElement().times(2).reply(404, constants_1.NO_SUCH_ELEMENT);
|
|
87
|
+
this._mock.command.findElement().times(2).reply(200, { value: elemResponse });
|
|
88
|
+
this._mock.command.isElementDisplayed(ELEMENT_ID).once().reply(200, { value: true });
|
|
89
|
+
}
|
|
90
|
+
isEventuallyDisplayedScenario() {
|
|
91
|
+
this.nockReset();
|
|
92
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
93
|
+
this._mock.command.findElement().times(1).reply(404, constants_1.NO_SUCH_ELEMENT);
|
|
94
|
+
this._mock.command.findElement().times(2).reply(200, { value: elemResponse });
|
|
95
|
+
this._mock.command.isElementDisplayed(ELEMENT_ID).once().reply(200, { value: true });
|
|
96
|
+
}
|
|
97
|
+
staleElementRefetchScenario() {
|
|
98
|
+
this.nockReset();
|
|
99
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
100
|
+
const elem2Response = { [ELEM_PROP]: ELEMENT_REFETCHED };
|
|
101
|
+
//Found initially
|
|
102
|
+
this._mock.command.findElement().once().reply(200, { value: elemResponse });
|
|
103
|
+
//Initiate refetch, but its not ready
|
|
104
|
+
this._mock.command.findElement().once().reply(404, constants_1.NO_SUCH_ELEMENT);
|
|
105
|
+
//Always return the new element after
|
|
106
|
+
this._mock.command.findElement().times(4).reply(200, { value: elem2Response });
|
|
107
|
+
//First click works
|
|
108
|
+
this._mock.command.elementClick(ELEMENT_ID).once().reply(200, { value: null });
|
|
109
|
+
//Additional clicks won't for the original element
|
|
110
|
+
this._mock.command.elementClick(ELEMENT_ID).times(4).reply(500, {
|
|
111
|
+
value: {
|
|
112
|
+
error: 'stale element reference',
|
|
113
|
+
message: 'element is not attached to the page document'
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
//Clicks on the new element are successful
|
|
117
|
+
this._mock.command.elementClick(ELEMENT_REFETCHED).times(4).reply(200, { value: null });
|
|
118
|
+
//Wait for it to exist - but 2 failed iterations
|
|
119
|
+
this._mock.command.findElements().times(2).reply(200, { value: [] });
|
|
120
|
+
//Always appears thereafter
|
|
121
|
+
this._mock.command.findElements().times(4).reply(200, { value: [elem2Response] });
|
|
122
|
+
}
|
|
123
|
+
asyncIterationScenario() {
|
|
124
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
125
|
+
const elem2Response = { [ELEM_PROP]: ELEMENT_REFETCHED };
|
|
126
|
+
this._mock.command.findElements().reply(200, { value: [elemResponse, elem2Response] });
|
|
127
|
+
return [ELEMENT_ID, ELEMENT_REFETCHED];
|
|
128
|
+
}
|
|
129
|
+
parentNextPreviousElementChaining() {
|
|
130
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
131
|
+
const elemParentResponse = { [ELEM_PROP]: ELEMENT_REFETCHED };
|
|
132
|
+
this._mock.command.findElement().reply(200, { value: elemResponse });
|
|
133
|
+
this._mock.command.executeScript().reply(200, { value: elemParentResponse });
|
|
134
|
+
this._mock.command.getElementText(ELEMENT_REFETCHED).reply(200, { value: 'some element text' });
|
|
135
|
+
}
|
|
136
|
+
multiremoteFetch() {
|
|
137
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
138
|
+
const elem2Response = { [ELEM_PROP]: ELEMENT_REFETCHED };
|
|
139
|
+
this._mock.command.findElement().twice().reply(200, { value: elemResponse });
|
|
140
|
+
this._mock.command.findElementFromElement(ELEMENT_ID).twice().reply(200, { value: elem2Response });
|
|
141
|
+
this._mock.command.elementClick(ELEMENT_REFETCHED).twice().reply(200, { value: null });
|
|
142
|
+
}
|
|
143
|
+
customCommandScenario(times = 1) {
|
|
144
|
+
this.nockReset();
|
|
145
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
146
|
+
const elemAltResponse = { [ELEM_PROP]: ELEMENT_ALT };
|
|
147
|
+
this._mock.command.findElement().times(times).reply(200, { value: elemResponse });
|
|
148
|
+
this._mock.command.findElement().times(times).reply(200, { value: elemAltResponse });
|
|
149
|
+
this._mock.command.executeScript().times(times).reply(200, { value: '2' });
|
|
150
|
+
// overwrite
|
|
151
|
+
this._mock.command.deleteAllCookies().times(times).reply(200, { value: 'deleteAllCookies' });
|
|
152
|
+
}
|
|
153
|
+
customSelectorScenario() {
|
|
154
|
+
this.nockReset();
|
|
155
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
156
|
+
const elemAltResponse = { [ELEM_PROP]: ELEMENT_ALT };
|
|
157
|
+
this._mock.command.findElement().reply(200, { value: elemResponse });
|
|
158
|
+
this._mock.command.executeScript().reply(200, { value: elemAltResponse });
|
|
159
|
+
this._mock.command.findElementFromElement(ELEMENT_ALT).reply(200, { value: elemResponse });
|
|
160
|
+
}
|
|
161
|
+
waitForDisplayedScenario() {
|
|
162
|
+
this.nockReset();
|
|
163
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
164
|
+
this._mock.command.findElement().once().reply(200, { value: elemResponse });
|
|
165
|
+
this._mock.command.isElementDisplayed(ELEMENT_ID).times(4).reply(200, { value: false });
|
|
166
|
+
this._mock.command.isElementDisplayed(ELEMENT_ID).once().reply(200, { value: true });
|
|
167
|
+
}
|
|
168
|
+
cucumberScenario() {
|
|
169
|
+
this.nockReset();
|
|
170
|
+
const elemResponse = { [ELEM_PROP]: ELEMENT_ID };
|
|
171
|
+
this._mock.command.navigateTo().reply(200, { value: null });
|
|
172
|
+
this._mock.command.findElement().times(4).reply(200, { value: elemResponse });
|
|
173
|
+
this._mock.command.elementClick(ELEMENT_ID).reply(200, { value: null });
|
|
174
|
+
}
|
|
175
|
+
nockReset() {
|
|
176
|
+
nock_1.default.cleanAll();
|
|
177
|
+
this.init();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.default = WebdriverMockService;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const newSession: {
|
|
2
|
+
value: {
|
|
3
|
+
sessionId: string;
|
|
4
|
+
capabilities: {
|
|
5
|
+
acceptInsecureCerts: boolean;
|
|
6
|
+
browserName: string;
|
|
7
|
+
browserVersion: number;
|
|
8
|
+
pageLoadStrategy: string;
|
|
9
|
+
platformName: string;
|
|
10
|
+
platformVersion: string;
|
|
11
|
+
rotatable: boolean;
|
|
12
|
+
setWindowRect: boolean;
|
|
13
|
+
timeouts: {}[];
|
|
14
|
+
unhandledPromptBehavior: string;
|
|
15
|
+
'moz:accessibilityChecks': boolean;
|
|
16
|
+
'moz:geckodriverVersion': string;
|
|
17
|
+
'moz:headless': boolean;
|
|
18
|
+
'moz:processID': number;
|
|
19
|
+
'moz:profile': string;
|
|
20
|
+
'moz:shutdownTimeout': number;
|
|
21
|
+
'moz:useNonSpecCompliantPointerOrigin': boolean;
|
|
22
|
+
'moz:webdriverClick': boolean;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export declare const deleteSession: {
|
|
27
|
+
value: null;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=newSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newSession.d.ts","sourceRoot":"","sources":["../../src/mocks/newSession.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;CAwBtB,CAAA;AAED,eAAO,MAAM,aAAa;;CAEzB,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteSession = exports.newSession = void 0;
|
|
4
|
+
exports.newSession = {
|
|
5
|
+
value: {
|
|
6
|
+
sessionId: 'undefined',
|
|
7
|
+
capabilities: {
|
|
8
|
+
acceptInsecureCerts: false,
|
|
9
|
+
browserName: 'firefox',
|
|
10
|
+
browserVersion: 64.0,
|
|
11
|
+
pageLoadStrategy: 'normal',
|
|
12
|
+
platformName: 'mac',
|
|
13
|
+
platformVersion: '17.7.0',
|
|
14
|
+
rotatable: false,
|
|
15
|
+
setWindowRect: true,
|
|
16
|
+
timeouts: [{}],
|
|
17
|
+
unhandledPromptBehavior: 'dismiss and notify',
|
|
18
|
+
'moz:accessibilityChecks': false,
|
|
19
|
+
'moz:geckodriverVersion': '0.23.0',
|
|
20
|
+
'moz:headless': false,
|
|
21
|
+
'moz:processID': 15867,
|
|
22
|
+
'moz:profile': '/var/folders/ns/8mj2mh0x27b_gsdddy1knnsm0000gn/T/rust_mozprofile.yUuH0ktcRJPN',
|
|
23
|
+
'moz:shutdownTimeout': 60000,
|
|
24
|
+
'moz:useNonSpecCompliantPointerOrigin': false,
|
|
25
|
+
'moz:webdriverClick': true
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.deleteSession = {
|
|
30
|
+
value: null
|
|
31
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdio/webdriver-mock-service",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.18.0",
|
|
4
4
|
"description": "A WebdriverIO service to stub all endpoints for internal testing purposes.",
|
|
5
5
|
"author": "Christian Bromann <christian@saucelabs.com>",
|
|
6
6
|
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-webdriver-mock-service",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@types/uuid": "^8.3.0",
|
|
22
|
-
"@wdio/protocols": "7.
|
|
23
|
-
"@wdio/types": "7.
|
|
22
|
+
"@wdio/protocols": "7.17.3",
|
|
23
|
+
"@wdio/types": "7.18.0",
|
|
24
24
|
"nock": "^13.0.0",
|
|
25
25
|
"uuid": "^8.0.0",
|
|
26
|
-
"webdriverio": "7.
|
|
26
|
+
"webdriverio": "7.18.0"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"types": "./build/index.d.ts",
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "44729cdd585af3ad69f2093f32377f297f5ac344"
|
|
33
33
|
}
|