如何让量角器等待弹出modal-dialog
?
背景:单击按钮后,量角器应等待弹出模式对话框(并在单击按钮时弹出对话框时弹出时间)。我怎样才能做到这一点?使用browser.wait()
?
原因是,我必须进行端到端测试并衡量用户在点击按钮和从网站获得反馈之间的体验时间。
当我手动进行测试时,网站可能需要5到30秒才能提供反馈。如何让量角器等待,然后读出页面顶部显示的对话框?
答案 0 :(得分:1)
因此,您需要测量点击按钮与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();
使用expected conditions
内的browser.wait()
等待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();
然后使用
获取buttonClickTime
和ModalDialogTime
之间的差异
var timeDifference = ModalDialogTime.getTime() - buttonClickTime.getTime();
答案 1 :(得分:0)
经过数小时的研究,我找到了一个非常有用的脚本: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);
});
});
});