How to insert a date filter in a protractor?

I am writing end-to-end tests for my angular application. I need to check dates that are in the correct format. So I want to enter "datefilter" so that I can use it in protractor.

When I 'googled', I found that I could use browser.executeAsyncScript to get the injector, and then use

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

to get the date feed.

But I'm still not able to combine them into code. Any heads-up will be enough to make me go with the code.

+4
source share
2 answers

Theoretically, you can access your services as follows:

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

+8

@Lajos Veres, . , .

browser.executeScript(function() {
  var myDateFilter = angular.injector(["ng"]).get('dateFilter');
  var dateString = myDateFilter(new Date(), 'EEE, dd MMM yy');
  return dateString;
})
.then(function(dateStr) {
    .... //use dateStr for whatever required.
});
0

Source: https://habr.com/ru/post/1534822/


All Articles