【问题标题】:Best way for checkForToastMessage (working example included)checkForToastMessage 的最佳方式(包括工作示例)
【发布时间】:2016-11-02 06:22:10
【问题描述】:

摸索了几个小时后,我们找到了以下解决方案。
很难想象这应该是理想的方式。现在我想知道,量角器的预期方式应该是什么样子。

checkForToastMessage(expectedMessageText: string) {
    browser.wait(function () {
        browser.ignoreSynchronization = true;
        return element(by.cssContainingText('.message-title', expectedMessageText)).isPresent()
            .then(function(isPresent) {
                if (!isPresent) {
                    $(".message-title").getText().then(function (text) {
                        console.log("found: " + text)
                    }) 
                }
                browser.ignoreSynchronization = false;
                return isPresent;
            });
    }, 2000, "There was no Toast with the message '" + expectedMessageText + "' to display!");
}

checkForNoToastMessage() {
    var timeout = 2000;
    var start = 0;
    while (start <= timeout) {
        browser.sleep(100);
        start += 100;
        browser.wait(function () {
            browser.ignoreSynchronization = true;
            return element(by.css('.message-title')).isPresent()
                .then(function(isPresent) { 
                    browser.ignoreSynchronization = false;
                    expect(isPresent).toBeFalsy("no toaster was expected");
                    return true;
                });
        }, 100);
    }
}

【问题讨论】:

    标签: javascript selenium-webdriver protractor e2e-testing


    【解决方案1】:

    借助 protracot.ExpectedConditions.visibilityOf() 方法,我们可以轻松地在量角器的 UI 上找到烤面包机弹出窗口。它完美地工作。我们不需要这么冗长的逻辑。

    您可以按照下面的工作示例进行操作:

    var EC=protractor.ExpectedConditions;
    
    var ToasterPopUP = element(by.css('.message-title'));
    
    EC.visibilityOf(ToasterPopUP ).call().then(function(isPresent){
        expect(isPresent).toBeFalsy("no toaster was expected");
      });
    

    【讨论】:

    • “条件”类型上不存在属性“调用”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 2016-12-05
    • 1970-01-01
    • 2018-09-11
    • 1970-01-01
    相关资源
    最近更新 更多