量角器 + ionicPopup

Protractor + ionicPopup

有没有人成功使用 Protractor 检测到 ionicPopup 警报? 我已经尝试了 here 建议的所有解决方法,但没有成功。 我需要 Protractor 来检测警报并检查警报中的文本。

Ionic Popup 仅由 DOM 元素组成,因此您应该能够使用普通定位器来 find/test 它们。因为它们不是由警报组成的,所以您链接到的问题中的解决方法可能没有用。

我明白了 - 我看到很多问题都试图以非常复杂的方式来做,但最后我尝试了这个,结果证明是这么简单。

检查您的元素并找到它的 ng-repeat 值,然后

var button = element(by.repeater('button in buttons')).getText()

您还需要让浏览器以某种方式停止几秒钟,这样当 ionic 弹出窗口实际上不存在时它不会解析测试。

为此,browser.sleep(3000);

就是这样!然而,将另一个按钮放入其中被证明是一个小问题。 var button = element(by.repeater('button in buttons')).get(0).get(1) return undefined 不是函数。

喜欢就采纳吧!如果我知道如何获得另一个按钮,我会 post 放在这里。

我已经通过如下设置弹出变量成功地测试了 Ionic 弹出窗口:

var popup = element(by.css('.popup-container.popup-showing.active'));

并且在测试中:

expect(popup.isDisplayed()).toBeTruthy();

这是我写的 class 以测试弹出窗口是否存在并确保 header 和 body:

中的文本正确
var TestUtilities = function(){
    this.popup = element(by.css('.popup-container.popup-showing.active'));

    //Tests to see if $ionicPopup.alert exists
    this.popupShouldExist = function() {
        expect(this.popup.isDisplayed()).toBeTruthy();
    };

    //Tests to see if $ionicPopup.alert contains the text provided in the argument exists in the header
    this.popupContainsHeaderText = function (text) {
        this.popupShouldExist();
        expect(this.popup.element(by.css('.popup-head')).getText()).toMatch(text);
    };

    //Tests to see if $ionicPopup.alert contains the text provided in the argument exists in the body
    this.popupContainsText = function (text) {
        this.popupShouldExist();
        expect(this.popup.element(by.css('.popup-body')).getText()).toMatch(text);
    };
};

module.exports=TestUtilities;

另请查看此站点以了解有关在量角器中测试 Ionic 的更多信息,它讨论了如何检查弹出窗口是否存在:http://gonehybrid.com/how-to-write-automated-tests-for-your-ionic-app-part-3/