Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(playwright): init command for playwright electron #3733

Merged
merged 2 commits into from
Jul 7, 2023
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
20 changes: 18 additions & 2 deletions docs/helpers/Playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.

Expand Down
10 changes: 10 additions & 0 deletions lib/command/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
38 changes: 31 additions & 7 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
},
];
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/worker_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Workers', () => {
});

beforeEach(function () {
this.timeout(20000);
this.timeout(40000);
});

it('should run simple worker', (done) => {
Expand Down