From aaffec14d94267b396f94c8de5f7fc21c1400319 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Tue, 4 Jul 2023 16:19:46 +0200 Subject: [PATCH 1/2] fix(playwright): init command for playwright electron --- docs/helpers/Playwright.md | 20 ++++++++++++++++++-- docs/plugins.md | 4 ++-- lib/command/init.js | 10 ++++++++++ lib/helper/Playwright.js | 38 +++++++++++++++++++++++++++++++------- 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/docs/helpers/Playwright.md b/docs/helpers/Playwright.md index 48d00dfaf..a6bf7744a 100644 --- a/docs/helpers/Playwright.md +++ b/docs/helpers/Playwright.md @@ -33,13 +33,13 @@ Using playwright-core package, will prevent the download of browser binaries and ## Configuration -This helper should be configured in codecept.conf.js +This helper should be configured in codecept.conf.(js|ts) Type: [object][5] ### Properties -- `url` **[string][8]** base url of website to be tested +- `url` **[string][8]?** base url of website to be tested - `browser` **(`"chromium"` | `"firefox"` | `"webkit"` | `"electron"`)?** a browser to test on, either: `chromium`, `firefox`, `webkit`, `electron`. Default: chromium. - `show` **[boolean][30]?** show browser window. - `restart` **([string][8] | [boolean][30])?** restart strategy between tests. Possible values:- 'context' or **false** - restarts [browser context][37] but keeps running browser. Recommended by Playwright team to keep tests isolated. @@ -217,6 +217,22 @@ const { devices } = require('playwright'); } ``` +- #### Example #9: Launch electron test + +```js +{ + helpers: { + Playwright: { + browser: 'electron', + electron: { + executablePath: require("electron"), + args: [path.join('../', "main.js")], + }, + } + }, +} +``` + Note: When connecting to remote browser `show` and specific `chrome` options (e.g. `headless` or `devtools`) are ignored. ## Access From Helpers diff --git a/docs/plugins.md b/docs/plugins.md index d4ba014c1..8327b3e1f 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -483,7 +483,7 @@ I.click('=sign-up'); // matches => [data-qa=sign-up],[data-test=sign-up] Prints errors found in HTML code after each failed test. -It scans HTML and searches for elements with error classes. +It scans HTML and searches for elements with error classes. If an element found prints a text from it to console and adds as artifact to the test. Enable this plugin in config: @@ -608,7 +608,7 @@ Scenario Outline: ... ## heal -Self-healing tests with OpenAI. +Self-healing tests with OpenAI. This plugin is experimental and requires OpenAI API key. diff --git a/lib/command/init.js b/lib/command/init.js index df1e2a4ab..2dc276fc5 100644 --- a/lib/command/init.js +++ b/lib/command/init.js @@ -317,6 +317,16 @@ module.exports = function (initPath) { print('Configure helpers...'); inquirer.prompt(helperConfigs).then((helperResult) => { + if (helperResult.Playwright_browser === 'electron') { + delete helperResult.Playwright_url; + delete helperResult.Playwright_show; + + helperResult.Playwright_electron = { + executablePath: '// require("electron") or require("electron-forge")', + args: ['path/to/your/main.js'], + }; + } + Object.keys(helperResult).forEach((key) => { const parts = key.split('_'); const helperName = parts[0]; diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 2e3143880..459f276d0 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -52,13 +52,13 @@ const pathSeparator = path.sep; /** * ## Configuration * - * This helper should be configured in codecept.conf.js + * This helper should be configured in codecept.conf.(js|ts) * * @typedef PlaywrightConfig * @type {object} - * @prop {string} url - base url of website to be tested + * @prop {string} [url] - base url of website to be tested * @prop {'chromium' | 'firefox'| 'webkit' | 'electron'} [browser='chromium'] - a browser to test on, either: `chromium`, `firefox`, `webkit`, `electron`. Default: chromium. - * @prop {boolean} [show=false] - show browser window. + * @prop {boolean} [show=true] - show browser window. * @prop {string|boolean} [restart=false] - restart strategy between tests. Possible values: * * 'context' or **false** - restarts [browser context](https://playwright.dev/docs/api/class-browsercontext) but keeps running browser. Recommended by Playwright team to keep tests isolated. * * 'browser' or **true** - closes browser and opens it again between tests. @@ -260,6 +260,22 @@ const config = {}; * } * ``` * + * * #### Example #9: Launch electron test + * + * ```js + * { + * helpers: { + * Playwright: { + * browser: 'electron', + * electron: { + * executablePath: require("electron"), + * args: [path.join('../', "main.js")], + * }, + * } + * }, + * } + * ``` + * * Note: When connecting to remote browser `show` and specific `chrome` options (e.g. `headless` or `devtools`) are ignored. * * ## Access From Helpers @@ -373,15 +389,23 @@ class Playwright extends Helper { static _config() { return [ - { name: 'url', message: 'Base url of site to be tested', default: 'http://localhost' }, - { - name: 'show', message: 'Show browser window', default: true, type: 'confirm', - }, { name: 'browser', message: 'Browser in which testing will be performed. Possible options: chromium, firefox, webkit or electron', default: 'chromium', }, + { + name: 'url', + message: 'Base url of site to be tested', + default: 'http://localhost', + when: (answers) => answers.Playwright_browser !== 'electron' + }, + { + name: 'show', + message: 'Show browser window', + default: true, type: 'confirm', + when: (answers) => answers.Playwright_browser !== 'electron' + }, ]; } From 68772c28ba772429471a63718e2549d1d14cc9ef Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Tue, 4 Jul 2023 16:24:02 +0200 Subject: [PATCH 2/2] fix: improve timeout --- test/unit/worker_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/worker_test.js b/test/unit/worker_test.js index 49b2dfe6f..681c69540 100644 --- a/test/unit/worker_test.js +++ b/test/unit/worker_test.js @@ -8,7 +8,7 @@ describe('Workers', () => { }); beforeEach(function () { - this.timeout(20000); + this.timeout(40000); }); it('should run simple worker', (done) => {