I'm creating the e2e test for my application and I have a problem when I'm testing the login page. I want to test both the correct login and the incorrect one but the problem is that when you enter incorrect credentials you get an alert("Your email or password is incorrect") and that also gets triggered in the e2e test which means I have to click the "OK" button on the alert() in order to continue the test. Is there anyway to ignore the alert() in the test ?
Asked
Active
Viewed 459 times
2 Answers
1
Please take a look at https://github.com/katranci/Angular-E2E-Window-Dialog-Commands
You can add alertOK();
in your test, before the alert will be shown and this let you skipped it.

Piotr Kozlowski
- 899
- 1
- 13
- 25
0
Granted this wouldn't necessarily qualify as E2E anymore - but you could abstract alert to a service in whatever directive or controller or service has the alert()
call and then just mock that particular service. Here's an example:
Javascript
var myApp = angular.module('myApp', []);
myApp.factory('alert', function () {
return function (message) {
alert(message);
};
});
myApp.controller('MyController', function ($scope, alert) {
$scope.alert = alert;
});
View
<body ng-app="myApp" ng-controller="MyController">
<div ng-init="alert('test')"></div>
</body>

Jesus is Lord
- 14,971
- 11
- 66
- 97
-
Yeah but I need this for angular's scenario test runner and from what I know I can't mock/handle services in there ... that's for unit testing where I'm not bothered by the alert. – Adrian Neatu Nov 02 '13 at 09:19