From 24d4aa771c658f45033dff9767b6b4bf2f3064e7 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Thu, 6 Jul 2023 17:38:15 +0200 Subject: [PATCH 01/15] feat: move to Locator playwright --- lib/helper/Playwright.js | 137 ++++++++++++++------------------- test/helper/Playwright_test.js | 24 +++--- test/helper/webapi.js | 53 +++++-------- 3 files changed, 91 insertions(+), 123 deletions(-) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 2e3143880..5542ddfb6 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -1123,7 +1123,7 @@ class Playwright extends Helper { } /** - * Find a checkbox by providing human readable text: + * Find a checkbox by providing human-readable text: * NOTE: Assumes the checkable element exists * * ```js @@ -1526,13 +1526,8 @@ class Playwright extends Helper { const els = await findFields.call(this, field); assertElementExists(els, field, 'Field'); const el = els[0]; - const tag = await el.getProperty('tagName').then(el => el.jsonValue()); - const editable = await el.getProperty('contenteditable').then(el => el.jsonValue()); - if (tag === 'INPUT' || tag === 'TEXTAREA') { - await this._evaluateHandeInContext(el => el.value = '', el); - } else if (editable) { - await this._evaluateHandeInContext(el => el.innerHTML = '', el); - } + + await el.fill(''); highlightActiveElement.call(this, el, this.page); @@ -1556,21 +1551,16 @@ class Playwright extends Helper { * ``` */ async clearField(locator, options = {}) { - let result; - const isNewClearMethodPresent = typeof this.page.locator().clear === 'function'; + const els = await findFields.call(this, locator); + assertElementExists(els, locator, 'Field to clear'); + + const el = els[0]; - if (isNewClearMethodPresent) { - const els = await findFields.call(this, locator); - assertElementExists(els, locator, 'Field to clear'); - // TODO: locator change required after #3677 implementation - const elXpath = await getXPathForElement(els[0]); + highlightActiveElement.call(this, el, this.page); - await this.page.locator(elXpath).clear(options); - result = await this._waitForAction(); - } else { - result = await this.fillField(locator, ''); - } - return result; + await el.fill(''); + + return this._waitForAction(); } /** @@ -1624,29 +1614,11 @@ class Playwright extends Helper { const els = await findFields.call(this, select); assertElementExists(els, select, 'Selectable field'); const el = els[0]; - if (await el.getProperty('tagName').then(t => t.jsonValue()) !== 'SELECT') { - throw new Error('Element is not ,