webdriverio 9.0.0-alpha.59 → 9.0.0-alpha.64

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.
@@ -110,7 +110,7 @@ async function pierceIntoShadowDOM($, elemsWithShadowRootAndId, shadowElementIds
110
110
  /**
111
111
  * fetch html of shadow roots
112
112
  */
113
- const shadowRootContent = await Promise.all(shadowElementIdsFound.map((sel) => (this.execute(getHTMLShadowScript, { [ELEMENT_KEY]: sel }, false, elemsWithShadowRootAndId).then(({ html, shadowElementIdsFound }) => ({ html, shadowElementIdsFound, shadowRootId: sel })))));
113
+ const shadowRootContent = await Promise.all(shadowElementIdsFound.map((sel) => (this.execute(getHTMLShadowScript, { [ELEMENT_KEY]: sel }, false, elemsWithShadowRootAndId).then(({ html, shadowElementIdsFound, styles }) => ({ html, styles, shadowElementIdsFound, shadowRootId: sel })))));
114
114
  /**
115
115
  * update virtual DOM and inject shadow root content
116
116
  */
@@ -119,8 +119,15 @@ async function pierceIntoShadowDOM($, elemsWithShadowRootAndId, shadowElementIds
119
119
  if (!se) {
120
120
  continue;
121
121
  }
122
- const { html } = shadowRootContent.find(({ shadowRootId }) => s === shadowRootId);
123
- se.append(`<shadow-root id="${s}">${html}</shadow-root>`);
122
+ const { html, styles } = shadowRootContent.find(({ shadowRootId }) => s === shadowRootId);
123
+ se.append([
124
+ `<template shadowroot="open" shadowrootmode="open" id="${s}">`,
125
+ styles.length > 0
126
+ ? `\t<style>${styles.join('\n')}</style>`
127
+ : '',
128
+ `\t${html}`,
129
+ '</template>',
130
+ ].join('\n'));
124
131
  }
125
132
  const elementsToLookup = shadowRootContent.map(({ shadowElementIdsFound }) => shadowElementIdsFound).flat();
126
133
  /**
@@ -144,16 +151,14 @@ function sanitizeHTML($, options = {}) {
144
151
  */
145
152
  const isCheerioObject = $ && typeof $ !== 'string';
146
153
  if (isCheerioObject) {
147
- $('shadow-root[id]').each((_, el) => { delete el.attribs.id; });
154
+ $('template[id]').each((_, el) => { delete el.attribs.id; });
148
155
  $('[data-wdio-shadow-id]').each((_, el) => { delete el.attribs['data-wdio-shadow-id']; });
149
156
  }
150
157
  let returnHTML = isCheerioObject ? $('body').html() : $;
151
158
  if (options.removeCommentNodes) {
152
159
  returnHTML = returnHTML?.replace(/<!--[\s\S]*?-->/g, '');
153
160
  }
154
- return options.prettify && returnHTML.includes('<')
155
- // we have to verify if HTML string starts with `<` and ends with `>` to avoid
156
- // https://github.com/j4w8n/htmlfy/issues/3
157
- ? prettifyFn(`${returnHTML.startsWith('<') ? '' : ' '}${returnHTML}${returnHTML.endsWith('>') ? '' : ' '}`)
161
+ return options.prettify
162
+ ? prettifyFn(returnHTML)
158
163
  : returnHTML;
159
164
  }
@@ -6,8 +6,13 @@
6
6
  * @param {Object} shadowElementIdsFound list of shadow root ids we want to look up in the next iteration
7
7
  * @return {Object} html source and list of shadow root ids found
8
8
  */
