protractor click action relies on ptor.sleep(). How can I resolve correctly?

212 views Asked by At

I'm a newbie trying to not rely so much or at all on using ptor.sleep() calls, especially after the click below. The line below never gets the value (they all return Nan)unless I include the ptor.sleep(1000); call after the click() below.

I've made various attempts to make the array elem to resolve before the results of the list after clicking, wrapping the click in the function, etc, but nothing I've tried works without the sleep calls. Already read up on protractor control flow.

devCountString = parseInt(arr[i]);

Thanks for any insights, maybe something obvious I've missed so that I can remove the ptor.sleep() calls.

my spec:

describe('\n  == patch List suite results == \n', function() {

// login already was done in config files, onPrepare function.
var ptor, noFilterCount;

// needed here if we turn ptor.ignoreSynchronization = false;

beforeEach(function() {
    ptor = protractor.getInstance();
    ptor.ignoreSynchronization = true;
    browser.get('https://my.abc.com:3000/fixes');
    ptor.sleep(1200);
});  //end beforeEach()

it('11 - verify filter fewer', function() {

    var sevStringElm, sevString;
    var applicableCount;

    ptor.ignoreSynchronization = false;
        ptor.sleep(500);

    sevStringElm = element(by.css("input.form-control.bf-spinner"));
        sevStringElm.clear();
        ptor.sleep(500);

    sevStringElm.sendKeys( '8' );
        ptor.sleep(500);

// click on the "fewer" spinner, wrap the click to wrap the .
    var fewerPromise = element(by.css("span.bf-spinner-toggle:nth-child(2)")).click(); 
        ptor.sleep(1000);

// now get the list of clickable elements in each device card. by title 
    var applicableDevicesElm = element.all(by.css("[title$='Applicable\ Devices']"));
        applicableDevicesElm.getText().then(function(arr) {
            console.log("arr.length= "+arr.length);
            for (var i = 0; i < arr.length; i++) {
                devCountString = parseInt(arr[i]);
                expect(devCountString).toBeLessThan( 9 );
            };
        });
    });
1

There are 1 answers

0
Gabriel Kohen On

Everytime an action goes to the webdriver, Protractor will put that into the flow queue as shown in the documentation. As a result, when you get to inspect your elements after the click, the queue should have resolved the dependencies and have your state ready for the finder. In any case, even if you don't want to have the implicit wrapping that Protractor does on its actions (which are always asyc), you can put a .then(function(){}) after the click and put the post click logic in that anonymous calback function. On a side note, you should have to use ptor anymore. Use browser instead that mixes in the protractor instance capabilities. Example: browser.sleep(1000)