@applitools/driver
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -7,6 +7,6 @@ { | ||
"version": "file:../dry-run.tgz", | ||
"integrity": "sha512-zP61GG1Y0dMNnYoY0okAsgbhj7feytzyQvr/D4RqhnYuCqeLXUjasGRqW2rPQGdXJSbJtYc5YgUvKAnYJ3EDeA==", | ||
"integrity": "sha512-wjMYlCrsc2UVVTWOM9lhTqd0y1yXwWeZILYL8CKyaX4bNqFh+dbAWcN2mcrqk9rNLz6X7innLCAiPLQOdwsV5Q==", | ||
"requires": { | ||
"@applitools/snippets": "2.1.4", | ||
"@applitools/types": "1.0.8", | ||
"@applitools/snippets": "2.1.5", | ||
"@applitools/types": "1.0.12", | ||
"@applitools/utils": "1.2.2" | ||
@@ -16,10 +16,10 @@ } | ||
"@applitools/snippets": { | ||
"version": "2.1.4", | ||
"resolved": "https://registry.npmjs.org/@applitools/snippets/-/snippets-2.1.4.tgz", | ||
"integrity": "sha512-Jmp+DM9Kj24+ByMaqoKxhMNsefsSshN5+MLyMyrFurb1FGRGoSMmAT5bZCI7zKFG02pxZmjBmenMhpNQbzZR/A==" | ||
"version": "2.1.5", | ||
"resolved": "https://registry.npmjs.org/@applitools/snippets/-/snippets-2.1.5.tgz", | ||
"integrity": "sha512-kgTE5NoSBauhpW+0klJRSsCD9Y/FCprVfUZXbrdM/QApnn1rmIYj5eY3IQ0KIxE7ekaIdM+UKzPp4wPN4gjN0g==" | ||
}, | ||
"@applitools/types": { | ||
"version": "1.0.8", | ||
"resolved": "https://registry.npmjs.org/@applitools/types/-/types-1.0.8.tgz", | ||
"integrity": "sha512-JypIIWukLRHe0lg5gB1anW1OHNOeZFVDujvHfETvgbXw4HZC4Q1DcStH9yBzJtJiNPY9s15nPuhZ3CmTEUddsA==" | ||
"version": "1.0.12", | ||
"resolved": "https://registry.npmjs.org/@applitools/types/-/types-1.0.12.tgz", | ||
"integrity": "sha512-CM5w3gb9lkNL7yOT3WLrCF1T/21yWH/mw+v79ePvzByizw2qWGJwJImRC9Od0tnIg3QMZI5xrV72b32OUcZvbA==" | ||
}, | ||
@@ -26,0 +26,0 @@ "@applitools/utils": { |
@@ -6,2 +6,8 @@ # Change Log | ||
## 1.1.4 - 2021/9/6 | ||
- add support of reach spec selectors with shadow properties | ||
- updated to @applitools/snippets@2.1.5 (from 2.1.4) | ||
- updated to @applitools/types@1.0.12 (from 1.0.8) | ||
## 1.1.3 - 2021/8/13 | ||
@@ -8,0 +14,0 @@ |
@@ -205,3 +205,14 @@ "use strict"; | ||
await this.focus(); | ||
const element = await this._spec.findElement(this.target, selectorOrElement); | ||
let rootElement = null; | ||
let selector = selectorOrElement; | ||
while (utils.types.has(selector, ['selector', 'shadow']) && this._spec.isSelector(selector.shadow)) { | ||
const element = await this._spec.findElement(this.target, selector, rootElement); | ||
if (!element) | ||
return null; | ||
rootElement = await this.execute(snippets.getShadowRoot, element); | ||
if (!rootElement) | ||
return null; | ||
selector = selector.shadow; | ||
} | ||
const element = await this._spec.findElement(this.target, selector, rootElement); | ||
return element | ||
@@ -224,3 +235,14 @@ ? new element_1.Element({ spec: this._spec, context: this, element, selector: selectorOrElement, logger: this._logger }) | ||
await this.focus(); | ||
const elements = await this._spec.findElements(this.target, selectorOrElement); | ||
let rootElement = null; | ||
let selector = selectorOrElement; | ||
while (utils.types.has(selector, ['selector', 'shadow']) && this._spec.isSelector(selector.shadow)) { | ||
const element = await this._spec.findElement(this.target, selector, rootElement); | ||
if (!element) | ||
return []; | ||
rootElement = await this.execute(snippets.getShadowRoot, element); | ||
if (!rootElement) | ||
return []; | ||
selector = selector.shadow; | ||
} | ||
const elements = await this._spec.findElements(this.target, selector, rootElement); | ||
return elements.map((element, index) => { | ||
@@ -227,0 +249,0 @@ return new element_1.Element({ |
{ | ||
"name": "@applitools/driver", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Applitools universal framework wrapper", | ||
@@ -47,4 +47,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@applitools/snippets": "2.1.4", | ||
"@applitools/types": "1.0.8", | ||
"@applitools/snippets": "2.1.5", | ||
"@applitools/types": "1.0.12", | ||
"@applitools/utils": "1.2.2" | ||
@@ -51,0 +51,0 @@ }, |
@@ -250,3 +250,14 @@ import type * as types from '@applitools/types' | ||
await this.focus() | ||
const element = await this._spec.findElement(this.target, selectorOrElement) | ||
let rootElement = null | ||
let selector = selectorOrElement | ||
while (utils.types.has(selector, ['selector', 'shadow']) && this._spec.isSelector(selector.shadow)) { | ||
const element: TElement = await this._spec.findElement(this.target, selector, rootElement) | ||
if (!element) return null | ||
rootElement = await this.execute(snippets.getShadowRoot, element) | ||
if (!rootElement) return null | ||
selector = selector.shadow | ||
} | ||
const element = await this._spec.findElement(this.target, selector, rootElement) | ||
return element | ||
@@ -270,3 +281,14 @@ ? new Element({spec: this._spec, context: this, element, selector: selectorOrElement, logger: this._logger}) | ||
await this.focus() | ||
const elements = await this._spec.findElements(this.target, selectorOrElement) | ||
let rootElement = null | ||
let selector = selectorOrElement | ||
while (utils.types.has(selector, ['selector', 'shadow']) && this._spec.isSelector(selector.shadow)) { | ||
const element: TElement = await this._spec.findElement(this.target, selector, rootElement) | ||
if (!element) return [] | ||
rootElement = await this.execute(snippets.getShadowRoot, element) | ||
if (!rootElement) return [] | ||
selector = selector.shadow | ||
} | ||
const elements = await this._spec.findElements(this.target, selector, rootElement) | ||
return elements.map((element, index) => { | ||
@@ -273,0 +295,0 @@ return new Element({ |
@@ -122,2 +122,5 @@ const {inspect} = require('util') | ||
}) | ||
this.mockScript(snippets.getShadowRoot, element => { | ||
return element | ||
}) | ||
this.mockScript(snippets.getUserAgent, () => { | ||
@@ -139,3 +142,3 @@ if (this._ua !== undefined) return this._ua | ||
}) | ||
this.mockScript(snippets.setElementMarkers, ([elements, ids]) => { | ||
this.mockScript(snippets.addElementIds, ([elements, ids]) => { | ||
for (const [index, el] of elements.entries()) { | ||
@@ -145,4 +148,8 @@ el.attributes = el.attributes || [] | ||
} | ||
return ids.reduce((selectors, id) => { | ||
selectors[id] = [`[data-applitools-selector~="${id}"]`] | ||
return selectors | ||
}, {}) | ||
}) | ||
this.mockScript(snippets.cleanupElementMarkers, ([elements]) => { | ||
this.mockScript(snippets.cleanupElementIds, ([elements]) => { | ||
for (const el of elements) { | ||
@@ -171,2 +178,3 @@ el.attributes.splice( | ||
parentContextId: null, | ||
parentRootId: null, | ||
...state, | ||
@@ -179,2 +187,5 @@ } | ||
} | ||
if (element.shadow) { | ||
element.shadowRootId = Symbol('shadowId' + (element.name || Math.floor(Math.random() * 100))) | ||
} | ||
elements.push(element) | ||
@@ -203,9 +214,10 @@ if (element.frame) { | ||
} | ||
mockElements(nodes, {parentId = null, parentContextId = null} = {}) { | ||
mockElements(nodes, {parentId = null, parentContextId = null, parentRootId = null} = {}) { | ||
for (const node of nodes) { | ||
const element = this.mockElement(node.selector, {...node, parentId, parentContextId}) | ||
const element = this.mockElement(node.selector, {...node, parentId, parentContextId, parentRootId}) | ||
if (node.children) { | ||
this.mockElements(node.children, { | ||
parentId: element.frame ? null : element.id, | ||
parentContextId: element.frame ? this._contexts.get(element.contextId).id : parentContextId, | ||
parentContextId: element.frame ? element.contextId : parentContextId, | ||
parentRootId: element.shadow ? element.shadowRootId : parentRootId, | ||
}) | ||
@@ -251,9 +263,21 @@ } | ||
} | ||
async findElement(selector) { | ||
async findElement(selector, rootElement) { | ||
const elements = this._elements.get(selector) | ||
return elements ? elements.find(element => element.parentContextId === this._contextId) : null | ||
return elements | ||
? elements.find( | ||
element => | ||
element.parentContextId === this._contextId && | ||
element.parentRootId === ((rootElement || {}).shadowRootId || null), | ||
) | ||
: null | ||
} | ||
async findElements(selector) { | ||
async findElements(selector, rootElement) { | ||
const elements = this._elements.get(selector) | ||
return elements ? elements.filter(element => element.parentContextId === this._contextId) : [] | ||
return elements | ||
? elements.filter( | ||
element => | ||
element.parentContextId === this._contextId && | ||
element.parentRootId === ((rootElement || {}).shadowRootId || null), | ||
) | ||
: [] | ||
} | ||
@@ -260,0 +284,0 @@ async switchToFrame(reference) { |
@@ -14,3 +14,3 @@ const utils = require('@applitools/utils') | ||
utils.types.has(selector, ['using', 'value']) || | ||
utils.types.has(selector, ['type', 'selector']) | ||
utils.types.has(selector, ['selector']) | ||
) | ||
@@ -27,7 +27,7 @@ }, | ||
}, | ||
findElement(driver, selector) { | ||
return driver.findElement(selector.selector || selector) | ||
findElement(driver, selector, parent) { | ||
return driver.findElement(selector.selector || selector, parent) | ||
}, | ||
findElements(driver, selector) { | ||
return driver.findElements(selector) | ||
findElements(driver, selector, parent) { | ||
return driver.findElements(selector.selector || selector, parent) | ||
}, | ||
@@ -34,0 +34,0 @@ mainContext(driver) { |
@@ -35,2 +35,14 @@ import assert from 'assert' | ||
}, | ||
{ | ||
selector: 'shadow1', | ||
shadow: true, | ||
children: [ | ||
{selector: 'shadow1--element1'}, | ||
{ | ||
selector: 'shadow1-1', | ||
shadow: true, | ||
children: [{selector: 'shadow1-1--element1'}], | ||
}, | ||
], | ||
}, | ||
], | ||
@@ -82,2 +94,70 @@ }, | ||
it('element(shadow-selector)', async () => { | ||
const selector = { | ||
selector: 'shadow1', | ||
shadow: {selector: 'shadow1-1', shadow: {selector: 'shadow1-1--element1'}}, | ||
} | ||
const element = await context.element(selector) | ||
assert.deepStrictEqual(element.selector, selector) | ||
}) | ||
it('elements(non-existent)', async () => { | ||
const selector = 'non-existent' | ||
const element = await context.element(selector) | ||
assert.strictEqual(element, null) | ||
}) | ||
it('elements(non-existent-shadow)', async () => { | ||
const selector = { | ||
selector: 'shadow1', | ||
shadow: {selector: 'shadow1-non-existent', shadow: {selector: 'shadow1-non-existent--element1'}}, | ||
} | ||
const element = await context.element(selector) | ||
assert.strictEqual(element, null) | ||
}) | ||
it('elements(selector)', async () => { | ||
const childContext1 = await context.context('frame1') | ||
const childContext11 = await childContext1.context('frame1-1') | ||
const selector = 'frame1-1--element1' | ||
const elements = await childContext11.elements(selector) | ||
assert.ok(Array.isArray(elements)) | ||
assert.strictEqual(elements.length, 1) | ||
assert.strictEqual(elements[0].selector, selector) | ||
}) | ||
it('elements(shadow-selector)', async () => { | ||
const selector = { | ||
selector: 'shadow1', | ||
shadow: {selector: 'shadow1-1', shadow: {selector: 'shadow1-1--element1'}}, | ||
} | ||
const elements = await context.elements(selector) | ||
assert.ok(Array.isArray(elements)) | ||
assert.strictEqual(elements.length, 1) | ||
assert.deepStrictEqual(elements[0].selector, selector) | ||
}) | ||
it('elements(non-existent)', async () => { | ||
const selector = 'non-existent' | ||
const elements = await context.elements(selector) | ||
assert.ok(Array.isArray(elements)) | ||
assert.strictEqual(elements.length, 0) | ||
}) | ||
it('elements(non-existent-shadow)', async () => { | ||
const selector = { | ||
selector: 'shadow1', | ||
shadow: {selector: 'shadow1-non-existent', shadow: {selector: 'shadow1-non-existent--element1'}}, | ||
} | ||
const elements = await context.elements(selector) | ||
assert.ok(Array.isArray(elements)) | ||
assert.strictEqual(elements.length, 0) | ||
}) | ||
it('getContextElement()', async () => { | ||
@@ -84,0 +164,0 @@ const mainContext = context |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
231933
4183
0
+ Added@applitools/snippets@2.1.5(transitive)
+ Added@applitools/types@1.0.12(transitive)
- Removed@applitools/snippets@2.1.4(transitive)
- Removed@applitools/types@1.0.8(transitive)
Updated@applitools/snippets@2.1.5
Updated@applitools/types@1.0.12