1
votes

I have some e2e tests written in Protractor. Some of my tests execute stuff that causes an alert to show (uib-alert). The tests run fine and can find and verify the alerts, but if I use the tag dismiss-on-timeout from uib-alert, the tests fail because protractor waits for the timeout before doing the asserts.

Issues: https://github.com/angular-ui/bootstrap/pull/2798 and https://github.com/angular/protractor/issues/169

So, I want to create my alerts without the dismiss-on-timeout tag when running protractor.

My alerts are created by a Service like this:

angular.module('MyApp').factory("AlertService", function (...

How can I override this on Protractor? I am trying to use browser.addMockModule('AlertService', mock) but that doesn't work...

1

1 Answers

1
votes

I made it by extracting the AlertService to a whole new module and then mocking it. I guess protractor can't mock a single service inside a module, only the whole thing.

Edit: I created alert.module.js:

angular.module('MyApp.alert', []);
angular.module('MyApp.alert').factory("AlertService", function($rootScope) {
...

And them, on protractor.conf.js:

exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: [],
  capabilities: {
    browserName: 'phantomjs',
    'phantomjs.binary.path': require('phantomjs-prebuilt').path
  },
  onPrepare: function() {
  ...
  function mockAlertService(){
    var alertMock = function() {
     angular.module('MyApp.alert', []);
     angular.module('MyApp.alert').factory("AlertService", function($rootScope) {
     ...
   }
   browser.addMockModule('MyApp.alert', alertMock);
  }