@applitools/spec-driver-browser-extension 1.0.7 → 1.0.9
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 +61 -0
- package/dist/spec-driver.js +53 -55
- package/package.json +5 -4
- package/types/spec-driver.d.ts +26 -47
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,66 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.9](https://github.com/applitools/eyes.sdk.javascript1/compare/js/spec-driver-browser-extension@1.0.8...js/spec-driver-browser-extension@1.0.9) (2023-08-30)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Dependencies
|
|
7
|
+
|
|
8
|
+
* @applitools/utils bumped to 1.5.2
|
|
9
|
+
#### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* fixed some types ([498b1d7](https://github.com/applitools/eyes.sdk.javascript1/commit/498b1d7c547df04773b64b66ee39cccb402c093e))
|
|
12
|
+
* @applitools/logger bumped to 2.0.9
|
|
13
|
+
|
|
14
|
+
* @applitools/spec-driver-playwright bumped to 1.3.24
|
|
15
|
+
|
|
16
|
+
* @applitools/driver bumped to 1.13.6
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## [1.0.8](https://github.com/applitools/eyes.sdk.javascript1/compare/js/spec-driver-browser-extension@1.0.7...js/spec-driver-browser-extension@1.0.8) (2023-08-18)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Code Refactoring
|
|
23
|
+
|
|
24
|
+
* refactored spec driver interface ([#1839](https://github.com/applitools/eyes.sdk.javascript1/issues/1839)) ([aa49ec2](https://github.com/applitools/eyes.sdk.javascript1/commit/aa49ec2a7d14b8529acc3a8a4c2baecfa113d98a))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Dependencies
|
|
28
|
+
|
|
29
|
+
* @applitools/utils bumped to 1.5.1
|
|
30
|
+
#### Code Refactoring
|
|
31
|
+
|
|
32
|
+
* refactored spec driver interface ([#1839](https://github.com/applitools/eyes.sdk.javascript1/issues/1839)) ([aa49ec2](https://github.com/applitools/eyes.sdk.javascript1/commit/aa49ec2a7d14b8529acc3a8a4c2baecfa113d98a))
|
|
33
|
+
* @applitools/logger bumped to 2.0.8
|
|
34
|
+
#### Code Refactoring
|
|
35
|
+
|
|
36
|
+
* refactored spec driver interface ([#1839](https://github.com/applitools/eyes.sdk.javascript1/issues/1839)) ([aa49ec2](https://github.com/applitools/eyes.sdk.javascript1/commit/aa49ec2a7d14b8529acc3a8a4c2baecfa113d98a))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
* @applitools/snippets bumped to 2.4.23
|
|
41
|
+
#### Code Refactoring
|
|
42
|
+
|
|
43
|
+
* refactored spec driver interface ([#1839](https://github.com/applitools/eyes.sdk.javascript1/issues/1839)) ([aa49ec2](https://github.com/applitools/eyes.sdk.javascript1/commit/aa49ec2a7d14b8529acc3a8a4c2baecfa113d98a))
|
|
44
|
+
* @applitools/spec-driver-playwright bumped to 1.3.23
|
|
45
|
+
#### Code Refactoring
|
|
46
|
+
|
|
47
|
+
* refactored spec driver interface ([#1839](https://github.com/applitools/eyes.sdk.javascript1/issues/1839)) ([aa49ec2](https://github.com/applitools/eyes.sdk.javascript1/commit/aa49ec2a7d14b8529acc3a8a4c2baecfa113d98a))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
* @applitools/driver bumped to 1.13.5
|
|
52
|
+
#### Bug Fixes
|
|
53
|
+
|
|
54
|
+
* optimize driver usage in close ([#1867](https://github.com/applitools/eyes.sdk.javascript1/issues/1867)) ([60dff6b](https://github.com/applitools/eyes.sdk.javascript1/commit/60dff6b160e69d3893c91a1125d668fa18b43072))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
#### Code Refactoring
|
|
58
|
+
|
|
59
|
+
* refactored spec driver interface ([#1839](https://github.com/applitools/eyes.sdk.javascript1/issues/1839)) ([aa49ec2](https://github.com/applitools/eyes.sdk.javascript1/commit/aa49ec2a7d14b8529acc3a8a4c2baecfa113d98a))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
3
64
|
## [1.0.7](https://github.com/applitools/eyes.sdk.javascript1/compare/js/spec-driver-browser-extension@1.0.6...js/spec-driver-browser-extension@1.0.7) (2023-08-10)
|
|
4
65
|
|
|
5
66
|
|
package/dist/spec-driver.js
CHANGED
|
@@ -26,10 +26,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
const utils = __importStar(require("@applitools/utils"));
|
|
29
|
+
exports.getUrl = exports.getTitle = exports.takeScreenshot = exports.getCookies = exports.setWindowSize = exports.getWindowSize = exports.getDriverInfo = exports.childContext = exports.parentContext = exports.mainContext = exports.findElements = exports.findElement = exports.executeScript = exports.extractContext = exports.toSelector = exports.isStaleElementError = exports.isSelector = exports.isElement = exports.isContext = exports.isDriver = void 0;
|
|
31
30
|
const webextension_polyfill_1 = __importDefault(require("webextension-polyfill"));
|
|
32
|
-
|
|
31
|
+
const utils = __importStar(require("@applitools/utils"));
|
|
33
32
|
function isDriver(driver) {
|
|
34
33
|
return utils.types.has(driver, ['windowId', 'tabId']);
|
|
35
34
|
}
|
|
@@ -46,32 +45,32 @@ function isSelector(selector) {
|
|
|
46
45
|
return utils.types.has(selector, ['type', 'selector']);
|
|
47
46
|
}
|
|
48
47
|
exports.isSelector = isSelector;
|
|
49
|
-
function
|
|
48
|
+
function isStaleElementError(error) {
|
|
49
|
+
if (!error)
|
|
50
|
+
return false;
|
|
51
|
+
error = error.originalError || error;
|
|
52
|
+
return error instanceof Error && error.message === 'StaleElementReferenceError';
|
|
53
|
+
}
|
|
54
|
+
exports.isStaleElementError = isStaleElementError;
|
|
55
|
+
function toSelector(selector) {
|
|
50
56
|
if (utils.types.isString(selector)) {
|
|
51
57
|
return { type: 'css', selector: selector };
|
|
52
58
|
}
|
|
53
59
|
else if (utils.types.has(selector, 'selector')) {
|
|
54
60
|
if (!utils.types.isString(selector.selector))
|
|
55
61
|
return selector.selector;
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
return {
|
|
63
|
+
type: utils.types.has(selector, 'type') ? selector.type : 'css',
|
|
64
|
+
selector: selector.selector,
|
|
65
|
+
};
|
|
58
66
|
}
|
|
59
67
|
return selector;
|
|
60
68
|
}
|
|
61
|
-
exports.
|
|
69
|
+
exports.toSelector = toSelector;
|
|
62
70
|
function extractContext(driver) {
|
|
63
71
|
return { ...driver, frameId: 0 };
|
|
64
72
|
}
|
|
65
73
|
exports.extractContext = extractContext;
|
|
66
|
-
function isStaleElementError(error) {
|
|
67
|
-
if (!error)
|
|
68
|
-
return false;
|
|
69
|
-
error = error.originalError || error;
|
|
70
|
-
return error instanceof Error && error.message === 'StaleElementReferenceError';
|
|
71
|
-
}
|
|
72
|
-
exports.isStaleElementError = isStaleElementError;
|
|
73
|
-
// #endregion
|
|
74
|
-
// #region COMMANDS
|
|
75
74
|
async function executeScript(context, script, arg) {
|
|
76
75
|
const [{ result, error }] = await webextension_polyfill_1.default.scripting.executeScript({
|
|
77
76
|
target: { tabId: context.tabId, frameIds: [context.frameId || 0] },
|
|
@@ -86,38 +85,6 @@ async function executeScript(context, script, arg) {
|
|
|
86
85
|
return result;
|
|
87
86
|
}
|
|
88
87
|
exports.executeScript = executeScript;
|
|
89
|
-
async function mainContext(context) {
|
|
90
|
-
return { ...context, frameId: 0 };
|
|
91
|
-
}
|
|
92
|
-
exports.mainContext = mainContext;
|
|
93
|
-
async function parentContext(context) {
|
|
94
|
-
const frames = await webextension_polyfill_1.default.webNavigation.getAllFrames({ tabId: context.tabId });
|
|
95
|
-
const frame = frames.find(frame => frame.frameId === context.frameId);
|
|
96
|
-
return { ...context, frameId: frame === null || frame === void 0 ? void 0 : frame.parentFrameId };
|
|
97
|
-
}
|
|
98
|
-
exports.parentContext = parentContext;
|
|
99
|
-
async function childContext(context, element) {
|
|
100
|
-
const childFrameId = await new Promise(async (resolve, reject) => {
|
|
101
|
-
const key = utils.general.guid();
|
|
102
|
-
webextension_polyfill_1.default.runtime.onMessage.addListener(handler);
|
|
103
|
-
function handler(data, sender) {
|
|
104
|
-
if (data.key === key) {
|
|
105
|
-
resolve(sender.frameId);
|
|
106
|
-
webextension_polyfill_1.default.runtime.onMessage.removeListener(handler);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
await webextension_polyfill_1.default.scripting.executeScript({
|
|
110
|
-
target: { tabId: context.tabId, frameIds: [context.frameId || 0] },
|
|
111
|
-
func: (element, key) => {
|
|
112
|
-
window.refer.deref(element).contentWindow.postMessage({ key, isApplitools: true }, '*'); // eslint-disable-line no-undef
|
|
113
|
-
},
|
|
114
|
-
args: [element, key],
|
|
115
|
-
});
|
|
116
|
-
setTimeout(() => reject(new Error('No such frame')), 5000);
|
|
117
|
-
});
|
|
118
|
-
return { ...context, frameId: childFrameId };
|
|
119
|
-
}
|
|
120
|
-
exports.childContext = childContext;
|
|
121
88
|
async function findElement(context, selector, parent) {
|
|
122
89
|
const [{ result }] = await webextension_polyfill_1.default.scripting.executeScript({
|
|
123
90
|
target: { tabId: context.tabId, frameIds: [context.frameId || 0] },
|
|
@@ -161,6 +128,42 @@ async function findElements(context, selector, parent) {
|
|
|
161
128
|
return result;
|
|
162
129
|
}
|
|
163
130
|
exports.findElements = findElements;
|
|
131
|
+
async function mainContext(context) {
|
|
132
|
+
return { ...context, frameId: 0 };
|
|
133
|
+
}
|
|
134
|
+
exports.mainContext = mainContext;
|
|
135
|
+
async function parentContext(context) {
|
|
136
|
+
const frames = await webextension_polyfill_1.default.webNavigation.getAllFrames({ tabId: context.tabId });
|
|
137
|
+
const frame = frames.find(frame => frame.frameId === context.frameId);
|
|
138
|
+
return { ...context, frameId: frame.parentFrameId };
|
|
139
|
+
}
|
|
140
|
+
exports.parentContext = parentContext;
|
|
141
|
+
async function childContext(context, element) {
|
|
142
|
+
const childFrameId = await new Promise(async (resolve, reject) => {
|
|
143
|
+
const key = utils.general.guid();
|
|
144
|
+
webextension_polyfill_1.default.runtime.onMessage.addListener(handler);
|
|
145
|
+
function handler(data, sender) {
|
|
146
|
+
if (data.key === key) {
|
|
147
|
+
resolve(sender.frameId);
|
|
148
|
+
webextension_polyfill_1.default.runtime.onMessage.removeListener(handler);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
await webextension_polyfill_1.default.scripting.executeScript({
|
|
152
|
+
target: { tabId: context.tabId, frameIds: [context.frameId || 0] },
|
|
153
|
+
func: (element, key) => {
|
|
154
|
+
window.refer.deref(element).contentWindow.postMessage({ key, isApplitools: true }, '*'); // eslint-disable-line no-undef
|
|
155
|
+
},
|
|
156
|
+
args: [element, key],
|
|
157
|
+
});
|
|
158
|
+
setTimeout(() => reject(new Error('No such frame')), 5000);
|
|
159
|
+
});
|
|
160
|
+
return { ...context, frameId: childFrameId };
|
|
161
|
+
}
|
|
162
|
+
exports.childContext = childContext;
|
|
163
|
+
async function getDriverInfo() {
|
|
164
|
+
return { features: { canExecuteOnlyFunctionScripts: true } };
|
|
165
|
+
}
|
|
166
|
+
exports.getDriverInfo = getDriverInfo;
|
|
164
167
|
async function getWindowSize(driver) {
|
|
165
168
|
const [{ result }] = await webextension_polyfill_1.default.scripting.executeScript({
|
|
166
169
|
target: { tabId: driver.tabId, frameIds: [0] },
|
|
@@ -208,16 +211,11 @@ async function takeScreenshot(driver) {
|
|
|
208
211
|
exports.takeScreenshot = takeScreenshot;
|
|
209
212
|
async function getTitle(driver) {
|
|
210
213
|
const { title } = await webextension_polyfill_1.default.tabs.get(driver.tabId);
|
|
211
|
-
return title;
|
|
214
|
+
return title || '';
|
|
212
215
|
}
|
|
213
216
|
exports.getTitle = getTitle;
|
|
214
217
|
async function getUrl(driver) {
|
|
215
218
|
const { url } = await webextension_polyfill_1.default.tabs.get(driver.tabId);
|
|
216
|
-
return url;
|
|
219
|
+
return url || '';
|
|
217
220
|
}
|
|
218
221
|
exports.getUrl = getUrl;
|
|
219
|
-
async function getDriverInfo() {
|
|
220
|
-
return { features: { canExecuteOnlyFunctionScripts: true } };
|
|
221
|
-
}
|
|
222
|
-
exports.getDriverInfo = getDriverInfo;
|
|
223
|
-
// #endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applitools/spec-driver-browser-extension",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"playwright",
|
|
6
6
|
"chrome devtools protocol",
|
|
@@ -39,12 +39,13 @@
|
|
|
39
39
|
"setup": "run --top-level xvfb:setup"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@applitools/
|
|
42
|
+
"@applitools/driver": "1.13.6",
|
|
43
|
+
"@applitools/utils": "1.5.2",
|
|
43
44
|
"webextension-polyfill": "0.10.0"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@applitools/api-extractor": "^1.2.21",
|
|
47
|
-
"@applitools/spec-driver-playwright": "^1.3.
|
|
48
|
+
"@applitools/spec-driver-playwright": "^1.3.24",
|
|
48
49
|
"@applitools/test-utils": "^1.5.17",
|
|
49
50
|
"@babel/core": "^7.22.5",
|
|
50
51
|
"@babel/preset-env": "^7.22.5",
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"babel-loader": "^9.1.2",
|
|
56
57
|
"copy-webpack-plugin": "^11.0.0",
|
|
57
58
|
"core-js": "^3.31.0",
|
|
58
|
-
"playwright": "^1.
|
|
59
|
+
"playwright": "^1.37.0",
|
|
59
60
|
"webpack": "^5.75.0",
|
|
60
61
|
"webpack-cli": "^5.0.1"
|
|
61
62
|
},
|
package/types/spec-driver.d.ts
CHANGED
|
@@ -1,65 +1,44 @@
|
|
|
1
1
|
import type { Size } from '@applitools/utils';
|
|
2
|
+
import type { SpecType, SpecDriver as BaseSpecDriver, CommonSelector, DriverInfo, Cookie } from '@applitools/driver';
|
|
2
3
|
import type { Ref } from './refer';
|
|
3
|
-
type
|
|
4
|
-
selector: TSelector | string;
|
|
5
|
-
type?: string;
|
|
6
|
-
};
|
|
7
|
-
type Driver = {
|
|
4
|
+
export type Driver = {
|
|
8
5
|
windowId: number;
|
|
9
6
|
tabId: number;
|
|
10
7
|
};
|
|
11
|
-
type Context = {
|
|
8
|
+
export type Context = {
|
|
12
9
|
windowId: number;
|
|
13
10
|
tabId: number;
|
|
14
11
|
frameId: number;
|
|
15
12
|
};
|
|
16
|
-
type Element =
|
|
13
|
+
export type Element = Ref;
|
|
14
|
+
export type Selector = {
|
|
15
|
+
type: 'css' | 'xpath';
|
|
16
|
+
selector: string;
|
|
17
|
+
};
|
|
18
|
+
export type PrimarySpecType = SpecType<Driver, Context, Element, Selector>;
|
|
19
|
+
export type SpecDriver = BaseSpecDriver<PrimarySpecType>;
|
|
17
20
|
declare global {
|
|
18
21
|
interface Window {
|
|
19
22
|
refer: any;
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
|
-
export declare function isDriver(driver: any):
|
|
23
|
-
export declare function isContext(context: any):
|
|
24
|
-
export declare function isElement(element: any):
|
|
25
|
-
export declare function isSelector(selector: any):
|
|
26
|
-
export declare function transformSelector(selector: CommonSelector): {
|
|
27
|
-
selector: string;
|
|
28
|
-
type?: string | undefined;
|
|
29
|
-
} & Record<"type", unknown>;
|
|
30
|
-
export declare function extractContext(driver: Driver): {
|
|
31
|
-
frameId: number;
|
|
32
|
-
windowId: number;
|
|
33
|
-
tabId: number;
|
|
34
|
-
};
|
|
25
|
+
export declare function isDriver(driver: any): driver is Driver;
|
|
26
|
+
export declare function isContext(context: any): context is Context;
|
|
27
|
+
export declare function isElement(element: any): element is Element;
|
|
28
|
+
export declare function isSelector(selector: any): selector is Selector;
|
|
35
29
|
export declare function isStaleElementError(error: any): boolean;
|
|
36
|
-
export declare function
|
|
37
|
-
export declare function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export declare function parentContext(context: Context): Promise<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
tabId: number;
|
|
46
|
-
}>;
|
|
47
|
-
export declare function childContext(context: Context, element: Element): Promise<{
|
|
48
|
-
frameId: unknown;
|
|
49
|
-
windowId: number;
|
|
50
|
-
tabId: number;
|
|
51
|
-
}>;
|
|
52
|
-
export declare function findElement(context: Context, selector: CommonSelector, parent?: Element | Node): Promise<any>;
|
|
53
|
-
export declare function findElements(context: Context, selector: CommonSelector, parent?: Element | Node): Promise<any>;
|
|
30
|
+
export declare function toSelector(selector: CommonSelector<Selector>): Selector;
|
|
31
|
+
export declare function extractContext(driver: Driver): Context;
|
|
32
|
+
export declare function executeScript(context: Context, script: (arg: any) => any, arg?: any): Promise<any>;
|
|
33
|
+
export declare function findElement(context: Context, selector: Selector, parent?: Element | Node): Promise<Element | null>;
|
|
34
|
+
export declare function findElements(context: Context, selector: Selector, parent?: Element | Node): Promise<Element[]>;
|
|
35
|
+
export declare function mainContext(context: Context): Promise<Context>;
|
|
36
|
+
export declare function parentContext(context: Context): Promise<Context>;
|
|
37
|
+
export declare function childContext(context: Context, element: Element): Promise<Context>;
|
|
38
|
+
export declare function getDriverInfo(): Promise<DriverInfo>;
|
|
54
39
|
export declare function getWindowSize(driver: Driver): Promise<Size>;
|
|
55
40
|
export declare function setWindowSize(driver: Driver, size: Size): Promise<void>;
|
|
56
|
-
export declare function getCookies(_driver: Driver): Promise<
|
|
41
|
+
export declare function getCookies(_driver: Driver): Promise<Cookie[]>;
|
|
57
42
|
export declare function takeScreenshot(driver: Driver): Promise<string>;
|
|
58
|
-
export declare function getTitle(driver: Driver): Promise<string
|
|
59
|
-
export declare function getUrl(driver: Driver): Promise<string
|
|
60
|
-
export declare function getDriverInfo(): Promise<{
|
|
61
|
-
features: {
|
|
62
|
-
canExecuteOnlyFunctionScripts: boolean;
|
|
63
|
-
};
|
|
64
|
-
}>;
|
|
65
|
-
export {};
|
|
43
|
+
export declare function getTitle(driver: Driver): Promise<string>;
|
|
44
|
+
export declare function getUrl(driver: Driver): Promise<string>;
|