TestCafe with Electron:确定应用程序是否在 Windows 桌面上可见 [英] TestCafe with Electron: Determine if app is visible on Windows desktop

查看:34
本文介绍了TestCafe with Electron:确定应用程序是否在 Windows 桌面上可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的 Electron 应用程序最小化到 Windows 托盘通知区域,即在桌面上不可见.

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

如果我尝试通过 方法如 this在此处描述,检查 'visible' 属性总是返回 true.

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

例如,无论应用是最小化到通知区域还是在桌面上可见,以下始终返回 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");

作为万岁,我还尝试检查focused"属性,但无论应用程序在桌面上的可见性如何,它也总是返回 true(至少在body"上).

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.

有谁知道通过 TestCafe 确定应用程序是否在 Windows 桌面上可见的可靠方法?

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

谢谢米

推荐答案

可以使用 Electron 的 API 来完成.详情请参考以下文章:https://electronjs.org/docs/api/browser-window#winisvisible .

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 .

这里是测试代码:

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.

这篇关于TestCafe with Electron:确定应用程序是否在 Windows 桌面上可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