【问题标题】:Message box pop up while during test测试时弹出消息框
【发布时间】:2019-12-02 23:48:57
【问题描述】:

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

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

从'testcafe'导入{选择器,ClientFunction}; 从“弹出窗口”导入 {popups}; 夹具svdemo manager cockpit .pagehttp://localhost/SvManagerCockpit/home .httpAuth({ 用户名:'myusernamehere', 密码:'mypasswordhere', 域:'mydomainhere' });

test('暂停', async t => { 等待 .click(Selector('span').withText('Machine OEE Dashboard')) .等待(10000); 弹出警报({ 内容:“你好!” }); 返回 1; });

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

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

【问题讨论】:

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


    【解决方案1】:

    您的 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'));
    });
    

    【讨论】:

      【解决方案2】:

      快速浏览一下,您的警报末尾没有分号吗?也许尝试添加这些,看看会发生什么。

      如果这不起作用,请发布您的完整代码,以便我们查看!

      【讨论】:

      • 对不起,我忘了包括那些末尾有分号的
      猜你喜欢
      • 2015-04-17
      • 2011-10-28
      • 1970-01-01
      • 1970-01-01
      • 2017-05-29
      • 2023-03-21
      • 2011-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多