繁体   English   中英

量角器等待模态对话

[英]Protractor wait for modal-dialog

如何让量角器等待modal-dialog弹出?

背景:单击按钮后,量角器应等待模式对话框弹出(并在单击按钮和对话框弹出时获得正确的时间)。 我怎样才能做到这一点? 使用browser.wait()吗?

原因是,我必须进行端到端测试,并测量用户单击按钮与从网站获得反馈之间的时间。

当我手动进行测试时,网站可能需要5到30秒才能给出反馈。 如何让量角器等待,然后读出显示在页面顶部的对话框?

因此,您需要测量按钮的单击与modal-dialogue窗口出现之间的时间差。

  • 单击按钮后获取时间

      //you can use any selector for clicking the button element(by.buttonText("button_text_for_thebutton").click(); //getting the time var buttonClickTime = new date(); 
  • 使用browser.wait()内部的expected conditions ,等待弹出modal-dialog

     //you can use any other locator for modal window browser.wait(EC.presenceOf(element(by.css('css_locator_formodal'))), 1000, 'Unable to find the modal-popup'); //get the time post Modal dialog appearance var ModalDialogTime = new date(); 
  • 然后使用以下方法获得buttonClickTimeModalDialogTime之间的区别

     var timeDifference = ModalDialogTime.getTime() - buttonClickTime.getTime(); 

注意:预期条件代码来自此SO 帖子中的 @alexce答案。

经过数小时的研究,我发现了一个非常有用的脚本: waitReady.js 这是我现在的工作解决方案。 我还添加了功能,该脚本还可以打印出模态对话框的文本。

it('Should wait until modal-dialog pops up', function() {
        var dialog = element(by.className('modal-dialog'));
        expect(dialog.waitReady()).toBeTruthy();
        var dialogtext = element(by.className('modal-body-content'));
        expect(dialogtext.waitReady()).toBeTruthy().then(function () {
            dialogtext.getText().then(function (text) {
            console.log('Button Text: ' + text);
        });
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM