javascript - 测试时弹出消息框

标签 javascript node.js popup testcafe end-to-end

我通过测试咖啡馆工作室运行了一个测试,该测试进入网站,单击页面并暂停。在暂停期间,我希望弹出一个消息框并显示评论(用作解释网站上发生的事情的教学工具)。我尝试了几种选择,但它们不起作用。我对此很陌生,可能会遗漏一些东西?

提前致谢! 这是我的简单测试代码

从 'testcafe' 导入 { Selector, ClientFunction }; 从“弹出窗口”导入{弹出窗口}; 固定装置svdemo管理器驾驶舱 .page http://localhost/SvManagerCockpit/home .httpAuth({ 用户名:'我的用户名在这里', 密码:'我的密码在这里', 域名:'mydomainhere' });

测试('暂停',异步t => { 等待t .click(Selector('span').withText('机器 OEE 仪表板')) .等待(10000); 弹出警报({ 内容:“你好!” }); 返回1; });

await t
 .expect(alert()).eql(1);

}); 我希望在 .js 测试中插入一些代码,以在浏览器中生成消息框/对话框。

最佳答案

您的 popup.alert 是 ClientFunction 吗?如果是这样,应该使用 await 关键字调用它。 请看一下下面的示例,该示例展示了如何实现此类测试:

import { Selector, ClientFunction } from 'testcafe';

fixture `testcafe`
    .page `https://devexpress.github.io/testcafe/`;

test('Test with message box', async t => {
    const showMessageBox = ClientFunction(message => {
        return new Promise(resolve => {
            var msgBox = document.createElement('div');
            msgBox.textContent = message;
            msgBox.style['top'] = '500px';
            msgBox.style['left'] = '500px';
            msgBox.style['position'] = 'absolute';
            msgBox.style['font-size'] = 'x-large';
            document.body.appendChild(msgBox);
            setTimeout(() => {
                document.body.removeChild(msgBox);
                resolve();
            }, 4000);            
        });
    });

    await t
        .click(Selector('span').withText('Docs'));
    await showMessageBox('Docs link was clicked!');
    await t
        .click(Selector('a').withText('Using TestCafe'));
});

关于javascript - 测试时弹出消息框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57189437/

相关文章:

javascript - 通过 Office Javascript API 1.1 发表评论

javascript - 绝对定位时使 <div> 缩放到内容?

Javascript - Node.js 需要 ('ttapi' )无法在书签中工作

javascript - Node.js:如果声明为粗箭头,则函数 "not defined"

javascript - CSS中的多个弹出窗口层位置

javascript - 如何使用javascript传递计算值

javascript - React Prop 类型检查,如何声明 "any component"?

javascript - 修改值 - 通过引用传递

javascript - 单击链接时终止垂直滚动?

javascript - 从代码隐藏打开的弹出窗口未关闭