webdriverio 9.2.0 → 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.
Files changed (2) hide show
  1. package/build/index.js +84 -79
  2. package/package.json +2 -2
package/build/index.js CHANGED
@@ -886,7 +886,7 @@ async function addInitScript(script, ...args) {
886
886
  throw new Error("This command is only supported when automating browser using WebDriver Bidi protocol");
887
887
  }
888
888
  const serializedParameters = (args || []).map((arg) => JSON.stringify(arg));
889
- const context2 = await this.getWindowHandle();
889
+ const context = await this.getWindowHandle();
890
890
  const fn = `(emit) => {
891
891
  const closure = new Function(\`return ${script.toString()}\`)
892
892
  return closure()(${serializedParameters.length ? `${serializedParameters.join(", ")}, emit` : "emit"})
@@ -898,7 +898,7 @@ async function addInitScript(script, ...args) {
898
898
  type: "channel",
899
899
  value: { channel }
900
900
  }],
901
- contexts: [context2]
901
+ contexts: [context]
902
902
  });
903
903
  await this.sessionSubscribe({
904
904
  events: ["script.message"]
@@ -972,13 +972,13 @@ function debug(commandTimeout = 5e3) {
972
972
  const { introMessage } = WDIORepl;
973
973
  if (!process.env.WDIO_WORKER_ID || typeof process.send !== "function") {
974
974
  console.log(WDIORepl.introMessage);
975
- const context2 = {
975
+ const context = {
976
976
  browser: this,
977
977
  driver: this,
978
978
  $: this.$.bind(this),
979
979
  $$: this.$$.bind(this)
980
980
  };
981
- return repl.start(context2);
981
+ return repl.start(context);
982
982
  }
983
983
  process._debugProcess(process.pid);
984
984
  process.send({
@@ -3013,15 +3013,15 @@ var ContextManager = class {
3013
3013
  *
3014
3014
  * @param {local.BrowsingContextNavigationInfo} context browsing context used to navigate
3015
3015
  */
3016
- async #handleNavigationStarted(context2) {
3016
+ async #handleNavigationStarted(context) {
3017
3017
  const windowHandle = await this.#browser.getWindowHandle();
3018
- if (context2.context === windowHandle && context2.url !== "UNKNOWN") {
3019
- log4.info(`Update current context: ${context2.context}`);
3020
- this.#currentContext = context2.context;
3018
+ if (context.context === windowHandle && context.url !== "UNKNOWN") {
3019
+ log4.info(`Update current context: ${context.context}`);
3020
+ this.#currentContext = context.context;
3021
3021
  }
3022
3022
  }
3023
- setCurrentContext(context2) {
3024
- this.#currentContext = context2;
3023
+ setCurrentContext(context) {
3024
+ this.#currentContext = context;
3025
3025
  }
3026
3026
  async getCurrentContext() {
3027
3027
  if (!this.#currentContext) {
@@ -3077,7 +3077,7 @@ async function execute(script, ...args) {
3077
3077
  if (this.isBidi && !this.isMultiremote) {
3078
3078
  const browser = getBrowserObject2(this);
3079
3079
  const contextManager2 = getContextManager(browser);
3080
- const context2 = await contextManager2.getCurrentContext();
3080
+ const context = await contextManager2.getCurrentContext();
3081
3081
  const userScript = typeof script === "string" ? new Function(script) : script;
3082
3082
  const functionDeclaration = new Function(`
3083
3083
  return (${SCRIPT_PREFIX}${userScript.toString()}${SCRIPT_SUFFIX}).apply(this, arguments);
@@ -3087,7 +3087,7 @@ async function execute(script, ...args) {
3087
3087
  awaitPromise: true,
3088
3088
  arguments: args.map((arg) => LocalValue.getArgument(arg)),
3089
3089
  target: {
3090
- context: context2
3090
+ context
3091
3091
  }
3092
3092
  };
3093
3093
  const result = await browser.scriptCallFunction(params);
