Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const popupStore = new Popup();
const consoleLogStore = new Console();
const availableBrowsers = ['chromium', 'webkit', 'firefox'];

const { createValueEngine } = require('./extras/PlaywrightPropEngine');
const { createValueEngine, createDisabledEngine } = require('./extras/PlaywrightPropEngine');
/**
* Uses [Playwright](https://github.com/microsoft/playwright) library to run tests inside:
*
Expand Down Expand Up @@ -261,6 +261,7 @@ class Playwright extends Helper {
// register an internal selector engine for reading value property of elements in a selector
try {
await playwright.selectors.register('__value', createValueEngine);
await playwright.selectors.register('__disabled', createDisabledEngine);
} catch (e) {
console.warn(e);
}
Expand Down Expand Up @@ -1326,9 +1327,9 @@ class Playwright extends Helper {
*/
async setCookie(cookie) {
if (Array.isArray(cookie)) {
return this.browserContext.setCookies(...cookie);
return this.browserContext.addCookies(...cookie);
}
return this.browserContext.setCookies([cookie]);
return this.browserContext.addCookies([cookie]);
}

/**
Expand Down Expand Up @@ -1609,7 +1610,7 @@ class Playwright extends Helper {
const context = await this._getContext();
if (!locator.isXPath()) {
// playwright combined selectors
waiter = context.waitForSelector(`${locator.isCustom() ? `${locator.type}=${locator.value}` : locator.simplify()} >> :not([disabled])`, { timeout: waitTimeout });
waiter = context.waitForSelector(`${locator.isCustom() ? `${locator.type}=${locator.value}` : locator.simplify()} >> __disabled=false`, { timeout: waitTimeout });
} else {
const enabledFn = function ([locator, $XPath]) {
eval($XPath); // eslint-disable-line no-eval
Expand Down
32 changes: 30 additions & 2 deletions lib/helper/extras/PlaywrightPropEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,43 @@ module.exports.createValueEngine = () => {
if (!root) {
return null;
}
return `${root.value}` === selector;
return `${root.value}`.includes(selector) ? root : null;
},

// Returns all elements matching given selector in the root's subtree.
queryAll(root, selector) {
if (!root) {
return null;
}
return `${root.value}` === selector;
return `${root.value}`.includes(selector) ? root : null;
},
};
};

module.exports.createDisabledEngine = () => {
return {
// Creates a selector that matches given target when queried at the root.
// Can return undefined if unable to create one.
create(root, target) {
return null;
},

// Returns the first element matching given selector in the root's subtree.
query(root, value) {
const bool = value === 'true';
if (!root) {
return null;
}
return root.disabled === bool ? root : null;
},

// Returns all elements matching given selector in the root's subtree.
queryAll(root, value) {
const bool = value === 'true';
if (!root) {
return null;
}
return root.disabled === bool ? root : null;
},
};
};
Empty file added settings_override.xml
Empty file.
2 changes: 1 addition & 1 deletion test/helper/Playwright_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Playwright', function () {
I = new Playwright({
url: siteUrl,
windowSize: '500x700',
show: true,
show: false,
waitForTimeout: 5000,
waitForAction: 500,
restart: true,
Expand Down