0

Has anyone succeeded in using Protractor to detect an ionicPopup alert? I've tried all the workarounds suggested here but no luck. I need Protractor to detect the alert and check the text in the alert.

Yoni Rabinovitch
  • 5,171
  • 1
  • 23
  • 34

4 Answers4

3

Here's the class I wrote to test that the popup exists and to ensure the text is correct in the header and 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;

Also check out this site for more on testing Ionic in protractor it talks about how to check to see if the popup exists: http://gonehybrid.com/how-to-write-automated-tests-for-your-ionic-app-part-3/

jgerstle
  • 1,674
  • 5
  • 25
  • 35
  • Perfect answer!! This completely answers my question, including how to check for the text in both header and body, all wrapped in a nice, generic utility class. Thanks!! – Yoni Rabinovitch Nov 22 '15 at 08:55
2

I've tested Ionic popups successfully by setting the popup variable as follows:

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

And in the test:

expect(popup.isDisplayed()).toBeTruthy();
sandrasaur
  • 127
  • 1
  • 12
0

Ionic Popups are just made of DOM elements, so you should be able to use normal locators to find/test them. Because they're not made of alerts, the workarounds in the issue you linked to are probably not useful.

sjelin
  • 303
  • 2
  • 7
0

I got it - I saw a lot of issues out there trying to do it in very complex ways, but in the end I tried this and it turns out to be this simple.

Inspect your element and find its ng-repeat value, then

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

You also need to have the browser sit out somehow for a couple seconds so it doesn't resolve to the tests while the ionic popup isn't actually there.

For that, browser.sleep(3000);

That's it! However, getting the other button in there is proving to be a little problem. var button = element(by.repeater('button in buttons')).get(0) or .get(1) return undefined is not a function.

Please accept the answer if you like it! If I figure out how to get the other button, I'll post it here.

realization
  • 189
  • 12