Question

I have recently started using protractor for e2e tests. I have a combobox which lists events that match what the user types in - so the list is empty if no such events are found.

What I would like to do is enter 3 random characters, and if the combobox list is empty, clear the combobox and retry another 3 random characters. This should be repeated until a non-empty list is found.

I have tried using a simple while loop to do this, but the asynchronous nature of webdriverjs means that I become stuck in an infinite loop. Is it possible to somehow wait inside the loop for the combobox to be populated? Or is there some other, cleaner solution to this problem?

Code:

var query = element(by.model('searchStr'));

query.clear();

var letters = generateRandomLetters();

console.log(letters);

query.sendKeys(letters);

var eventList = element.all(by.repeater('result in results'));

eventList.count().then(function(count) {

    if(count) {

        //test continues here

    }

}); 
Was it helpful?

Solution

Declare a function that calls itself recursively until your condition is met. That should to the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top