9
- export default function getHTMLShadow(element: HTMLElement, includeSelectorTag: boolean, shadowElementIds?: [string, HTMLElement][]): {
9
+ export default function getHTMLShadow(element: HTMLElement | ShadowRoot, includeSelectorTag: boolean, shadowElementIds?: [string, HTMLElement][]): {
10
+ /**
11
+ * `getHTMLShadow` requires `includeSelectorTag` to be set to `false` if the element
12
+ * is a shadow root itself
13
+ */
10
14
  html: string;
11
15
  shadowElementIdsFound: string[];
16
+ styles: string[];
12
17
  };
13
18
  //# sourceMappingURL=getHTMLShadow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getHTMLShadow.d.ts","sourceRoot":"","sources":["../../src/scripts/getHTMLShadow.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACjC,OAAO,EAAE,WAAW,EACpB,kBAAkB,EAAE,OAAO,EAC3B,gBAAgB,GAAE,CAAC,MAAM,EAAE,WAAW,CAAC,EAAO;;;EA6BjD"}
1
+ {"version":3,"file":"getHTMLShadow.d.ts","sourceRoot":"","sources":["../../src/scripts/getHTMLShadow.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACjC,OAAO,EAAE,WAAW,GAAG,UAAU,EACjC,kBAAkB,EAAE,OAAO,EAC3B,gBAAgB,GAAE,CAAC,MAAM,EAAE,WAAW,CAAC,EAAO;IAkC1C;;;OAGG;;;;EAKV"}
@@ -7,6 +7,7 @@
7
7
  * @return {Object} html source and list of shadow root ids found
8
8
  */
9
9
  export default function getHTMLShadow(element, includeSelectorTag, shadowElementIds = []) {
10
+ let styles = [];
10
11
  const shadowElementIdsFound = [];
11
12
  const elemsWithShadowRoot = Array.from(element.querySelectorAll('*'))
12
13
  .filter((el) => el.shadowRoot);
@@ -16,6 +17,12 @@ export default function getHTMLShadow(element, includeSelectorTag, shadowElement
16
17
  if (element.shadowRoot) {
17
18
  elemsWithShadowRoot.unshift(element);
18
19
  }
20
+ if (element.nodeType === 11) {
21
+ styles = Array.from(element.adoptedStyleSheets)
22
+ .map(({ cssRules }) => Array.from(cssRules))
23
+ .flat()
24
+ .map(({ cssText }) => cssText);
25
+ }
19
26
  for (const elem of elemsWithShadowRoot) {
20
27
  /**
21
28
  * attach `data-wdio-shadow-id` attribute to the element so we can later
@@ -28,7 +35,12 @@ export default function getHTMLShadow(element, includeSelectorTag, shadowElement
28
35
  }
29
36
  }
30
37
  return {
38
+ /**
39
+ * `getHTMLShadow` requires `includeSelectorTag` to be set to `false` if the element
40
+ * is a shadow root itself
41
+ */
31
42
  html: element[includeSelectorTag ? 'outerHTML' : 'innerHTML'],
32
- shadowElementIdsFound
43
+ shadowElementIdsFound,
44
+ styles
33
45
  };
34
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"shadowRoot.d.ts","sourceRoot":"","sources":["../src/shadowRoot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAKtC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,qBAShE;AAED;;;;GAIG;AACH,qBAAa,iBAAiB;;gBAUd,OAAO,EAAE,WAAW,CAAC,OAAO;IAyBxC,UAAU;IAIV;;OAEG;IACH,yBAAyB,CAAC,QAAQ,EAAE,KAAK,CAAC,6BAA6B;IAKvE;;OAEG;IACH,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ;IA2ClC;;;;OAIG;IACH,wBAAwB,CAAC,OAAO,CAAC,EAAE,MAAM;IASzC,gBAAgB,CAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAU9C;;;;OAIG;IACH,uBAAuB,CAAE,EAAE,EAAE,MAAM;CAGtC"}
1
+ {"version":3,"file":"shadowRoot.d.ts","sourceRoot":"","sources":["../src/shadowRoot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAKtC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,qBAShE;AAED;;;;GAIG;AACH,qBAAa,iBAAiB;;gBAUd,OAAO,EAAE,WAAW,CAAC,OAAO;IAyBxC,UAAU;IAIV;;OAEG;IACH,yBAAyB,CAAC,QAAQ,EAAE,KAAK,CAAC,6BAA6B;IAIvE;;OAEG;IACH,cAAc,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ;IA6ClC;;;;OAIG;IACH,wBAAwB,CAAC,OAAO,CAAC,EAAE,MAAM;IASzC,gBAAgB,CAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAU9C;;;;OAIG;IACH,uBAAuB,CAAE,EAAE,EAAE,MAAM;CAGtC"}
@@ -52,7 +52,6 @@ export class ShadowRootManager {
52
52
  */
53
53
  handleBrowsingContextLoad(response) {
54
54
  this.#currentContext = response.context;
55
- this.#shadowRoots.set(response.context, new Set());
56
55
  }
57
56
  /**
58
57
  * capture shadow root elements propagated through console.debug
@@ -76,10 +75,13 @@ export class ShadowRootManager {
76
75
  if (!log.source.context) {
77
76
  return;
78
77
  }
79
- const shadowRootForContext = this.#shadowRoots.get(log.source.context);
80
- if (!shadowRootForContext) {
81
- return;
78
+ /**
79
+ * create set for shadow roots if not existing
80
+ */
81
+ if (!this.#shadowRoots.has(log.source.context)) {
82
+ this.#shadowRoots.set(log.source.context, new Set());
82
83
  }
84
+ const shadowRootForContext = this.#shadowRoots.get(log.source.context);
83
85
  const eventType = args[1].value;
84
86
  if (eventType === 'newShadowRoot' && args[2].type === 'node' && args[3].type === 'node') {
85
87
  shadowRootForContext.add(args[2].sharedId);
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.0.0-alpha.59+259e4a29f",
4
+ "version": "9.0.0-alpha.64+3cfecb6e4",
5
5
  "homepage": "https://webdriver.io",
6
6
  "author": "Christian Bromann <mail@bromann.dev>",
7
7
  "license": "MIT",
@@ -61,36 +61,36 @@
61
61
  "typeScriptVersion": "3.8.3",
62
62
  "devDependencies": {
63
63
  "@types/archiver": "^6.0.2",
64
- "@types/aria-query": "^5.0.0",
65
- "@types/lodash.clonedeep": "^4.5.6",
66
- "@types/lodash.zip": "^4.2.6",
67
- "puppeteer-core": "^22.3.0"
64
+ "@types/aria-query": "^5.0.4",
65
+ "@types/lodash.clonedeep": "^4.5.9",
66
+ "@types/lodash.zip": "^4.2.9",
67
+ "puppeteer-core": "^22.6.1"
68
68
  },
69
69
  "dependencies": {
70
- "@types/node": "^20.1.0",
71
- "@wdio/config": "9.0.0-alpha.59+259e4a29f",
72
- "@wdio/logger": "9.0.0-alpha.59+259e4a29f",
73
- "@wdio/protocols": "9.0.0-alpha.59+259e4a29f",
74
- "@wdio/repl": "9.0.0-alpha.59+259e4a29f",
75
- "@wdio/types": "9.0.0-alpha.59+259e4a29f",
76
- "@wdio/utils": "9.0.0-alpha.59+259e4a29f",
77
- "archiver": "^7.0.0",
78
- "aria-query": "^5.0.0",
70
+ "@types/node": "^20.11.30",
71
+ "@wdio/config": "9.0.0-alpha.64+3cfecb6e4",
72
+ "@wdio/logger": "9.0.0-alpha.64+3cfecb6e4",
73
+ "@wdio/protocols": "9.0.0-alpha.64+3cfecb6e4",
74
+ "@wdio/repl": "9.0.0-alpha.64+3cfecb6e4",
75
+ "@wdio/types": "9.0.0-alpha.64+3cfecb6e4",
76
+ "@wdio/utils": "9.0.0-alpha.64+3cfecb6e4",
77
+ "archiver": "^7.0.1",
78
+ "aria-query": "^5.3.0",
79
79
  "cheerio": "^1.0.0-rc.12",
80
80
  "css-shorthand-properties": "^1.1.1",
81
81
  "css-value": "^0.0.1",
82
- "grapheme-splitter": "^1.0.2",
83
- "htmlfy": "0.1.0",
82
+ "grapheme-splitter": "^1.0.4",
83
+ "htmlfy": "^0.2.1",
84
84
  "import-meta-resolve": "^4.0.0",
85
85
  "is-plain-obj": "^4.1.0",
86
86
  "lodash.clonedeep": "^4.5.0",
87
87
  "lodash.zip": "^4.2.0",
88
- "minimatch": "^9.0.0",
89
- "query-selector-shadow-dom": "^1.0.0",
90
- "resq": "^1.9.1",
88
+ "minimatch": "^9.0.3",
89
+ "query-selector-shadow-dom": "^1.0.1",
90
+ "resq": "^1.11.0",
91
91
  "rgb2hex": "0.2.5",
92
- "serialize-error": "^11.0.1",
93
- "webdriver": "9.0.0-alpha.59+259e4a29f"
92
+ "serialize-error": "^11.0.3",
93
+ "webdriver": "9.0.0-alpha.64+3cfecb6e4"
94
94
  },
95
95
  "peerDependencies": {
96
96
  "puppeteer-core": "^22.3.0"
@@ -100,5 +100,5 @@
100
100
  "optional": true
101
101
  }
102
102
  },
103
- "gitHead": "259e4a29f28745e0af3ca6ca3140c8cf491e3771"
103
+ "gitHead": "3cfecb6e45e7d38a1e86766d79d83822160c8e45"
104
104
  }