4

I have several protractor tests and sometimes I get a error saying:

Message:
     timeout: timed out after 10000 msec waiting for spec to complete
   Stacktrace:
     undefined

It can be randomly happening on some tests. I usually test on BrowserStack and it shows the error once in 3-5 builds. But recently I tried SauceLabs and almost every (every!) but not all the tests fail with that error. Probably, SauceLabs are just significantly slower so I get the error more often...

So here are the questions:

  1. Is there a way in Protractor/Selenium to change test running timeout? It needs to be changed on BrowserStack/Saucelabs as well.
  2. Why am I getting the error so often? Is there anything wrong with my tests? Most of the doesn't seem complicated or long running. Again, on local machine it's almost always fine.

Here is the example:

   it('should check that login gives error on empty or incorrect email', function () {
      p.get('/#/login');
      p.findElement(protractor.By.css('button[type="submit"]')).click();
      expect(p.findElement(protractor.By.css('.alert-danger')).getText()).toEqual('E-mailadres is niet geldig');
      p.findElement(protractor.By.model('user.email')).sendKeys('test-1xtc.vc');
      p.findElement(protractor.By.css('button[type="submit"]')).click();
      expect(p.findElement(protractor.By.css('.alert-danger')).getText()).toEqual('E-mailadres is niet geldig');
      p.findElement(protractor.By.model('user.email')).clear();
    });

The app is using AngularJS, selenium 2.20, protractor 0.20.1

artem_golovin
  • 154
  • 2
  • 14
  • I've been getting timeouts frequently on Sauce Labs, too, and mine is set to 30000 msec. It really reduces the usefulness of the tests. Any advice would be appreciated. – cjerdonek Sep 01 '14 at 04:05

5 Answers5

3

Is there a way in Protractor/Selenium to change test running timeout?

Yes :) You can do it via the allScriptsTimeout in your Protractor config (from Protractor FAQ)

You can also set the defaultTimeoutInterval in jasmineNodeOpts option (from Protractor referenceConf.js)

Why am I getting the error so often? Is there anything wrong with my tests? Most of the doesn't seem complicated or long running. Again, on local machine it's almost always fine.

Hard to say without seeing your tests. The example you provided looks good to me.

glepretre
  • 8,365
  • 5
  • 41
  • 56
2

Is your project an angularjs project? Are you using any $interval or $timeout service somewhere? If so, try to use $interval instead of $timeout and try to adjust the optional 'count' parameter to be 1, for example (https://docs.angularjs.org/api/ng/service/$interval#usage). I had recently a similar problem and I solved it this way.

J. Andre Pires
  • 173
  • 1
  • 8
  • I have exactly the same issue, But I'm using $timeout, because I have a method doing this: After 10 seconds start printing a hello world message for 5 seconds. How can I remove my $timeout in order to get my protractor test running fine? – RicardoGonzales Aug 12 '15 at 23:21
1

I solved it using a different property of config file, which I didn't see mentioned in answers above.

getPageTimeout : 100000 //in millis, i.e., 100 secs
Saba Hassan
  • 2,898
  • 1
  • 17
  • 32
0

the default time for saucelabs is 90 seconds I believe. it can be changed via your conf.js file using the idleTimeout variable which takes in a value of seconds. example

idleTimeout = 90; // equals 90 seconds

  exports.config = {
  //Includes test sub-sub-foldersbefore any tests in sub folders 
  specs: ['tests/*/*/*.js', 'tests/*/*.js', ],


  // use jasmine 2
  framework: 'jasmine2',
  capabilities :  {
                browserName: "chrome",
                // this takes seconds so 120 would be 120 seconds.
                idleTimeout = 120;
            },
},

Now if you need to change the value of a specific spec file you can use this inside your spec file, of course if your saucelabs idleTimeout is lower than this value than it will time out on saucelabs first. or if your saucelabs value is higher but the DEFAULT_TIMEOUT_INTERVAL is lower then it will time out.

// this takes in miliseconds so 1000 = 1 second
jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;
BarretV
  • 1,145
  • 7
  • 15
0

Jasmine has timeout for each spec i.e. each it in jasmine framework. so if any spec (it) exceeds jasmine spec's default timeout then it fails that spec.

Solution: To override jasmine spec timeout for one individual spec, pass a third parameter to it: it(description, testFn, timeout_in_millis)

it('description of test case', function() {
   /*your test 
               steps
                    here*/
},120000);//120 seconds timeout for this spec

more information on timeouts is here

Jlearner
  • 493
  • 4
  • 5