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.
-
Could you provide a reproducible example using a public site? – alecxe Jun 01 '15 at 14:25
4 Answers
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/

- 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
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();

- 127
- 1
- 12
-
Thanks very much! This worked. See also http://gonehybrid.com/how-to-write-automated-tests-for-your-ionic-app-part-3/ – Yoni Rabinovitch Nov 19 '15 at 13:14
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.

- 303
- 2
- 7
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.

- 189
- 12
-
This did not work for me. I got: NoSuchElementError: No element found using locator: by.repeater("button in buttons") – Yoni Rabinovitch Jul 21 '15 at 19:25
-
You have to inspect the element and see what they use for repeater, i.e. banana in bananas ? – realization Jul 21 '15 at 20:27