Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inject datefilter in protractor?

I am writing end to end test cases for my angular application. I need to check for dates that are in correct format. So I want to inject the 'datefilter', so that I can use it in protractor.

When i 'googled' i found that i can use the browser.executeAsyncScript to get the injector and then use

angular.injector(["ng"]).get("dateFilter"); 

to get the datefilter.

But i am still not able to put them all together in code. Any heads-up would be enough to get me going with the code.

like image 319
Vikram Avatar asked Apr 03 '14 12:04

Vikram


1 Answers

Theoretically you can access your services like this:

browser.executeAsyncScript(function(callback) {
  var service = angular.injector(['MyModule']).get('myService');
  service.query({}, function(data) {
    callback(data);
  });
}).then(function (output) {
  console.log(output);
});

And there is an example:

https://github.com/andresdominguez/protractor-meetup/blob/master/test/e2e/api-helper.js

like image 182
Lajos Veres Avatar answered Nov 02 '22 18:11

Lajos Veres