webdriverio 9.1.5 → 9.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.
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type local } from 'webdriver';
|
|
2
|
+
import type { ChainablePromiseElement } from '../../types.js';
|
|
3
|
+
type FlatContextTree = Omit<local.BrowsingContextInfo, 'children'> & {
|
|
4
|
+
children: string[];
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Switches the active context to a frame, e.g. an iframe on the page. There are multiple ways you can query a frame
|
|
8
|
+
* on the page:
|
|
9
|
+
*
|
|
10
|
+
* - If given a string it switches to the frame with a matching context id, url or url that contains that string
|
|
11
|
+
* ```ts
|
|
12
|
+
* // switch to a frame that has the url "https://the-internet.herokuapp.com/iframe"
|
|
13
|
+
* await browser.switchFrame('https://the-internet.herokuapp.com/iframe')
|
|
14
|
+
* // switch to a frame that has a certain context id
|
|
15
|
+
* await browser.switchFrame('A5734774C41F8C91D483BDD4022B2EF3')
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* - If given a WebdriverIO element that references an `iframe` element it will switch to that frame
|
|
19
|
+
* ```ts
|
|
20
|
+
* // switch to a frame element queried from current context
|
|
21
|
+
* await browser.switchFrame($('iframe'))
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* - If given a function it will loop through all iframes on the page and call the function with the context
|
|
25
|
+
* object. The function should return a boolean indicating if the frame should be selected. Within the function
|
|
26
|
+
* you can use WebdriverIO commands to e.g. check if a certain frame element exists.
|
|
27
|
+
* ```ts
|
|
28
|
+
* // switch to first frame that contains an element with id "#frameContent"
|
|
29
|
+
* await browser.switchFrame(() => $('#frameContent').isExisting())
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* - If given `null` it will switch to the top level frame
|
|
33
|
+
* ```ts
|
|
34
|
+
* // first switch into a frame
|
|
35
|
+
* await browser.switchFrame($('iframe'))
|
|
36
|
+
* // do more automation within that frame, then ...
|
|
37
|
+
*
|
|
38
|
+
* // switch to the top level frame
|
|
39
|
+
* await browser.switchFrame(null)
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @alias browser.switchFrame
|
|
43
|
+
* @param {string|object|function} context
|
|
44
|
+
* @returns {Promise<string>} the current active context id
|
|
45
|
+
*/
|
|
46
|
+
export declare function switchFrame(this: WebdriverIO.Browser, context: WebdriverIO.Element | ChainablePromiseElement | string | null | ((tree: FlatContextTree) => boolean | Promise<boolean>)): Promise<string | ((tree: FlatContextTree) => boolean | Promise<boolean>)>;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=switchFrame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switchFrame.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/switchFrame.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,WAAW,CAAA;AAGtC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAE7D,KAAK,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,UAAU,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA;AAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAsB,WAAW,CAC7B,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,OAAO,EAAE,WAAW,CAAC,OAAO,GAAG,uBAAuB,GAAG,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,4BAA/C,eAAe,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAgFlI"}
|
|
@@ -34,6 +34,7 @@ export * from './browser/setTimeout.js';
|
|
|
34
34
|
export * from './browser/setViewport.js';
|
|
35
35
|
export * from './browser/setWindowSize.js';
|
|
36
36
|
export * from './browser/switchWindow.js';
|
|
37
|
+
export * from './browser/switchFrame.js';
|
|
37
38
|
export * from './browser/throttle.js';
|
|
38
39
|
export * from './browser/throttleCPU.js';
|
|
39
40
|
export * from './browser/throttleNetwork.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/commands/browser.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,2BAA2B,CAAA;AACzC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CAAA;AACzC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,2BAA2B,CAAA;AACzC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kCAAkC,CAAA;AAChD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,0BAA0B,CAAA;AACxC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,2BAA2B,C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AAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -122,6 +122,7 @@ __export(browser_exports, {
|
|
|
122
122
|
setTimeout: () => setTimeout2,
|
|
123
123
|
setViewport: () => setViewport,
|
|
124
124
|
setWindowSize: () => setWindowSize,
|
|
125
|
+
switchFrame: () => switchFrame,
|
|
125
126
|
switchWindow: () => switchWindow,
|
|
126
127
|
throttle: () => throttle,
|
|
127
128
|
throttleCPU: () => throttleCPU,
|
|
@@ -4164,6 +4165,112 @@ async function switchWindow(matcher) {
|
|
|
4164
4165
|
throw new Error(`No window found with title, url or name matching "${matcher}"`);
|
|
4165
4166
|
}
|
|
4166
4167
|
|
|
4168
|
+
// src/commands/browser/switchFrame.ts
|
|
4169
|
+
async function switchFrame(context) {
|
|
4170
|
+
if (context === null) {
|
|
4171
|
+
const handle = await this.getWindowHandle();
|
|
4172
|
+
await switchToFrameHelper(this, handle);
|
|
4173
|
+
return handle;
|
|
4174
|
+
}
|
|
4175
|
+
if (typeof context === "string") {
|
|
4176
|
+
const tree = await this.browsingContextGetTree({});
|
|
4177
|
+
const urlContext = findContext(context, tree.contexts, byUrl)?.context;
|
|
4178
|
+
if (urlContext) {
|
|
4179
|
+
await switchToFrameHelper(this, urlContext);
|
|
4180
|
+
return urlContext;
|
|
4181
|
+
}
|
|
4182
|
+
const urlContextContaining = findContext(context, tree.contexts, byUrlContaining)?.context;
|
|
4183
|
+
if (urlContextContaining) {
|
|
4184
|
+
await switchToFrameHelper(this, urlContextContaining);
|
|
4185
|
+
return urlContextContaining;
|
|
4186
|
+
}
|
|
4187
|
+
const contextIdContext = findContext(context, tree.contexts, byContextId)?.context;
|
|
4188
|
+
if (contextIdContext) {
|
|
4189
|
+
await switchToFrameHelper(this, contextIdContext);
|
|
4190
|
+
return contextIdContext;
|
|
4191
|
+
}
|
|
4192
|
+
throw new Error(`Frame with url or context id "${context}" not found`);
|
|
4193
|
+
}
|
|
4194
|
+
if (typeof context === "object" && typeof context.getElement === "function") {
|
|
4195
|
+
const element = await context.getElement();
|
|
4196
|
+
return switchToFrameUsingElement(this, element);
|
|
4197
|
+
}
|
|
4198
|
+
if (typeof context === "function") {
|
|
4199
|
+
const tree = await this.browsingContextGetTree({});
|
|
4200
|
+
const mapContext = (context2) => [
|
|
4201
|
+
context2.context,
|
|
4202
|
+
...(context2.children || []).map(mapContext)
|
|
4203
|
+
];
|
|
4204
|
+
const sessionContext = getContextManager(this);
|
|
4205
|
+
const currentContext = await sessionContext.getCurrentContext();
|
|
4206
|
+
const allContexts = tree.contexts.map(mapContext).flat(Infinity).filter((ctx) => ctx !== currentContext).reduce((acc, ctx) => {
|
|
4207
|
+
const context2 = findContext(ctx, tree.contexts, byContextId);
|
|
4208
|
+
acc[ctx] = context2;
|
|
4209
|
+
return acc;
|
|
4210
|
+
}, {});
|
|
4211
|
+
for (const [contextId, ctx] of Object.entries(allContexts)) {
|
|
4212
|
+
sessionContext.setCurrentContext(contextId);
|
|
4213
|
+
const isDesiredFrame = await context(ctx);
|
|
4214
|
+
if (isDesiredFrame) {
|
|
4215
|
+
return context;
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
sessionContext.setCurrentContext(currentContext);
|
|
4219
|
+
throw new Error("Could not find the desired frame");
|
|
4220
|
+
}
|
|
4221
|
+
throw new Error(
|
|
4222
|
+
`Invalid type for context parameter: ${typeof context}, expected one of number, string or null. Check out our docs: https://webdriver.io/docs/api/browser/switchToFrame.html`
|
|
4223
|
+
);
|
|
4224
|
+
}
|
|
4225
|
+
function switchToFrameHelper(browser, context) {
|
|
4226
|
+
const sessionContext = getContextManager(browser);
|
|
4227
|
+
sessionContext.setCurrentContext(context);
|
|
4228
|
+
}
|
|
4229
|
+
async function switchToFrameUsingElement(browser, element) {
|
|
4230
|
+
let frameSrc = await element.getAttribute("src");
|
|
4231
|
+
if (!frameSrc) {
|
|
4232
|
+
const source = await element.getHTML({ includeSelectorTag: true });
|
|
4233
|
+
throw new Error(
|
|
4234
|
+
`The provided frame element ("${source}") does not have a src attribute needed to detect the context, please use a different method to select the frame. For more information checkout our docs: https://webdriver.io/docs/api/browser/switchFrame.html`
|
|
4235
|
+
);
|
|
4236
|
+
}
|
|
4237
|
+
if (!frameSrc.startsWith("http")) {
|
|
4238
|
+
frameSrc = await browser.execute((urlPath) => URL.parse(urlPath, window.location.href)?.href, frameSrc) || frameSrc;
|
|
4239
|
+
}
|
|
4240
|
+
const tree = await browser.browsingContextGetTree({});
|
|
4241
|
+
const urlContext = findContext(frameSrc, tree.contexts, byUrl)?.context;
|
|
4242
|
+
if (!urlContext) {
|
|
4243
|
+
throw new Error(
|
|
4244
|
+
`Frame with url "${frameSrc}" not found! Please try a different method to select the frame. For more information checkout our docs: https://webdriver.io/docs/api/browser/switchFrame.html`
|
|
4245
|
+
);
|
|
4246
|
+
}
|
|
4247
|
+
await switchToFrameHelper(browser, urlContext);
|
|
4248
|
+
return urlContext;
|
|
4249
|
+
}
|
|
4250
|
+
function byUrl(context, url6) {
|
|
4251
|
+
return context.url === url6;
|
|
4252
|
+
}
|
|
4253
|
+
function byUrlContaining(context, url6) {
|
|
4254
|
+
return context.url.includes(url6);
|
|
4255
|
+
}
|
|
4256
|
+
function byContextId(context, contextId) {
|
|
4257
|
+
return context.context === contextId;
|
|
4258
|
+
}
|
|
4259
|
+
function findContext(url6, contexts, matcher) {
|
|
4260
|
+
for (const context of contexts || []) {
|
|
4261
|
+
if (matcher(context, url6)) {
|
|
4262
|
+
return context;
|
|
4263
|
+
}
|
|
4264
|
+
if (Array.isArray(context.children) && context.children.length > 0) {
|
|
4265
|
+
const result = findContext(url6, context.children, matcher);
|
|
4266
|
+
if (result) {
|
|
4267
|
+
return result;
|
|
4268
|
+
}
|
|
4269
|
+
}
|
|
4270
|
+
}
|
|
4271
|
+
return void 0;
|
|
4272
|
+
}
|
|
4273
|
+
|
|
4167
4274
|
// src/commands/browser/throttle.ts
|
|
4168
4275
|
import logger13 from "@wdio/logger";
|
|
4169
4276
|
import { getBrowserObject as getBrowserObject8 } from "@wdio/utils";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webdriverio",
|
|
3
3
|
"description": "Next-gen browser and mobile automation test framework for Node.js",
|
|
4
|
-
"version": "9.1
|
|
4
|
+
"version": "9.2.1",
|
|
5
5
|
"homepage": "https://webdriver.io",
|
|
6
6
|
"author": "Christian Bromann <mail@bromann.dev>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@types/sinonjs__fake-timers": "^8.1.5",
|
|
79
79
|
"@wdio/config": "9.1.3",
|
|
80
80
|
"@wdio/logger": "9.1.3",
|
|
81
|
-
"@wdio/protocols": "9.0
|
|
81
|
+
"@wdio/protocols": "9.2.0",
|
|
82
82
|
"@wdio/repl": "9.0.8",
|
|
83
83
|
"@wdio/types": "9.1.3",
|
|
84
84
|
"@wdio/utils": "9.1.3",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"rgb2hex": "0.2.5",
|
|
101
101
|
"serialize-error": "^11.0.3",
|
|
102
102
|
"urlpattern-polyfill": "^10.0.0",
|
|
103
|
-
"webdriver": "9.
|
|
103
|
+
"webdriver": "9.2.0"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"puppeteer-core": "^22.3.0"
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"optional": true
|
|
111
111
|
}
|
|
112
112
|
},
|
|
113
|
-
"gitHead": "
|
|
113
|
+
"gitHead": "3da8b097c684b0ed9cda7224c41f96151bcd4104"
|
|
114
114
|
}
|