gpt4 book ai didi

javascript - Protractor 等待命令无法等待引导模式出现

转载 作者:数据小太阳 更新时间:2023-10-29 03:55:30 25 4
gpt4 key购买 nike

场景:每当用户使用不正确的凭据登录时, Bootstrap 模式会显示 1-2 秒,并显示消息“抱歉,不正确的凭据”。下面是模态的 HTML。

<div class="modal-content">
<div class="modal-body note-error text-center ng-binding"> Sorry, invalid credentials! </div>
</div>

我需要验证预期的错误文本是否等于实际的错误文本。

我的代码

页面对象.js

var errorModal = element(by.css('.modal-body.note-error.text-center.ng-binding'));

this.getErrorText = function(){

var until = protractor.ExpectedConditions;
browser.wait(until.textToBePresentInElement(errorModal, "Sorry, invalid credentials!"), 3000, "Not able to find");


return errorModal.getText();

};

规范.js

expect(Login_Page.getErrorText()).toMatch('Sorry, invalid credentials!');

输出

Message: Expected '' to match 'Sorry, invalid credentials!'.

我不知道为什么这个等待不起作用。

最佳答案

在查看您的 [app] 后,我找到了问题的根本原因。您要查找的错误模态始终存在于dom 中- 这意味着 isPresent()将始终返回 true。但它在无效输入时仅显示 1 或 2 秒 - 这意味着 isDisplayed()将返回 true对于那短短的几秒钟

这样做的副作用是返回值 getText() .它只返回可见的 innerText。检查以下来自 official documentation 的摘录

Get the visible innerText of this element, including sub-elements, without any leading or trailing whitespace. Visible elements are not hidden by CSS.

这就是您从 getText() 中看到空值的原因

我建议您通过 browser.executeScript() 提取 innerText 的变通方法

替换return errorModal.getText()return browser.executeScript('return arguments[0].textContent',errorModal)你应该一切都好

让我知道这是否有效

关于javascript - Protractor 等待命令无法等待引导模式出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41829169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com