Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor: Correct use of waitReady.js file in my tests

We are using browser.wait extensively throughout the entire test suite. It became a headache when managing different timeouts for different scenarios. I came across a waitReady function(https://gist.github.com/elgalu/2939aad2b2e31418c1bb), but I am unable to utilize it in my code. The directory looks like: (all files besides each other) .

├── conf.js
├── main.js
├── waitReady.js

Main.js --->Contains all describe and it blocks

    require('./waitReady.js');
    describe(...){
    it{
    code...
expect(element.waitReady()).toBeTruthy();
    };
    });

For some reason the code does not find that function and my code keeps getting function not defined error. Do I need to initialize it somewhere?

like image 965
cathelesup Avatar asked Mar 14 '23 05:03

cathelesup


2 Answers

Put the import into the onPrepare() in your protractor config:

onPrepare: function () {
    require('./waitReady.js');
},
like image 107
alecxe Avatar answered Mar 23 '23 13:03

alecxe


I had no doubt Alecxe would answer this one :)

An alternate solution for managing timeout lengths, which I've found useful, is to add default timeout lengths to a basePage, or onPrepare. For this I use t-shirt sizes... Eg:

this.timeout = {
    's' : 500,
    'm'  : 1000,
    'l'  : 5000,
    'xl'  : 10000
}; 

Then call thusly:

browser.wait(someThingToWaitFor(), this.timeout.xl);
like image 41
Brine Avatar answered Mar 23 '23 13:03

Brine