From 768b0452dca612229fb313f34943bf6cc1051f5b Mon Sep 17 00:00:00 2001 From: Calvin Bayer Date: Mon, 8 Mar 2021 19:47:53 +0100 Subject: [PATCH 1/9] feat: add capability to launch playwright-electron --- lib/helper/Playwright.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 5c8c41af4..09388959b 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -35,7 +35,7 @@ let defaultSelectorEnginesInitialized = false; const popupStore = new Popup(); const consoleLogStore = new Console(); -const availableBrowsers = ['chromium', 'webkit', 'firefox']; +const availableBrowsers = ['chromium', 'webkit', 'firefox', '_electron']; const { createValueEngine, createDisabledEngine } = require('./extras/PlaywrightPropEngine'); /** @@ -207,6 +207,7 @@ class Playwright extends Helper { this.isAuthenticated = false; this.sessionPages = {}; this.activeSessionName = ''; + this.isElectron = false; // override defaults with config this._setConfig(config); @@ -258,6 +259,7 @@ class Playwright extends Helper { ...this._getOptionsForBrowser(config), }; this.isRemoteBrowser = !!this.playwrightOptions.browserWSEndpoint; + this.isElectron = this.options.browser === '_electron'; this.userDataDir = this.playwrightOptions.userDataDir; popupStore.defaultAction = this.options.defaultPopupAction; } @@ -579,13 +581,19 @@ class Playwright extends Helper { if (this.userDataDir) { this.browserContext = this.browser; + } else if (this.isElectron) { + this.browserContext = this.browser.context(); } else { this.browserContext = await this.browser.newContext({ ignoreHTTPSErrors: this.options.ignoreHTTPSErrors, acceptDownloads: true, ...this.options.emulate });// Adding the HTTPSError ignore in the context so that we can ignore those errors } - const existingPages = await this.browserContext.pages(); - - const mainPage = existingPages[0] || await this.browserContext.newPage(); + let mainPage; + if (this.isElectron) { + mainPage = await this.browser.firstWindow(); + } else { + const existingPages = await this.browserContext.pages(); + mainPage = existingPages[0] || await this.browserContext.newPage(); + } targetCreatedHandler.call(this, mainPage); await this._setPage(mainPage); From 79a79e04a97ff66031be3937c120894cbd05a4d7 Mon Sep 17 00:00:00 2001 From: Calvin Bayer Date: Mon, 8 Mar 2021 19:50:36 +0100 Subject: [PATCH 2/9] test: add basic capabilities to test playwright-electron setup --- package.json | 3 ++- test/data/electron/index.html | 10 ++++++++++ test/data/electron/index.js | 12 ++++++++++++ test/helper/Playwright_test.js | 35 ++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/data/electron/index.html create mode 100644 test/data/electron/index.js diff --git a/package.json b/package.json index 0d25dce0a..ec8e0c582 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "contributor-faces": "^1.0.3", "documentation": "^12.3.0", "dtslint": "^3.6.12", + "electron": "^12.0.0", "eslint": "^6.8.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-plugin-import": "^2.22.1", @@ -120,7 +121,7 @@ "mocha-parallel-tests": "^2.3.0", "nightmare": "^3.0.2", "nodemon": "^1.19.4", - "playwright": "^1.6.2", + "playwright": "^1.9.1", "protractor": "^5.4.4", "puppeteer": "^4.0.0", "qrcode-terminal": "^0.12.0", diff --git a/test/data/electron/index.html b/test/data/electron/index.html new file mode 100644 index 000000000..5a8f46c75 --- /dev/null +++ b/test/data/electron/index.html @@ -0,0 +1,10 @@ + + + + + Hello World! + + +

Hello World!

+ + \ No newline at end of file diff --git a/test/data/electron/index.js b/test/data/electron/index.js new file mode 100644 index 000000000..f49b6a046 --- /dev/null +++ b/test/data/electron/index.js @@ -0,0 +1,12 @@ +const { app, BrowserWindow } = require('electron'); + +function createWindow() { + const window = new BrowserWindow({ + width: 500, + height: 700, + }); + + window.loadFile('index.html'); +} + +app.whenReady().then(createWindow); diff --git a/test/helper/Playwright_test.js b/test/helper/Playwright_test.js index 32efbe4b9..83fd8b3b4 100644 --- a/test/helper/Playwright_test.js +++ b/test/helper/Playwright_test.js @@ -906,3 +906,38 @@ describe('Playwright - PERSISTENT', () => { assert.equal(I._getType(), 'BrowserContext'); }); }); + +describe('Playwright - Electron', () => { + before(() => { + global.codecept_dir = path.join(__dirname, '/../data'); + + I = new Playwright({ + show: true, + waitForTimeout: 5000, + waitForAction: 500, + restart: true, + browser: '_electron', + _electron: { + executablePath: require('electron'), + args: [path.join(codecept_dir, '/electron/')], + }, + defaultPopupAction: 'accept', + }); + I._init(); + return I._beforeSuite(); + }); + + beforeEach(() => { + webApiTests.init({ + I, siteUrl, + }); + return I._before().then(() => { + page = I.page; + browser = I.browser; + }); + }); + + afterEach(() => { + return I._after(); + }); +}); From 3cdab9ec4db2e217ae4aaf17ac2c33ddbc440fa8 Mon Sep 17 00:00:00 2001 From: Calvin Bayer Date: Mon, 8 Mar 2021 19:51:26 +0100 Subject: [PATCH 3/9] feat: throw an error for amOnPage in electron setup --- lib/helper/Playwright.js | 8 ++++++++ test/helper/Playwright_test.js | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 09388959b..9dfa99c3c 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -324,6 +324,11 @@ class Playwright extends Helper { async _after() { if (!this.isRunning) return; + if (this.isElectron) { + this.browser.close(); + return; + } + // close other sessions try { const contexts = await this.browser.contexts(); @@ -664,6 +669,9 @@ class Playwright extends Helper { * {{> amOnPage }} */ async amOnPage(url) { + if (this.isElectron) { + throw new Error('Cannot open pages inside an Electron container'); + } if (!(/^\w+\:\/\//.test(url))) { url = this.options.url + url; } diff --git a/test/helper/Playwright_test.js b/test/helper/Playwright_test.js index 83fd8b3b4..8204c08f2 100644 --- a/test/helper/Playwright_test.js +++ b/test/helper/Playwright_test.js @@ -940,4 +940,15 @@ describe('Playwright - Electron', () => { afterEach(() => { return I._after(); }); + + describe('#amOnPage', () => { + it('should throw an error', async () => { + try { + await I.amOnPage('/'); + throw Error('It should never get this far'); + } catch (e) { + e.message.should.include('Cannot open pages inside an Electron container'); + } + }); + }); }); From fb5f414c5dab46159b040558d6791b349e563a17 Mon Sep 17 00:00:00 2001 From: Calvin Bayer Date: Fri, 12 Mar 2021 16:23:47 +0100 Subject: [PATCH 4/9] fix: throw error for unsupported operations in electron --- lib/helper/Playwright.js | 12 ++++++++++ test/helper/Playwright_test.js | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 9dfa99c3c..3c0a8461b 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -923,6 +923,9 @@ class Playwright extends Helper { * @param {number} [num=1] */ async switchToNextTab(num = 1) { + if (this.isElectron) { + throw new Error('Cannot switch tabs inside an Electron container'); + } const pages = await this.browserContext.pages(); const index = pages.indexOf(this.page); @@ -946,6 +949,9 @@ class Playwright extends Helper { * @param {number} [num=1] */ async switchToPreviousTab(num = 1) { + if (this.isElectron) { + throw new Error('Cannot switch tabs inside an Electron container'); + } const pages = await this.browserContext.pages(); const index = pages.indexOf(this.page); this.withinLocator = null; @@ -967,6 +973,9 @@ class Playwright extends Helper { * ``` */ async closeCurrentTab() { + if (this.isElectron) { + throw new Error('Cannot close current tab inside an Electron container'); + } const oldPage = this.page; await this.switchToPreviousTab(); await oldPage.close(); @@ -1005,6 +1014,9 @@ class Playwright extends Helper { * ``` */ async openNewTab(options) { + if (this.isElectron) { + throw new Error('Cannot open new tabs inside an Electron container'); + } await this._setPage(await this.browserContext.newPage(options)); return this._waitForAction(); } diff --git a/test/helper/Playwright_test.js b/test/helper/Playwright_test.js index 8204c08f2..22669d087 100644 --- a/test/helper/Playwright_test.js +++ b/test/helper/Playwright_test.js @@ -951,4 +951,48 @@ describe('Playwright - Electron', () => { } }); }); + + describe('#openNewTab', () => { + it('should throw an error', async () => { + try { + await I.openNewTab(); + throw Error('It should never get this far'); + } catch (e) { + e.message.should.include('Cannot open new tabs inside an Electron container'); + } + }); + }); + + describe('#switchToNextTab', () => { + it('should throw an error', async () => { + try { + await I.switchToNextTab(); + throw Error('It should never get this far'); + } catch (e) { + e.message.should.include('Cannot switch tabs inside an Electron container'); + } + }); + }); + + describe('#switchToPreviousTab', () => { + it('should throw an error', async () => { + try { + await I.switchToNextTab(); + throw Error('It should never get this far'); + } catch (e) { + e.message.should.include('Cannot switch tabs inside an Electron container'); + } + }); + }); + + describe('#closeCurrentTab', () => { + it('should throw an error', async () => { + try { + await I.closeCurrentTab(); + throw Error('It should never get this far'); + } catch (e) { + e.message.should.include('Cannot close current tab inside an Electron container'); + } + }); + }); }); From cf334150e524a549bcf77ef95a4d377d0da35e3a Mon Sep 17 00:00:00 2001 From: Calvin Bayer Date: Mon, 15 Mar 2021 22:25:26 +0100 Subject: [PATCH 5/9] feat: add support for multi sessions --- lib/helper/Playwright.js | 18 +++++++-- .../codecept.Playwright-Electron.js | 37 +++++++++++++++++++ test/acceptance/session_test.js | 9 +++++ test/data/electron/index.js | 1 + 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 test/acceptance/codecept.Playwright-Electron.js diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 3c0a8461b..5ecd70de4 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -208,6 +208,7 @@ class Playwright extends Helper { this.sessionPages = {}; this.activeSessionName = ''; this.isElectron = false; + this.electronSessions = []; // override defaults with config this._setConfig(config); @@ -326,6 +327,7 @@ class Playwright extends Helper { if (this.isElectron) { this.browser.close(); + this.electronSessions.forEach(session => session.close()); return; } @@ -384,12 +386,22 @@ class Playwright extends Helper { this.debugSection('New Context', config ? JSON.stringify(config) : 'opened'); this.activeSessionName = sessionName; - const bc = await this.browser.newContext(config); - const page = await bc.newPage(); + let browserContext; + let page; + if (this.isElectron) { + const browser = await playwright[this.options.browser].launch(this.playwrightOptions); + this.electronSessions.push(browser); + browserContext = browser.context(); + page = await browser.firstWindow(); + } else { + browserContext = await this.browser.newContext(config); + page = await browserContext.newPage(); + } + targetCreatedHandler.call(this, page); this._setPage(page); // Create a new page inside context. - return bc; + return browserContext; }, stop: async () => { // is closed by _after diff --git a/test/acceptance/codecept.Playwright-Electron.js b/test/acceptance/codecept.Playwright-Electron.js new file mode 100644 index 000000000..d908e6bb3 --- /dev/null +++ b/test/acceptance/codecept.Playwright-Electron.js @@ -0,0 +1,37 @@ +const path = require('path'); +const TestHelper = require('../support/TestHelper'); + +module.exports.config = { + tests: './*_test.js', + timeout: 10000, + output: './output', + grep: '@Playwright-Electron', + helpers: { + Playwright: { + url: TestHelper.siteUrl(), + show: false, + browser: '_electron', + _electron: { + executablePath: require('electron'), + args: [path.join('data/', 'electron/')], + }, + }, + ScreenshotSessionHelper: { + require: '../support/ScreenshotSessionHelper.js', + outputPath: 'test/acceptance/output', + }, + }, + include: {}, + bootstrap: false, + mocha: {}, + plugins: { + screenshotOnFail: { + enabled: true, + }, + }, + name: 'acceptance', + gherkin: { + features: './gherkin/*.feature', + steps: ['./gherkin/steps.js'], + }, +}; diff --git a/test/acceptance/session_test.js b/test/acceptance/session_test.js index 29f94a17b..39dafdd67 100644 --- a/test/acceptance/session_test.js +++ b/test/acceptance/session_test.js @@ -1,4 +1,6 @@ const assert = require('assert'); +const session = require('../../lib/session'); +const { addWorker } = require('../../lib/workerStorage'); const { event } = codeceptjs; @@ -15,6 +17,13 @@ Scenario('simple session @WebDriverIO @Protractor @Puppeteer @Playwright', ({ I I.seeInCurrentUrl('/info'); }); +Scenario('simple session @Playwright-Electron', ({ I }) => { + I.see('Hello World!'); + session('john', () => { + I.see('Hello World!'); + }); +}); + Scenario('screenshots reflect the current page of current session @Puppeteer @Playwright @WebDriver', async ({ I }) => { I.amOnPage('/'); I.saveScreenshot('session_default_1.png'); diff --git a/test/data/electron/index.js b/test/data/electron/index.js index f49b6a046..cc56d244f 100644 --- a/test/data/electron/index.js +++ b/test/data/electron/index.js @@ -4,6 +4,7 @@ function createWindow() { const window = new BrowserWindow({ width: 500, height: 700, + show: false, }); window.loadFile('index.html'); From f9d3634367b83b63dff01cd4e341cd87409520ae Mon Sep 17 00:00:00 2001 From: Calvin Bayer Date: Mon, 15 Mar 2021 22:35:45 +0100 Subject: [PATCH 6/9] refactor: rename browser from _electron to electron --- lib/helper/Playwright.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 5ecd70de4..844977d35 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -35,7 +35,7 @@ let defaultSelectorEnginesInitialized = false; const popupStore = new Popup(); const consoleLogStore = new Console(); -const availableBrowsers = ['chromium', 'webkit', 'firefox', '_electron']; +const availableBrowsers = ['chromium', 'webkit', 'firefox', 'electron']; const { createValueEngine, createDisabledEngine } = require('./extras/PlaywrightPropEngine'); /** @@ -260,7 +260,7 @@ class Playwright extends Helper { ...this._getOptionsForBrowser(config), }; this.isRemoteBrowser = !!this.playwrightOptions.browserWSEndpoint; - this.isElectron = this.options.browser === '_electron'; + this.isElectron = this.options.browser === 'electron'; this.userDataDir = this.playwrightOptions.userDataDir; popupStore.defaultAction = this.options.defaultPopupAction; } @@ -273,7 +273,7 @@ class Playwright extends Helper { }, { name: 'browser', - message: 'Browser in which testing will be performed. Possible options: chromium, firefox or webkit', + message: 'Browser in which testing will be performed. Possible options: chromium, firefox, webkit or electron', default: 'chromium', }, ]; @@ -389,7 +389,7 @@ class Playwright extends Helper { let browserContext; let page; if (this.isElectron) { - const browser = await playwright[this.options.browser].launch(this.playwrightOptions); + const browser = await playwright._electron.launch(this.playwrightOptions); this.electronSessions.push(browser); browserContext = browser.context(); page = await browser.firstWindow(); @@ -572,7 +572,9 @@ class Playwright extends Helper { } async _startBrowser() { - if (this.isRemoteBrowser) { + if (this.isElectron) { + this.browser = await playwright._electron.launch(this.playwrightOptions); + } else if (this.isRemoteBrowser) { try { this.browser = await playwright[this.options.browser].connect(this.playwrightOptions.browserWSEndpoint); } catch (err) { @@ -581,13 +583,9 @@ class Playwright extends Helper { } throw err; } - } - - if (!this.isRemoteBrowser && this.userDataDir) { + } else if (this.userDataDir) { this.browser = await playwright[this.options.browser].launchPersistentContext(this.userDataDir, this.playwrightOptions); - } - - if (!this.isRemoteBrowser && !this.userDataDir) { + } else { this.browser = await playwright[this.options.browser].launch(this.playwrightOptions); } @@ -596,10 +594,10 @@ class Playwright extends Helper { this.debugSection('Url', target.url()); }); - if (this.userDataDir) { - this.browserContext = this.browser; - } else if (this.isElectron) { + if (this.isElectron) { this.browserContext = this.browser.context(); + } else if (this.userDataDir) { + this.browserContext = this.browser; } else { this.browserContext = await this.browser.newContext({ ignoreHTTPSErrors: this.options.ignoreHTTPSErrors, acceptDownloads: true, ...this.options.emulate });// Adding the HTTPSError ignore in the context so that we can ignore those errors } From db79d16d0523e8e133f5da2940741b514de031fe Mon Sep 17 00:00:00 2001 From: Calvin Bayer Date: Sat, 27 Mar 2021 19:34:57 +0100 Subject: [PATCH 7/9] docs: add electron to playwright docs --- docs/playwright.md | 51 ++++++++++++++++++++++++++++++++++++++-- lib/helper/Playwright.js | 3 ++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/docs/playwright.md b/docs/playwright.md index da145a752..1b666dd1c 100644 --- a/docs/playwright.md +++ b/docs/playwright.md @@ -5,7 +5,7 @@ title: Testing with Playwright # Testing with Playwright -Playwright is a Node library to automate the [Chromium](https://www.chromium.org/Home), [WebKit](https://webkit.org/) and [Firefox](https://www.mozilla.org/en-US/firefox/new/) browsers with a single API. It enables **cross-browser** web automation that is **ever-green**, **capable**, **reliable** and **fast**. +Playwright is a Node library to automate the [Chromium](https://www.chromium.org/Home), [WebKit](https://webkit.org/) and [Firefox](https://www.mozilla.org/en-US/firefox/new/) browsers as well as [Electron](https://www.electronjs.org/) apps with a single API. It enables **cross-browser** web automation that is **ever-green**, **capable**, **reliable** and **fast**. Playwright was built similarly to [Puppeteer](https://github.com/puppeteer/puppeteer), using its API and so is very different in usage. However, Playwright has cross browser support with better design for test automaiton. @@ -202,7 +202,7 @@ CodeceptJS allows you to implement custom actions like `I.createTodo` or use **P ## Multi Session Testing -TO launch additional browser context (or incognito window) use `session` command. +To launch additional browser context (or incognito window) use `session` command. ```js Scenario('I try to open this site as anonymous user', ({ I }) => { @@ -217,6 +217,53 @@ Scenario('I try to open this site as anonymous user', ({ I }) => { > ℹ Learn more about [multi-session testing](/basics/#multiple-sessions) +## Electron Testing + +CodeceptJS allows you to make use of [Playwright's Electron flavor](https://github.com/microsoft/playwright/blob/master/packages/playwright-electron/README.md). +To use this functionality, all you need to do is set the browser to `electron` in the CodeceptJS configuration file and, according to the [Playwright BrowserType API](https://playwright.dev/docs/api/class-browsertype/#browsertypelaunchoptions), set the launch options to point to your Electron application. + +`main.js` - main Electron application file +```js +const { app, BrowserWindow } = require("electron"); + +function createWindow() { + const window = new BrowserWindow({ width: 800, height: 600 }); + window.loadURL("https://example.com"); +} + +app.whenReady().then(createWindow); +``` + +`codecept.conf.js` - CodeceptJS configuration file +```js +const path = require("path"); + +exports.config = { + helpers: { + Playwright: { + browser: "electron", + electron: { + executablePath: require("electron"), + args: [path.join(__dirname, "main.js")], + }, + }, + }, + // rest of config +} +``` + +### Headless Mode + +With Electron, headless mode must be set when creating the window. Therefore, CodeceptJS's `show` configuration parameter will not work. However, you can set it in the `main.js` file as shown below: + +```js +function createWindow() { + const window = new BrowserWindow({ width: 800, height: 600, show: false }); + window.loadURL("https://example.com"); +} +``` + + ## Device Emulation Playwright can emulate browsers of mobile devices. Instead of paying for expensive devices for mobile tests you can adjust Playwright settings so it could emulate mobile browsers on iPhone, Samsung Galaxy, etc. diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 844977d35..9c4c25ecd 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -58,7 +58,7 @@ const { createValueEngine, createDisabledEngine } = require('./extras/Playwright * This helper should be configured in codecept.json or codecept.conf.js * * * `url`: base url of website to be tested - * * `browser`: a browser to test on, either: `chromium`, `firefox`, `webkit`. Default: chromium. + * * `browser`: a browser to test on, either: `chromium`, `firefox`, `webkit`, `electron`. Default: chromium. * * `show`: (optional, default: false) - show browser window. * * `restart`: (optional, default: true) - restart browser between tests. * * `disableScreenshots`: (optional, default: false) - don't save screenshot on failure. @@ -77,6 +77,7 @@ const { createValueEngine, createDisabledEngine } = require('./extras/Playwright * * `userAgent`: (optional) user-agent string. * * `manualStart`: (optional, default: false) - do not start browser before a test, start it manually inside a helper with `this.helpers["Playwright"]._startBrowser()`. * * `chromium`: (optional) pass additional chromium options + * * `electron`: (optional) pass additional electron options * * #### Example #1: Wait for 0 network connections. * From 2c65fe2e4f2af4da8e29b849130fb048eaf2e486 Mon Sep 17 00:00:00 2001 From: Calvin Bayer Date: Sun, 28 Mar 2021 10:51:23 +0200 Subject: [PATCH 8/9] test: fix session test --- .github/workflows/playwright.yml | 2 ++ .../codecept.Playwright-Electron.js | 15 ++++---------- test/acceptance/session_test.js | 4 +--- test/helper/Playwright_test.js | 20 ++----------------- 4 files changed, 9 insertions(+), 32 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 46eda609e..8f106a3e3 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -39,6 +39,8 @@ jobs: run: "php -S 127.0.0.1:8000 -t test/data/app &" - name: run chromium tests run: "./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug" + - name: run electron tests + run: "./bin/codecept.js run -c test/acceptance/codecept.Playwright-Electron.js --grep @ElectronPlaywright --debug" - name: run firefox tests run: "BROWSER=firefox node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug" - name: run webkit tests diff --git a/test/acceptance/codecept.Playwright-Electron.js b/test/acceptance/codecept.Playwright-Electron.js index d908e6bb3..81e3dffc5 100644 --- a/test/acceptance/codecept.Playwright-Electron.js +++ b/test/acceptance/codecept.Playwright-Electron.js @@ -1,19 +1,16 @@ const path = require('path'); -const TestHelper = require('../support/TestHelper'); module.exports.config = { tests: './*_test.js', timeout: 10000, output: './output', - grep: '@Playwright-Electron', + grep: '@ElectronPlaywright', helpers: { Playwright: { - url: TestHelper.siteUrl(), - show: false, - browser: '_electron', - _electron: { + browser: 'electron', + electron: { executablePath: require('electron'), - args: [path.join('data/', 'electron/')], + args: [path.join('test/data/', 'electron/')], }, }, ScreenshotSessionHelper: { @@ -30,8 +27,4 @@ module.exports.config = { }, }, name: 'acceptance', - gherkin: { - features: './gherkin/*.feature', - steps: ['./gherkin/steps.js'], - }, }; diff --git a/test/acceptance/session_test.js b/test/acceptance/session_test.js index 39dafdd67..486845658 100644 --- a/test/acceptance/session_test.js +++ b/test/acceptance/session_test.js @@ -1,6 +1,4 @@ const assert = require('assert'); -const session = require('../../lib/session'); -const { addWorker } = require('../../lib/workerStorage'); const { event } = codeceptjs; @@ -17,7 +15,7 @@ Scenario('simple session @WebDriverIO @Protractor @Puppeteer @Playwright', ({ I I.seeInCurrentUrl('/info'); }); -Scenario('simple session @Playwright-Electron', ({ I }) => { +Scenario('simple session @ElectronPlaywright', ({ I }) => { I.see('Hello World!'); session('john', () => { I.see('Hello World!'); diff --git a/test/helper/Playwright_test.js b/test/helper/Playwright_test.js index 22669d087..9a8dd84d3 100644 --- a/test/helper/Playwright_test.js +++ b/test/helper/Playwright_test.js @@ -912,35 +912,19 @@ describe('Playwright - Electron', () => { global.codecept_dir = path.join(__dirname, '/../data'); I = new Playwright({ - show: true, waitForTimeout: 5000, waitForAction: 500, restart: true, - browser: '_electron', - _electron: { + browser: 'electron', + electron: { executablePath: require('electron'), args: [path.join(codecept_dir, '/electron/')], }, - defaultPopupAction: 'accept', }); I._init(); return I._beforeSuite(); }); - beforeEach(() => { - webApiTests.init({ - I, siteUrl, - }); - return I._before().then(() => { - page = I.page; - browser = I.browser; - }); - }); - - afterEach(() => { - return I._after(); - }); - describe('#amOnPage', () => { it('should throw an error', async () => { try { From f022053899b66ade9a035b73e505f072e90ced30 Mon Sep 17 00:00:00 2001 From: Calvin Bayer Date: Tue, 30 Mar 2021 16:40:13 +0200 Subject: [PATCH 9/9] test: remove failing test --- .github/workflows/playwright.yml | 2 -- .../codecept.Playwright-Electron.js | 30 ------------------- test/acceptance/session_test.js | 7 ----- 3 files changed, 39 deletions(-) delete mode 100644 test/acceptance/codecept.Playwright-Electron.js diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 8f106a3e3..46eda609e 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -39,8 +39,6 @@ jobs: run: "php -S 127.0.0.1:8000 -t test/data/app &" - name: run chromium tests run: "./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug" - - name: run electron tests - run: "./bin/codecept.js run -c test/acceptance/codecept.Playwright-Electron.js --grep @ElectronPlaywright --debug" - name: run firefox tests run: "BROWSER=firefox node ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug" - name: run webkit tests diff --git a/test/acceptance/codecept.Playwright-Electron.js b/test/acceptance/codecept.Playwright-Electron.js deleted file mode 100644 index 81e3dffc5..000000000 --- a/test/acceptance/codecept.Playwright-Electron.js +++ /dev/null @@ -1,30 +0,0 @@ -const path = require('path'); - -module.exports.config = { - tests: './*_test.js', - timeout: 10000, - output: './output', - grep: '@ElectronPlaywright', - helpers: { - Playwright: { - browser: 'electron', - electron: { - executablePath: require('electron'), - args: [path.join('test/data/', 'electron/')], - }, - }, - ScreenshotSessionHelper: { - require: '../support/ScreenshotSessionHelper.js', - outputPath: 'test/acceptance/output', - }, - }, - include: {}, - bootstrap: false, - mocha: {}, - plugins: { - screenshotOnFail: { - enabled: true, - }, - }, - name: 'acceptance', -}; diff --git a/test/acceptance/session_test.js b/test/acceptance/session_test.js index 486845658..29f94a17b 100644 --- a/test/acceptance/session_test.js +++ b/test/acceptance/session_test.js @@ -15,13 +15,6 @@ Scenario('simple session @WebDriverIO @Protractor @Puppeteer @Playwright', ({ I I.seeInCurrentUrl('/info'); }); -Scenario('simple session @ElectronPlaywright', ({ I }) => { - I.see('Hello World!'); - session('john', () => { - I.see('Hello World!'); - }); -}); - Scenario('screenshots reflect the current page of current session @Puppeteer @Playwright @WebDriver', async ({ I }) => { I.amOnPage('/'); I.saveScreenshot('session_default_1.png');