Question

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 ?

Was it helpful?

Solution

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.

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top