/**
* 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 electronName = process.platform === 'win32' ? 'electron.cmd' : 'electron';
describe('Electron', function() {
beforeEach(async (state, testRun) => {
const electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', electronName);
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: {
isEnabled: (name, severity) => {
return name === 'browser' ||
(name === 'protocol' && config.dumpProtocolOnFailure);
},
log: (name, severity, message, args) => {
if (name === 'browser') {
if (severity === 'warning')
testRun.log(`\x1b[31m[browser]\x1b[0m ${message}`)
else
testRun.log(`\x1b[33m[browser]\x1b[0m ${message}`)
} else if (name === 'protocol' && config.dumpProtocolOnFailure) {
testRun.log(`\x1b[32m[protocol]\x1b[0m ${message}`)
}
}
}
});
});
afterEach(async (state, testRun) => {
await state.application.close();
// This is for our own extensive protocol logging, customers don't need it.
if (config.dumpProtocolOnFailure) {
if (testRun.ok())
testRun.output().splice(0);
}
});
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,