From 5ebec2f3cf5f9ae005af762fbb6a90df6ab98b82 Mon Sep 17 00:00:00 2001 From: George Griffiths Date: Sun, 29 Mar 2020 14:47:35 +0100 Subject: [PATCH 1/3] fix wait for value --- lib/helper/extras/PlaywrightPropEngine.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/helper/extras/PlaywrightPropEngine.js b/lib/helper/extras/PlaywrightPropEngine.js index 28966ef9f..b8c95e3a4 100644 --- a/lib/helper/extras/PlaywrightPropEngine.js +++ b/lib/helper/extras/PlaywrightPropEngine.js @@ -1,5 +1,6 @@ module.exports.createValueEngine = () => { return { + name: '__value', // Creates a selector that matches given target when queried at the root. // Can return undefined if unable to create one. create(root, target) { @@ -11,7 +12,7 @@ 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. @@ -19,7 +20,7 @@ module.exports.createValueEngine = () => { if (!root) { return null; } - return `${root.value}` === selector; + return `${root.value}`.includes(selector) ? root : null; }, }; }; From b2c8a4b8b493c6f2e69708ea48bedf109d80240e Mon Sep 17 00:00:00 2001 From: George Griffiths Date: Sun, 29 Mar 2020 14:56:50 +0100 Subject: [PATCH 2/3] fix waitForEnabled --- lib/helper/Playwright.js | 5 ++-- lib/helper/extras/PlaywrightPropEngine.js | 29 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 49681640b..46f596eaa 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -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: * @@ -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); } @@ -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 diff --git a/lib/helper/extras/PlaywrightPropEngine.js b/lib/helper/extras/PlaywrightPropEngine.js index b8c95e3a4..8da862604 100644 --- a/lib/helper/extras/PlaywrightPropEngine.js +++ b/lib/helper/extras/PlaywrightPropEngine.js @@ -1,6 +1,5 @@ module.exports.createValueEngine = () => { return { - name: '__value', // Creates a selector that matches given target when queried at the root. // Can return undefined if unable to create one. create(root, target) { @@ -24,3 +23,31 @@ module.exports.createValueEngine = () => { }, }; }; + +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; + }, + }; +}; From 16c32771fff4a273624bb97b6414b19379d6d670 Mon Sep 17 00:00:00 2001 From: George Griffiths Date: Sun, 29 Mar 2020 15:08:24 +0100 Subject: [PATCH 3/3] fix add cookies --- lib/helper/Playwright.js | 4 ++-- settings_override.xml | 0 test/helper/Playwright_test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 settings_override.xml diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 46f596eaa..ecd5314f6 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -1327,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]); } /** diff --git a/settings_override.xml b/settings_override.xml new file mode 100644 index 000000000..e69de29bb diff --git a/test/helper/Playwright_test.js b/test/helper/Playwright_test.js index e61c6a5bb..e2e4e0c79 100644 --- a/test/helper/Playwright_test.js +++ b/test/helper/Playwright_test.js @@ -27,7 +27,7 @@ describe('Playwright', function () { I = new Playwright({ url: siteUrl, windowSize: '500x700', - show: true, + show: false, waitForTimeout: 5000, waitForAction: 500, restart: true,