feat(electron): add app.firstWindow convenience method (#2195)
This commit is contained in:
parent
fdc9ce8e07
commit
3f8dfed67f
|
|
@ -82,7 +82,7 @@ describe('Sanity checks', function () {
|
||||||
|
|
||||||
it('sanity checks', async () => {
|
it('sanity checks', async () => {
|
||||||
// Wait for the first window to appear.
|
// Wait for the first window to appear.
|
||||||
const window = await this.app.waitForEvent('window');
|
const window = await this.app.firstWindow();
|
||||||
|
|
||||||
// Assert window title.
|
// Assert window title.
|
||||||
assert.equal(await window.title(), 'Hello World!');
|
assert.equal(await window.title(), 'Hello World!');
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ export class ElectronApplication extends ExtendedEventEmitter {
|
||||||
this._windows.delete(page);
|
this._windows.delete(page);
|
||||||
});
|
});
|
||||||
this._windows.add(page);
|
this._windows.add(page);
|
||||||
|
await page.waitForLoadState('domcontentloaded');
|
||||||
this.emit(ElectronEvents.ElectronApplication.Window, page);
|
this.emit(ElectronEvents.ElectronApplication.Window, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,6 +91,12 @@ export class ElectronApplication extends ExtendedEventEmitter {
|
||||||
return [...this._windows];
|
return [...this._windows];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async firstWindow(): Promise<Page> {
|
||||||
|
if (this._windows.size)
|
||||||
|
return this._windows.values().next().value;
|
||||||
|
return this.waitForEvent('window');
|
||||||
|
}
|
||||||
|
|
||||||
async newBrowserWindow(options: any): Promise<Page> {
|
async newBrowserWindow(options: any): Promise<Page> {
|
||||||
const windowId = await this.evaluate(async ({ BrowserWindow }, options) => {
|
const windowId = await this.evaluate(async ({ BrowserWindow }, options) => {
|
||||||
const win = new BrowserWindow(options);
|
const win = new BrowserWindow(options);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ describe('Electron', function() {
|
||||||
const electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', electronName);
|
const electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', electronName);
|
||||||
state.application = await playwright.electron.launch(electronPath, {
|
state.application = await playwright.electron.launch(electronPath, {
|
||||||
args: [path.join(__dirname, 'testApp.js')],
|
args: [path.join(__dirname, 'testApp.js')],
|
||||||
|
// This is for our own extensive protocol logging, customers don't need it.
|
||||||
logger: {
|
logger: {
|
||||||
isEnabled: (name, severity) => {
|
isEnabled: (name, severity) => {
|
||||||
return name === 'browser' ||
|
return name === 'browser' ||
|
||||||
|
|
@ -44,6 +45,7 @@ describe('Electron', function() {
|
||||||
});
|
});
|
||||||
afterEach(async (state, testRun) => {
|
afterEach(async (state, testRun) => {
|
||||||
await state.application.close();
|
await state.application.close();
|
||||||
|
// This is for our own extensive protocol logging, customers don't need it.
|
||||||
if (config.dumpProtocolOnFailure) {
|
if (config.dumpProtocolOnFailure) {
|
||||||
if (testRun.ok())
|
if (testRun.ok())
|
||||||
testRun.output().splice(0);
|
testRun.output().splice(0);
|
||||||
|
|
@ -115,9 +117,17 @@ describe('Electron', function() {
|
||||||
await page.goto('data:text/html,<script>window.result = add(20, 22);</script>');
|
await page.goto('data:text/html,<script>window.result = add(20, 22);</script>');
|
||||||
expect(await page.evaluate(() => result)).toBe(42);
|
expect(await page.evaluate(() => result)).toBe(42);
|
||||||
});
|
});
|
||||||
|
it('should wait for first window', async ({ application }) => {
|
||||||
|
application.evaluate(({ BrowserWindow }) => {
|
||||||
|
const window = new BrowserWindow({ width: 800, height: 600 });
|
||||||
|
window.loadURL('data:text/html,<title>Hello World!</title>');
|
||||||
|
});
|
||||||
|
const window = await application.firstWindow();
|
||||||
|
expect(await window.title()).toBe('Hello World!');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Electron window', function() {
|
describe('Electron per window', function() {
|
||||||
beforeAll(async state => {
|
beforeAll(async state => {
|
||||||
const electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', electronName);
|
const electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', electronName);
|
||||||
state.application = await playwright.electron.launch(electronPath, {
|
state.application = await playwright.electron.launch(electronPath, {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue