I'm trying to find the electron window object that contains the loaded page. I want to take the following action:
let window1 : BrowserWindow | null = null
let window2 : BrowserWindow | null = null
electronApp.on("window", async (page) => {
//evaluate page so that title is loaded
await page.evaluate(() => { });
if(await page.title() === 'page1') {
window1 = getElectronBrowserWindow(page); // Example
}
else if(await page.title() === 'page2') {
window2 = getElectronBrowserWindow(page);
}
});
In my test I would like to do something like:
test("check if window is not visible", async () => {
let visibility = window1.isVisible();
expect(visibility).toBeFalsy
});
});
I've come across electronApplication.browserWindow(page)
. However, it does not provide the page's BrowserWindow object.
Yes, it can be done.
What
electronApplication.browserWindow(page)
provides is an object of typeJSHandle<Electron.BrowserWindow>
. You have to use itsevaluate()
method.I'm not sure of all the details of your test and the differences b/w
window1
andwindow2
, but here's an example of testing that a browser window is visible. Hopefully this clarifies