From 40520007d27a290b9897c71d7f9d81f65cfd6caa Mon Sep 17 00:00:00 2001 From: EgorBodnar Date: Fri, 21 Apr 2023 20:52:00 +0800 Subject: [PATCH 01/35] chore: bringing the name of options to a general form --- docs/helpers/Playwright.md | 4 ++-- lib/helper/Playwright.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/helpers/Playwright.md b/docs/helpers/Playwright.md index 20cc6a474..85421d64d 100644 --- a/docs/helpers/Playwright.md +++ b/docs/helpers/Playwright.md @@ -493,7 +493,7 @@ I.click({css: 'nav a.login'}); - `locator` **([string][8] | [object][5])** clickable link or button located by text, or any element located by CSS|XPath|strict locator. - `context` **([string][8]? | [object][5] | null)** (optional, `null` by default) element to search in CSS|XPath|Strict locator. ⚠️ returns a _promise_ which is synchronized internally by recorder -- `opts` **any?** [Additional options][10] for click available as 3rd argument.Examples:```js +- `options` **any?** [Additional options][10] for click available as 3rd argument.Examples:```js // click on element at position I.click('canvas', '.model', { position: { x: 20, y: 40 } }) @@ -2001,7 +2001,7 @@ See [Playwright's reference][31] #### Parameters -- `opts` **any** +- `options` **any** ### waitForRequest diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 7f8061237..40f1452d4 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -1285,7 +1285,7 @@ class Playwright extends Helper { /** * {{> click }} * - * @param {any} [opts] [Additional options](https://playwright.dev/docs/api/class-page#page-click) for click available as 3rd argument. + * @param {any} [options] [Additional options](https://playwright.dev/docs/api/class-page#page-click) for click available as 3rd argument. * * Examples: * @@ -1298,8 +1298,8 @@ class Playwright extends Helper { * ``` * */ - async click(locator, context = null, opts = {}) { - return proceedClick.call(this, locator, context, opts); + async click(locator, context = null, options = {}) { + return proceedClick.call(this, locator, context, options); } /** @@ -2461,15 +2461,15 @@ class Playwright extends Helper { * * See [Playwright's reference](https://playwright.dev/docs/api/class-page?_highlight=waitfornavi#pagewaitfornavigationoptions) * - * @param {*} opts + * @param {*} options */ - async waitForNavigation(opts = {}) { - opts = { + async waitForNavigation(options = {}) { + options = { timeout: this.options.getPageTimeout, waitUntil: this.options.waitForNavigation, - ...opts, + ...options, }; - return this.page.waitForNavigation(opts); + return this.page.waitForNavigation(options); } async waitUntilExists(locator, sec) { From eddae7c1f6fa8c767fea1dcb9f66e535d580c7b4 Mon Sep 17 00:00:00 2001 From: EgorBodnar Date: Mon, 15 May 2023 16:26:06 +0800 Subject: [PATCH 02/35] FEATURE(new playwright api): add .blur() --- lib/helper/Playwright.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 40f1452d4..d4e872566 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -1302,6 +1302,26 @@ class Playwright extends Helper { return proceedClick.call(this, locator, context, options); } + /** + * {{> blur }} + * Remove focus from a text input + * @param {any} [options] [Additional options](https://playwright.dev/docs/api/class-locator#locator-blur) for available options object as 2nd argument. + * + * Examples: + * + * ```js + * I.blur('.text-area') + * ``` + * + */ + async blur(locator, options = {}) { + const els = await this._locate(locator); + assertElementExists(els, locator, 'Element to blur'); + const el = els[0]; + await el.blur(options); + return this._waitForAction(); + } + /** * Clicks link and waits for navigation (deprecated) */ From 6d05ec980f8694329e8c1d4aacddfe0ef56fb219 Mon Sep 17 00:00:00 2001 From: EgorBodnar Date: Mon, 15 May 2023 17:16:41 +0800 Subject: [PATCH 03/35] DOC(new playwright api): add .blur() --- docs/helpers/Playwright.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/helpers/Playwright.md b/docs/helpers/Playwright.md index 85421d64d..f6f611aa1 100644 --- a/docs/helpers/Playwright.md +++ b/docs/helpers/Playwright.md @@ -406,6 +406,18 @@ I.attachFile('form input[name=avatar]', 'data/avatar.jpg'); - `pathToFile` **[string][8]** local file path relative to codecept.conf.ts or codecept.conf.js config file. ⚠️ returns a _promise_ which is synchronized internally by recorder +### blur + +{{> blur }} +Remove focus from a text input + +#### Parameters + +- `locator` +- `options` **any?** [Additional options][9] for available options object as 2nd argument.Examples:```js + I.blur('.text-area') + ``` + ### cancelPopup Dismisses the active JavaScript popup, as created by window.alert|window.confirm|window.prompt. From 3393c7683f5f3155d7a768b183b5803a8c249664 Mon Sep 17 00:00:00 2001 From: EgorBodnar Date: Mon, 15 May 2023 19:41:31 +0800 Subject: [PATCH 04/35] FEATURE(new playwright api): add .blur() --- lib/helper/Playwright.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index d4e872566..872948680 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -1302,26 +1302,6 @@ class Playwright extends Helper { return proceedClick.call(this, locator, context, options); } - /** - * {{> blur }} - * Remove focus from a text input - * @param {any} [options] [Additional options](https://playwright.dev/docs/api/class-locator#locator-blur) for available options object as 2nd argument. - * - * Examples: - * - * ```js - * I.blur('.text-area') - * ``` - * - */ - async blur(locator, options = {}) { - const els = await this._locate(locator); - assertElementExists(els, locator, 'Element to blur'); - const el = els[0]; - await el.blur(options); - return this._waitForAction(); - } - /** * Clicks link and waits for navigation (deprecated) */ @@ -1519,6 +1499,26 @@ class Playwright extends Helper { return this._waitForAction(); } + /** + * {{> blur }} + * Remove focus from a text input + * @param {any} [options] [Additional options](https://playwright.dev/docs/api/class-locator#locator-blur) for available options object as 2nd argument. + * + * Examples: + * + * ```js + * I.blur('.text-area') + * ``` + * + */ + async blur(locator, options = {}) { + const els = await this._locate(locator); + assertElementExists(els, locator, 'Element to blur'); + const el = els[0]; + await el.blur(options); + return this._waitForAction(); + } + /** * {{> seeInField }} */ From 24363458396984073fe0451502f5e3bf1eed3b4f Mon Sep 17 00:00:00 2001 From: EgorBodnar Date: Mon, 15 May 2023 20:09:59 +0800 Subject: [PATCH 05/35] FEATURE(new playwright api): add .focus() --- lib/helper/Playwright.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 872948680..954a08022 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -905,6 +905,28 @@ class Playwright extends Helper { return this._waitForAction(); } + /** + * {{> focus }} + * Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the matching element. + * @param {any} [options] [Additional options](https://playwright.dev/docs/api/class-locator#locator-focus) for available options object as 2nd argument. + * + * Examples: + * + * ```js + * I.dontSee('#add-to-cart'); + * I.focus('#product-tile') + * I.see('#add-to-cart'); + * ``` + * + */ + async focus(locator, options = {}) { + const els = await this._locate(locator); + assertElementExists(els, locator, 'Element to focus'); + const el = els[0]; + await el.focus(options); + return this._waitForAction(); + } + /** * {{> dragAndDrop }} * From 1a48bd4ad76dd8192aedc712bec4165bcd25e068 Mon Sep 17 00:00:00 2001 From: EgorBodnar Date: Mon, 15 May 2023 20:12:23 +0800 Subject: [PATCH 06/35] DOC(new playwright api): add .focus() --- docs/helpers/Playwright.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/helpers/Playwright.md b/docs/helpers/Playwright.md index f6f611aa1..5ff284a02 100644 --- a/docs/helpers/Playwright.md +++ b/docs/helpers/Playwright.md @@ -779,6 +779,20 @@ I.fillField({css: 'form#login input[name=username]'}, 'John'); - `value` **([string][8] | [object][5])** text value to fill. ⚠️ returns a _promise_ which is synchronized internally by recorder +### focus + +{{> focus }} +Calls [focus][16] on the matching element. + +#### Parameters + +- `locator` +- `options` **any?** [Additional options][17] for available options object as 2nd argument.Examples:```js + I.dontSee('#add-to-cart'); + I.focus('#product-tile') + I.see('#add-to-cart'); + ``` + ### forceClick Perform an emulated click on a link or a button, given by a locator. From 30cff4ce8dbad6e01cb55064ac56d11148e0efb2 Mon Sep 17 00:00:00 2001 From: EgorBodnar Date: Mon, 15 May 2023 20:23:59 +0800 Subject: [PATCH 07/35] FEATURE(new playwright api): add .blur() --- lib/helper/Playwright.js | 47 +++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 954a08022..c603c3cda 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -927,6 +927,33 @@ class Playwright extends Helper { return this._waitForAction(); } + /** + * {{> blur }} + * Remove focus from a text input, button, etc + * Calls [blur](https://playwright.dev/docs/api/class-locator#locator-blur) on the element. + * @param {any} [options] [Additional options](https://playwright.dev/docs/api/class-locator#locator-blur) for available options object as 2nd argument. + * + * Examples: + * + * ```js + * I.blur('.text-area') + * ``` + * ```js + * //element `#product-tile` is focused + * I.see('#add-to-cart-btn'); + * I.blur('#product-tile') + * I.dontSee('#add-to-cart-btn'); + * ``` + * + */ + async blur(locator, options = {}) { + const els = await this._locate(locator); + assertElementExists(els, locator, 'Element to blur'); + const el = els[0]; + await el.blur(options); + return this._waitForAction(); + } + /** * {{> dragAndDrop }} * @@ -1521,26 +1548,6 @@ class Playwright extends Helper { return this._waitForAction(); } - /** - * {{> blur }} - * Remove focus from a text input - * @param {any} [options] [Additional options](https://playwright.dev/docs/api/class-locator#locator-blur) for available options object as 2nd argument. - * - * Examples: - * - * ```js - * I.blur('.text-area') - * ``` - * - */ - async blur(locator, options = {}) { - const els = await this._locate(locator); - assertElementExists(els, locator, 'Element to blur'); - const el = els[0]; - await el.blur(options); - return this._waitForAction(); - } - /** * {{> seeInField }} */ From 0e3e49b05123d90c79758d029074e3fb56209b3c Mon Sep 17 00:00:00 2001 From: EgorBodnar Date: Mon, 15 May 2023 20:25:08 +0800 Subject: [PATCH 08/35] chore: .focus() example extend --- lib/helper/Playwright.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index c603c3cda..ef844226b 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -913,9 +913,9 @@ class Playwright extends Helper { * Examples: * * ```js - * I.dontSee('#add-to-cart'); + * I.dontSee('#add-to-cart-btn'); * I.focus('#product-tile') - * I.see('#add-to-cart'); + * I.see('#add-to-cart-bnt'); * ``` * */ From c1bfe27548384066794f8f745da13e62ea54fef6 Mon Sep 17 00:00:00 2001 From: EgorBodnar Date: Mon, 15 May 2023 21:50:42 +0800 Subject: [PATCH 09/35] TEST(new playwright api): focus(), blur() --- .../app/view/form/focus_blur_elements.php | 54 +++++++++++++++++++ test/helper/Playwright_test.js | 27 ++++++++++ 2 files changed, 81 insertions(+) create mode 100644 test/data/app/view/form/focus_blur_elements.php diff --git a/test/data/app/view/form/focus_blur_elements.php b/test/data/app/view/form/focus_blur_elements.php new file mode 100644 index 000000000..bfb7c90e0 --- /dev/null +++ b/test/data/app/view/form/focus_blur_elements.php @@ -0,0 +1,54 @@ + + + + Test Focus and Blur + + + + + +Button not focused + +

+ + +Input field not focused + +

+ + +Textarea not focused + + + + + diff --git a/test/helper/Playwright_test.js b/test/helper/Playwright_test.js index 9e274c9d5..6b48a6372 100644 --- a/test/helper/Playwright_test.js +++ b/test/helper/Playwright_test.js @@ -184,6 +184,33 @@ describe('Playwright', function () { .then(() => I.dontSee('Hovered', '#show'))); }); + describe('#focus, #blur', () => { + it('should focus a button, field and textarea', () => I.amOnPage('/form/focus_blur_elements') + .then(() => I.focus('#button')) + .then(() => I.see('Button is focused', '#buttonMessage')) + .then(() => I.focus('#field')) + .then(() => I.see('Button not focused', '#buttonMessage')) + .then(() => I.see('Input field is focused', '#fieldMessage')) + .then(() => I.focus('#textarea')) + .then(() => I.see('Button not focused', '#buttonMessage')) + .then(() => I.see('Input field not focused', '#fieldMessage')) + .then(() => I.see('Textarea is focused', '#textareaMessage'))); + + it('should blur focused button, field and textarea', () => I.amOnPage('/form/focus_blur_elements') + .then(() => I.focus('#button')) + .then(() => I.see('Button is focused', '#buttonMessage')) + .then(() => I.blur('#button')) + .then(() => I.see('Button not focused', '#buttonMessage')) + .then(() => I.focus('#field')) + .then(() => I.see('Input field is focused', '#fieldMessage')) + .then(() => I.blur('#field')) + .then(() => I.see('Input field not focused', '#fieldMessage')) + .then(() => I.focus('#textarea')) + .then(() => I.see('Textarea is focused', '#textareaMessage')) + .then(() => I.focus('#textarea')) + .then(() => I.see('Textarea not focused', '#textareaMessage'))); + }); + describe('#switchToNextTab, #switchToPreviousTab, #openNewTab, #closeCurrentTab, #closeOtherTabs, #grabNumberOfOpenTabs', () => { it('should only have 1 tab open when the browser starts and navigates to the first page', () => I.amOnPage('/') .then(() => I.wait(1)) From e2e15ee2fabdf5cd5f1e64197ee91f12a7fa8c05 Mon Sep 17 00:00:00 2001 From: EgorBodnar Date: Mon, 15 May 2023 21:51:18 +0800 Subject: [PATCH 10/35] bump playwright version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8c0712a17..a18f2dd24 100644 --- a/package.json +++ b/package.json @@ -122,7 +122,7 @@ "json-server": "^0.10.1", "nightmare": "^3.0.2", "nodemon": "^1.19.4", - "playwright": "^1.23.2", + "playwright": "^1.32.3", "puppeteer": "^10.4.0", "qrcode-terminal": "^0.12.0", "rosie": "^1.6.0", From b1f629799c026dc27a8a34e7c8ee11f25b24ce8f Mon Sep 17 00:00:00 2001 From: EgorBodnar Date: Mon, 15 May 2023 22:12:40 +0800 Subject: [PATCH 11/35] FEATURE(new playwright api): add .clear() --- lib/helper/Playwright.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index ef844226b..c52c9ffbc 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -1530,11 +1530,36 @@ class Playwright extends Helper { /** * {{> clearField }} + * (deprecated) use `I.clear() instead` */ async clearField(field) { + console.log('I.clearField() is DEPRECATED: use `I.clear()` to clear field or text area'); return this.fillField(field, ''); } + /** + * {{> clear }} + * Clear the ,