Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TestCafe with Electron: Determine if app is visible on Windows desktop

Our Electron application starts minimized to the Windows tray notification area i.e. not visible on the desktop.

If I attempt to get visibility information through methods such as this or as described here, checking the 'visible' property always returns true.

For example, the below always returns true whether the app is minimized to the notification area or visible on the desktop:

if(await Selector('button', { visibilityCheck: true }).visible)
    console.log("VISIBLE");
  else
    console.log("NOT VISIBLE");

As a hail-mary, I have also attempted to check the 'focused' property but that also always returns true (at least on the 'body') regardless of the application's visibility on the desktop.

Does anyone know of a reliable method through TestCafe to determine if the application is visible on the Windows desktop?

Thanks m

like image 960
Maximojo Avatar asked Nov 24 '25 13:11

Maximojo


1 Answers

It can be done using Electron's API. Please refer to the following article to get details: https://electronjs.org/docs/api/browser-window#winisvisible .

Here is the test code:

import { ClientFunction } from 'testcafe';
fixture `Electron page`
    .page ``;

const isDocumentHidden = ClientFunction(() => {
    const remote = require('electron').remote;
    const win = remote.getCurrentWindow();
    return !win.isVisible();
});

test('is hidden', async t => {
    console.log(await isDocumentHidden());
});

I checked the code on your project and it works as expected.

like image 100
Alex Kamaev Avatar answered Nov 27 '25 01:11

Alex Kamaev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!