/**
* 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 path = require('path');
const config = require('../test.config');
const utils = require('../utils');
const electronName = process.platform === 'win32' ? 'electron.cmd' : 'electron';
describe('Electron', function() {
beforeEach(async (state, testRun) => {
const electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', electronName);
state.logger = utils.createTestLogger(config.dumpLogOnFailure, testRun);
state.application = await playwright.electron.launch(electronPath, {
args: [path.join(__dirname, 'testApp.js')],
// This is for our own extensive protocol logging, customers don't need it.
logger: state.logger,
});
});
afterEach(async (state, testRun) => {
await state.application.close();
state.logger.setTestRun(null);
});
it('should script application', async ({ application }) => {
const appPath = await application.evaluate(async ({ app }) => app.getAppPath());
expect(appPath).toContain('electron');
});
it('should create window', async ({ application }) => {
const [ page ] = await Promise.all([
application.waitForEvent('window'),
application.evaluate(({ BrowserWindow }) => {
const window = new BrowserWindow({ width: 800, height: 600 });
window.loadURL('data:text/html,