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

流过昼夜 提交于 2019-12-07 13:27:31

问题


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


回答1:


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

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



来源:https://stackoverflow.com/questions/58369151/testcafe-with-electron-determine-if-app-is-visible-on-windows-desktop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!