How to count gettext values until certain amount of those values are reached

Viewed 58

There are multiple elements with the same div. By clicking a button, these elements get number values. If the text in those elements reaches a certain pattern, I'm done and I should end the test.

For example, there are 5 elements with the div "someelement", these elements have numbers in them. If there are three numbers of 5 in those elements altogether, it should log out "you win" or something. if there are four numbers of 2 in those elements, it should log out "you win2". And it should loop through all of those options for validation. How to continue this into loop?

I found an easy solution for counting those values in elements, but how to continue the test until one of those expect conditions is reached?

var els = element.all(by.cssContainingText('.thediv', '5'));
expect(els.count()).toBe(3);

var els2 = element.all(by.cssContainingText('.thediv', '4'));
expect(els.count()).toBe(2);

1 Answers

It will click on button and then found elements and count them. Loop will run until first elements count will not be equal 3 AND second elements count will not be equal 2.

let els;
let els2;
let count = 0;
let count2 = 0;

do {
  button.click();
  els = element.all(by.cssContainingText('.thediv', '5'));
  els2 = element.all(by.cssContainingText('.thediv', '4'));
  count = els.count();
  count 2 = els2.count();
} while (count !== 3 && count2 !== 2)
Related