Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test: add sanity test for playwright-electron (#3387)
Dmitry Gozman3a6b5cab4207
diff --git a/packages/installation-tests/electron-app.js b/packages/installation-tests/electron-app.jsnew file mode 100644index 0000000000..493b45a009--- /dev/null+++ b/packages/installation-tests/electron-app.js@@ -0,0 +1,3 @@+const { app } = require('electron');++app.on('window-all-closed', e => e.preventDefault());\ No newline at end of filediff --git a/packages/installation-tests/installation-tests.sh b/packages/installation-tests/installation-tests.shindex 570748470f..46e3fe1a34 100755--- a/packages/installation-tests/installation-tests.sh+++ b/packages/installation-tests/installation-tests.sh@@ -21,6 +21,7 @@ PLAYWRIGHT_TGZ="$(node ${PACKAGE_BUILDER} playwright ./playwright.tgz)"PLAYWRIGHT_CHROMIUM_TGZ="$(node ${PACKAGE_BUILDER} playwright-chromium ./playwright-chromium.tgz)"PLAYWRIGHT_WEBKIT_TGZ="$(node ${PACKAGE_BUILDER} playwright-webkit ./playwright-webkit.tgz)"PLAYWRIGHT_FIREFOX_TGZ="$(node ${PACKAGE_BUILDER} playwright-firefox ./playwright-firefox.tgz)"+PLAYWRIGHT_ELECTRON_TGZ="$(node ${PACKAGE_BUILDER} playwright-electron ./playwright-electron.tgz)"SCRIPTS_PATH="$(pwd -P)/.."TEST_ROOT="$(pwd -P)"@@ -33,6 +34,8 @@ function copy_test_scripts {cp "${SCRIPTS_PATH}/esm-playwright-chromium.mjs" .cp "${SCRIPTS_PATH}/esm-playwright-firefox.mjs" .cp "${SCRIPTS_PATH}/esm-playwright-webkit.mjs" .+ cp "${SCRIPTS_PATH}/sanity-electron.js" .+ cp "${SCRIPTS_PATH}/electron-app.js" .}function run_tests {@@ -45,6 +48,7 @@ function run_tests {test_playwright_firefox_should_worktest_playwright_global_installationtest_playwright_global_installation_cross_package+ test_playwright_electron_should_work}function test_typescript_types {@@ -228,6 +232,15 @@ function test_playwright_firefox_should_work {fi}+function test_playwright_electron_should_work {+ initialize_test "${FUNCNAME[0]}"++ npm install ${PLAYWRIGHT_ELECTRON_TGZ}+ npm install [email protected]+ copy_test_scripts+ xvfb-run --auto-servernum -- bash -c "node sanity-electron.js"+}+function initialize_test {cd ${TEST_ROOT}local TEST_NAME="./$1"diff --git a/packages/installation-tests/sanity-electron.js b/packages/installation-tests/sanity-electron.jsnew file mode 100644index 0000000000..85489243e6--- /dev/null+++ b/packages/installation-tests/sanity-electron.js@@ -0,0 +1,34 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++const playwright = require('playwright-electron');+const path = require('path');++(async () => {+ const electronName = process.platform === 'win32' ? 'electron.cmd' : 'electron';+ const electronPath = path.join(__dirname, 'node_modules', '.bin', electronName);+ const application = await playwright.electron.launch(electronPath, {+ args: [path.join(__dirname, 'electron-app.js')],+ });+ const appPath = await application.evaluate(async ({ app }) => app.getAppPath());+ await application.close();+ if (appPath !== __dirname)+ throw new Error(`Malformed app path: got "${appPath}", expected "${__dirname}"`);+ console.log(`playwright-electron SUCCESS`);+})().catch(err => {+ console.error(err);+ process.exit(1);+});diff --git a/packages/playwright-electron/index.js b/packages/playwright-electron/index.jsindex cc3f52771d..ab8f673350 100644--- a/packages/playwright-electron/index.js+++ b/packages/playwright-electron/index.js@@ -14,8 +14,8 @@* limitations under the License.*/-const { Playwright } = require('playwright-core/lib/server/playwright');-const { Electron } = require('playwright-core/lib/server/electron');+const { Playwright } = require('./lib/server/playwright');+const { Electron } = require('./lib/server/electron');const { setupInProcess } = require('./lib/rpc/inprocess');const playwright = new Playwright(__dirname, require('./browsers.json')['browsers']);