Search code examples
testingautomationelectrone2e-testingtestcafe

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


Solution

  • 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.