1

I am trying to run Selenium Tests written in C# (Visual Studio 2015) with Protractor for .NET. This works fine with any random public Angular2 applications that I found online.

However, it does not work with the Angular2 application being built at our company. Each simple 'FindElement' command times out (after the timeframe I set).

The frontend team tells me they are using Angular-CLI which has protractor already built-in and is all wonderful. Can't I test this the way I am trying to? Or are there maybe some settings I'm missing?

Thanks for any help!

Martin K.
  • 29
  • 4
  • Possible duplicate of [Testing AngularJS with Selenium](http://stackoverflow.com/questions/25062969/testing-angularjs-with-selenium) – Kindle Q Feb 03 '17 at 12:13

3 Answers3

1

Just to finish this up: the problem has been solved. It is like BBaia said in his comment above. Things are called differently now in Angular 2/4, but the principle is the same.

The application under test did constantly check for updated data (every couple of milliseconds) and Angular never got into a stable state. Protractor's WaitForAngular method is waiting for Angular to become stable, so it timed out.

The front-end developers helped me by moving the constant polling outside of Angular and let it only feed updated information back into Angular if data had actually changed.

Here two lines of JavaScript that can be executed in the browser's console to check if the application is in a stable state or not:

var testabilities = window.getAllAngularTestabilities();
testabilities[0].isStable();

I summarized it in this blog post as well.

Thanks!

Martin K.
  • 29
  • 4
0

Adding following lines could also help you

ngDriver.IgnoreSynchronization = true;
ngDriver.WaitForAngular();

Add this in SetUp() method or try using at line where you are facing issue

snaik
  • 41
  • 3
-1

I tried some things and came to the following conclusion:

The timeout I was getting came from Protractor's 'WaitForAngular' method. Now I'm just a tester and have no idea about JaveScript, but I think there might be something wrong in the "clientsidescripts.js" file of Protractor and hence also in the "ClientSideScripts.cs" of Protractor for .NET, which I am using:

else if (window.getAllAngularTestabilities) {
  var testabilities = window.getAllAngularTestabilities();
  var count = testabilities.length;
  var decrement = function() {
    count--;
    if (count === 0) {
      callback();
    }
  };
  testabilities.forEach(function(testability) {
    testability.whenStable(decrement);
  });

(that's lines 156-167 in Protractor / lines 99-110 in Protractor-net )

In my understanding and from what I tried, in the last line the call of "decrement" should be "decrement()". Otherwise the decrement function will not be called and the callback never happens.

So far, this is working fine for me, I am not stuck with timeouts anymore. On the other hand, the automatic waiting doesn't seem to work all that great now either. But I just found this work-around and will keep playing with it.

Update: The above 'fix' is not working. It does prevent getting timeouts, but it also prevents Protractor from doing its work properly ;)

Martin K.
  • 29
  • 4
  • From Protractor's documentation : "Before performing any action, Protractor waits until there are no pending asynchronous tasks in your Angular application. This means that all timeouts and http requests are finished. If your application continuously polls $timeout or $http, Protractor will wait indefinitely and time out. You should use the $interval for anything that polls continuously (introduced in Angular 1.2rc3)." – bbaia Feb 12 '17 at 17:42
  • Thank you very much, @bbaia ! I will forward this to the frontend team. – Martin K. Feb 14 '17 at 08:39