javascript - 使用 Testcafe 访问自定义窗口属性
问题描述
所以在我们的应用程序中,我们有一个名为 reactMap 的自定义窗口属性。因此,当您加载我们的站点并转到控制台并输入“window.reactMap.loaded()”时,它将返回 true 或 false。但是,当我尝试在 TestCafe 测试中添加以下内容时:
const mapLoaded = ClientFunction(() => window.reactMap.loaded());
它只是抱怨Property 'reactMap' does not exist on type 'Window'.
我如何在 TestCafe 测试中运行那段代码?谢谢
解决方案
这意味着您ClientFunction
在应用程序初始化window.reactMap
属性之前执行。尝试如下修改您的测试代码:
const waitForProperty = ClientFunction(() => {
return new Promise(function (resolve, reject){
var intervalId = null;
var timeoutId = null;
var checkCondition = function () {
return window.reactMap;
}
timeoutId = window.setTimeout(function () {
window.clearInterval(intervalId);
if (checkCondition())
resolve();
else
reject();
}, 10000);
intervalId = window.createInterval(function (){
if (checkCondition()) {
window.clearInterval(intervalId);
resolve();
}
}, 1000);
});
});
await waitForProperty();
const mapLoaded = await ClientFunction(() => window.reactMap.loaded())();
推荐阅读
- java - ArrayList - 索引与大小
- django - AWS 弹性 beantalk 上的 Django 项目始终具有“严重”的健康状况和 100% 的 CPU 负载
- javascript - 为什么会触发两个事件侦听器而不是一个?
- regex - sas 子字符串到第一个空格
- r - 将数值变量转换为 dplyr 中的因子
- php - 如何强制浏览器等到 php 服务器发送响应?
- javascript - socket.io 加入房间 N 次时发送 N 条消息
- javascript - 功能未按预期运行。为什么?
- windows - Native Windows:如何捕获被 Google Hangouts 等其他窗口覆盖的窗口
- c# - 使用 IReliableDictionary2 时数据何时保存到磁盘?