@@ -3111,7 +3111,7 @@ async function executeAsync(script, ...args) {
3111
3111
  if (this.isBidi && !this.isMultiremote) {
3112
3112
  const browser = getBrowserObject3(this);
3113
3113
  const contextManager2 = getContextManager(browser);
3114
- const context2 = await contextManager2.getCurrentContext();
3114
+ const context = await contextManager2.getCurrentContext();
3115
3115
  const userScript = typeof script === "string" ? new Function(script) : script;
3116
3116
  const functionDeclaration = new Function(`
3117
3117
  const args = Array.from(arguments)
@@ -3129,7 +3129,7 @@ async function executeAsync(script, ...args) {
3129
3129
  awaitPromise: true,
3130
3130
  arguments: args.map((arg) => LocalValue.getArgument(arg)),
3131
3131
  target: {
3132
- context: context2
3132
+ context
3133
3133
  }
3134
3134
  };
3135
3135
  const result = await browser.scriptCallFunction(params);
@@ -3802,12 +3802,12 @@ async function mock(url6, filterOptions) {
3802
3802
  }
3803
3803
  const browser = getBrowserObject5(this);
3804
3804
  const contextManager2 = getContextManager(browser);
3805
- const context2 = await contextManager2.getCurrentContext();
3806
- if (!SESSION_MOCKS[context2]) {
3807
- SESSION_MOCKS[context2] = /* @__PURE__ */ new Set();
3805
+ const context = await contextManager2.getCurrentContext();
3806
+ if (!SESSION_MOCKS[context]) {
3807
+ SESSION_MOCKS[context] = /* @__PURE__ */ new Set();
3808
3808
  }
3809
3809
  const networkInterception = await WebDriverInterception.initiate(url6, filterOptions || {}, this);
3810
- SESSION_MOCKS[context2].add(networkInterception);
3810
+ SESSION_MOCKS[context].add(networkInterception);
3811
3811
  return networkInterception;
3812
3812
  }
3813
3813
 
@@ -3849,9 +3849,9 @@ async function newWindow(url6, { windowName = "", windowFeatures = "" } = {}) {
3849
3849
  const tabsBefore = await this.getWindowHandles();
3850
3850
  if (this.isBidi) {
3851
3851
  const contextManager2 = getContextManager(this);
3852
- const { context: context2 } = await this.browsingContextCreate({ type: "window" });
3853
- contextManager2.setCurrentContext(context2);
3854
- await this.browsingContextNavigate({ context: context2, url: url6 });
3852
+ const { context } = await this.browsingContextCreate({ type: "window" });
3853
+ contextManager2.setCurrentContext(context);
3854
+ await this.browsingContextNavigate({ context, url: url6 });
3855
3855
  } else {
3856
3856
  await this.execute(newWindowHelper, url6, windowName, windowFeatures);
3857
3857
  }
@@ -4017,8 +4017,8 @@ async function saveScreenshot(filepath) {
4017
4017
  if (this.isBidi) {
4018
4018
  const browser = getBrowserObject6(this);
4019
4019
  const contextManager2 = getContextManager(browser);
4020
- const context2 = await contextManager2.getCurrentContext();
4021
- const { data } = await this.browsingContextCaptureScreenshot({ context: context2 });
4020
+ const context = await contextManager2.getCurrentContext();
4021
+ const { data } = await this.browsingContextCaptureScreenshot({ context });
4022
4022
  screenBuffer = data;
4023
4023
  } else {
4024
4024
  screenBuffer = await this.takeScreenshot();
@@ -4104,9 +4104,9 @@ async function setViewport(options) {
4104
4104
  throw new Error("setViewport expects devicePixelRatio to be a number in the 0 to 2^31 \u2212 1 range");
4105
4105
  }
4106
4106
  const contextManager2 = getContextManager(this);
4107
- const context2 = await contextManager2.getCurrentContext();
4107
+ const context = await contextManager2.getCurrentContext();
4108
4108
  await this.browsingContextSetViewport({
4109
- context: context2,
4109
+ context,
4110
4110
  devicePixelRatio: options.devicePixelRatio || 1,
4111
4111
  viewport: {
4112
4112
  width: options.width,
@@ -4166,70 +4166,73 @@ async function switchWindow(matcher) {
4166
4166
  }
4167
4167
 
4168
4168
  // src/commands/browser/switchFrame.ts
4169
- async function switchFrame(context2) {
4170
- if (context2 === null) {
4169
+ async function switchFrame(context) {
4170
+ if (context === null) {
4171
4171
  const handle = await this.getWindowHandle();
4172
4172
  await switchToFrameHelper(this, handle);
4173
4173
  return handle;
4174
4174
  }
4175
- if (typeof context2 === "string") {
4175
+ if (typeof context === "string") {
4176
4176
  const tree = await this.browsingContextGetTree({});
4177
- const urlContext = findContext(context2, tree.contexts, byUrl)?.context;
4177
+ const urlContext = findContext(context, tree.contexts, byUrl)?.context;
4178
4178
  if (urlContext) {
4179
4179
  await switchToFrameHelper(this, urlContext);
4180
4180
  return urlContext;
4181
4181
  }
4182
- const urlContextContaining = findContext(context2, tree.contexts, byUrlContaining)?.context;
4182
+ const urlContextContaining = findContext(context, tree.contexts, byUrlContaining)?.context;
4183
4183
  if (urlContextContaining) {
4184
4184
  await switchToFrameHelper(this, urlContextContaining);
4185
4185
  return urlContextContaining;
4186
4186
  }
4187
- const contextIdContext = findContext(context2, tree.contexts, byContextId)?.context;
4187
+ const contextIdContext = findContext(context, tree.contexts, byContextId)?.context;
4188
4188
  if (contextIdContext) {
4189
4189
  await switchToFrameHelper(this, contextIdContext);
4190
4190
  return contextIdContext;
4191
4191
  }
4192
- throw new Error(`Frame with url or context id "${context2}" not found`);
4192
+ throw new Error(`Frame with url or context id "${context}" not found`);
4193
4193
  }
4194
- if (typeof context2 === "object" && typeof context2.getElement === "function") {
4195
- const element = await context2.getElement();
4194
+ if (typeof context === "object" && typeof context.getElement === "function") {
4195
+ const element = await context.getElement();
4196
4196
  return switchToFrameUsingElement(this, element);
4197
4197
  }
4198
- if (typeof context2 === "function") {
4198
+ if (typeof context === "function") {
4199
4199
  const tree = await this.browsingContextGetTree({});
4200
- const mapContext = (context3) => [
4201
- context3.context,
4202
- ...(context3.children || []).map(mapContext)
4200
+ const mapContext = (context2) => [
4201
+ context2.context,
4202
+ ...(context2.children || []).map(mapContext)
4203
4203
  ];
4204
4204
  const sessionContext = getContextManager(this);
4205
4205
  const currentContext = await sessionContext.getCurrentContext();
4206
4206
  const allContexts = tree.contexts.map(mapContext).flat(Infinity).filter((ctx) => ctx !== currentContext).reduce((acc, ctx) => {
4207
- const context3 = findContext(ctx, tree.contexts, byContextId);
4208
- acc[ctx] = context3;
4207
+ const context2 = findContext(ctx, tree.contexts, byContextId);
4208
+ acc[ctx] = context2;
4209
4209
  return acc;
4210
4210
  }, {});
4211
4211
  for (const [contextId, ctx] of Object.entries(allContexts)) {
4212
4212
  sessionContext.setCurrentContext(contextId);
4213
- const isDesiredFrame = await context2(ctx);
4213
+ const isDesiredFrame = await context(ctx);
4214
4214
  if (isDesiredFrame) {
4215
- return context2;
4215
+ return context;
4216
4216
  }
4217
4217
  }
4218
4218
  sessionContext.setCurrentContext(currentContext);
4219
4219
  throw new Error("Could not find the desired frame");
4220
4220
  }
4221
4221
  throw new Error(
4222
- `Invalid type for context parameter: ${typeof context2}, expected one of number, string or null. Check out our docs: https://webdriver.io/docs/api/browser/switchToFrame.html`
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
4223
  );
4224
4224
  }
4225
- function switchToFrameHelper(browser, context2) {
4225
+ function switchToFrameHelper(browser, context) {
4226
4226
  const sessionContext = getContextManager(browser);
4227
- sessionContext.setCurrentContext(context2);
4227
+ sessionContext.setCurrentContext(context);
4228
4228
  }
4229
4229
  async function switchToFrameUsingElement(browser, element) {
4230
4230
  let frameSrc = await element.getAttribute("src");
4231
4231
  if (!frameSrc) {
4232
- throw new Error(`Frame with index ${context} has no src attribute`);
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
+ );
4233
4236
  }
4234
4237
  if (!frameSrc.startsWith("http")) {
4235
4238
  frameSrc = await browser.execute((urlPath) => URL.parse(urlPath, window.location.href)?.href, frameSrc) || frameSrc;
@@ -4237,27 +4240,29 @@ async function switchToFrameUsingElement(browser, element) {
4237
4240
  const tree = await browser.browsingContextGetTree({});
4238
4241
  const urlContext = findContext(frameSrc, tree.contexts, byUrl)?.context;
4239
4242
  if (!urlContext) {
4240
- throw new Error(`Frame with url "${frameSrc}" not found`);
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
+ );
4241
4246
  }
4242
4247
  await switchToFrameHelper(browser, urlContext);
4243
4248
  return urlContext;
4244
4249
  }
4245
- function byUrl(context2, url6) {
4246
- return context2.url === url6;
4250
+ function byUrl(context, url6) {
4251
+ return context.url === url6;
4247
4252
  }
4248
- function byUrlContaining(context2, url6) {
4249
- return context2.url.includes(url6);
4253
+ function byUrlContaining(context, url6) {
4254
+ return context.url.includes(url6);
4250
4255
  }
4251
- function byContextId(context2, contextId) {
4252
- return context2.context === contextId;
4256
+ function byContextId(context, contextId) {
4257
+ return context.context === contextId;
4253
4258
  }
4254
4259
  function findContext(url6, contexts, matcher) {
4255
- for (const context2 of contexts || []) {
4256
- if (matcher(context2, url6)) {
4257
- return context2;
4260
+ for (const context of contexts || []) {
4261
+ if (matcher(context, url6)) {
4262
+ return context;
4258
4263
  }
4259
- if (Array.isArray(context2.children) && context2.children.length > 0) {
4260
- const result = findContext(url6, context2.children, matcher);
4264
+ if (Array.isArray(context.children) && context.children.length > 0) {
4265
+ const result = findContext(url6, context.children, matcher);
4261
4266
  if (result) {
4262
4267
  return result;
4263
4268
  }
@@ -4557,18 +4562,18 @@ var NetworkManager = class {
4557
4562
  };
4558
4563
  response.children?.push(request);
4559
4564
  }
4560
- getRequestResponseData(context2) {
4561
- return this.#requests.get(context2);
4565
+ getRequestResponseData(context) {
4566
+ return this.#requests.get(context);
4562
4567
  }
4563
4568
  /**
4564
4569
  * Returns the number of requests that are currently pending.
4565
4570
  * @param context browsing context id
4566
4571
  * @returns the number of requests that are currently pending
4567
4572
  */
4568
- getPendingRequests(context2) {
4569
- const request = this.#requests.get(context2);
4573
+ getPendingRequests(context) {
4574
+ const request = this.#requests.get(context);
4570
4575
  if (!request) {
4571
- throw new Error(`Couldn't find request for context ${context2}`);
4576
+ throw new Error(`Couldn't find request for context ${context}`);
4572
4577
  }
4573
4578
  const subRequests = request.children || [];
4574
4579
  return subRequests.filter((child) => (
@@ -4602,7 +4607,7 @@ async function url3(path4, options = {}) {
4602
4607
  if (this.isBidi) {
4603
4608
  let resetPreloadScript;
4604
4609
  const contextManager2 = getContextManager(this);
4605
- const context2 = await contextManager2.getCurrentContext();
4610
+ const context = await contextManager2.getCurrentContext();
4606
4611
  if (options.onBeforeLoad) {
4607
4612
  if (typeof options.onBeforeLoad !== "function") {
4608
4613
  throw new Error(`Option "onBeforeLoad" must be a function, but received: ${typeof options.onBeforeLoad}`);
@@ -4623,22 +4628,22 @@ async function url3(path4, options = {}) {
4623
4628
  const classicPageLoadStrategy = this.capabilities.pageLoadStrategy === "none" ? "none" : this.capabilities.pageLoadStrategy === "normal" ? "complete" : this.capabilities.pageLoadStrategy === "eager" ? "interactive" : void 0;
4624
4629
  const wait = options.wait === "networkIdle" ? "complete" : options.wait || classicPageLoadStrategy || DEFAULT_WAIT_STATE;
4625
4630
  await this.browsingContextNavigate({
4626
- context: context2,
4631
+ context,
4627
4632
  url: path4,
4628
4633
  wait
4629
4634
  });
4630
4635
  const network = networkManager.get(this);
4631
- const request = network?.getRequestResponseData(context2);
4636
+ const request = network?.getRequestResponseData(context);
4632
4637
  if (mock2) {
4633
4638
  await mock2.restore();
4634
4639
  }
4635
4640
  if (network && options.wait === "networkIdle") {
4636
4641
  const timeout = options.timeout || DEFAULT_NETWORK_IDLE_TIMEOUT;
4637
4642
  await this.waitUntil(async () => {
4638
- return network.getPendingRequests(context2).length === 0;
4643
+ return network.getPendingRequests(context).length === 0;
4639
4644
  }, {
4640
4645
  timeout,
4641
- timeoutMsg: `Navigation to '${path4}' timed out after ${timeout}ms with ${network.getPendingRequests(context2).length} (${network.getPendingRequests(context2).map((r) => r.url).join(", ")}) pending requests`
4646
+ timeoutMsg: `Navigation to '${path4}' timed out after ${timeout}ms with ${network.getPendingRequests(context).length} (${network.getPendingRequests(context).map((r) => r.url).join(", ")}) pending requests`
4642
4647
  });
4643
4648
  }
4644
4649
  if (resetPreloadScript) {
@@ -5319,8 +5324,8 @@ async function getHTML(options = {}) {
5319
5324
  const { load } = await import("cheerio");
5320
5325
  const shadowRootManager2 = getShadowRootManager(browser);
5321
5326
  const contextManager2 = getContextManager(browser);
5322
- const context2 = await contextManager2.getCurrentContext();
5323
- const shadowRootElementPairs = shadowRootManager2.getShadowElementPairsByContextId(context2, this.elementId);
5327
+ const context = await contextManager2.getCurrentContext();
5328
+ const shadowRootElementPairs = shadowRootManager2.getShadowElementPairsByContextId(context, this.elementId);
5324
5329
  const elementsWithShadowRootAndIdVerified = (await Promise.all(
5325
5330
  shadowRootElementPairs.map(([elemId, elem]) => browser.execute((elem2) => elem2.tagName, { [ELEMENT_KEY11]: elemId }).then(
5326
5331
  () => [elemId, elem],
@@ -5341,7 +5346,7 @@ async function getHTML(options = {}) {
5341
5346
  populateHTML($3, shadowElementHTML.map(({ id, ...props }) => ({
5342
5347
  ...props,
5343
5348
  id,
5344
- mode: shadowRootManager2.getShadowRootModeById(context2, id) || "open"
5349
+ mode: shadowRootManager2.getShadowRootModeById(context, id) || "open"
5345
5350
  })));
5346
5351
  return sanitizeHTML($3, { removeCommentNodes, prettify, excludeElements });
5347
5352
  }
@@ -5492,8 +5497,8 @@ var getWebElement = (el) => ({
5492
5497
  async function isEqual(el) {
5493
5498
  const browser = getBrowserObject21(this);
5494
5499
  if (browser.isMobile) {
5495
- const context2 = await browser.getContext().catch(() => void 0);
5496
- const contextId = typeof context2 === "string" ? context2 : context2?.id;
5500
+ const context = await browser.getContext().catch(() => void 0);
5501
+ const contextId = typeof context === "string" ? context : context?.id;
5497
5502
  if (contextId && contextId.toLowerCase().includes("native")) {
5498
5503
  return this.elementId === el.elementId;
5499
5504
  }
@@ -6595,15 +6600,15 @@ async function findDeepElement(selector) {
6595
6600
  const browser = getBrowserObject30(this);
6596
6601
  const shadowRootManager2 = getShadowRootManager(browser);
6597
6602
  const contextManager2 = getContextManager(browser);
6598
- const context2 = await contextManager2.getCurrentContext();
6603
+ const context = await contextManager2.getCurrentContext();
6599
6604
  const shadowRoots = shadowRootManager2.getShadowElementsByContextId(
6600
- context2,
6605
+ context,
6601
6606
  this.elementId
6602
6607
  );
6603
6608
  const { using, value } = findStrategy(selector, this.isW3C, this.isMobile);
6604
6609
  const locator = transformClassicToBidiSelector(using, value);
6605
6610
  const startNodes = shadowRoots.length > 0 ? shadowRoots.map((shadowRootNodeId) => ({ sharedId: shadowRootNodeId })) : this.elementId ? [{ sharedId: this.elementId }] : void 0;
6606
- const deepElementResult = await browser.browsingContextLocateNodes({ locator, context: context2, startNodes }).then(async (result) => {
6611
+ const deepElementResult = await browser.browsingContextLocateNodes({ locator, context, startNodes }).then(async (result) => {
6607
6612
  const nodes = result.nodes.filter((node) => Boolean(node.sharedId)).map((node) => ({
6608
6613
  [ELEMENT_KEY17]: node.sharedId,
6609
6614
  locator
@@ -6633,15 +6638,15 @@ async function findDeepElements(selector) {
6633
6638
  const browser = getBrowserObject30(this);
6634
6639
  const shadowRootManager2 = getShadowRootManager(browser);
6635
6640
  const contextManager2 = getContextManager(browser);
6636
- const context2 = await contextManager2.getCurrentContext();
6641
+ const context = await contextManager2.getCurrentContext();
6637
6642
  const shadowRoots = shadowRootManager2.getShadowElementsByContextId(
6638
- context2,
6643
+ context,
6639
6644
  this.elementId
6640
6645
  );
6641
6646
  const { using, value } = findStrategy(selector, this.isW3C, this.isMobile);
6642
6647
  const locator = transformClassicToBidiSelector(using, value);
6643
6648
  const startNodes = shadowRoots.length > 0 ? shadowRoots.map((shadowRootNodeId) => ({ sharedId: shadowRootNodeId })) : this.elementId ? [{ sharedId: this.elementId }] : void 0;
6644
- const deepElementResult = await browser.browsingContextLocateNodes({ locator, context: context2, startNodes }).then(async (result) => {
6649
+ const deepElementResult = await browser.browsingContextLocateNodes({ locator, context, startNodes }).then(async (result) => {
6645
6650
  const nodes = result.nodes.filter((node) => Boolean(node.sharedId)).map((node) => ({
6646
6651
  [ELEMENT_KEY17]: node.sharedId,
6647
6652
  locator
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.2.0",
4
+ "version": "9.2.1",
5
5
  "homepage": "https://webdriver.io",
6
6
  "author": "Christian Bromann <mail@bromann.dev>",
7
7
  "license": "MIT",
@@ -110,5 +110,5 @@
110
110
  "optional": true
111
111
  }
112
112
  },
113
- "gitHead": "d19039c7166c6df2e47a02de289a66865372107e"
113
+ "gitHead": "3da8b097c684b0ed9cda7224c41f96151bcd4104"
114
114
  }