CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

while loop with element present assertion in page object file

Open ecampii opened this issue 10 years ago • 3 comments

Is it possilbe to use while (I.seeElement(element) == false) { do the following }

I just get an expected true not equal to false failure as below.

log result is below. expected elements of elementLocatorHere to be seen + expected - actual

  -false
  +true

Scenario Steps: 93) I.seeElement(elementLocatorHere)

The code snippet is here. while (I.seeElement(elementLocatorHere) == false) {             I.click(elementLocatorHere);             I.pressKey(somethinghere');             I.click(elementLocatorHere;         }

ecampii avatar Nov 10 '16 05:11 ecampii

Calls inside 'I' don't return values (except grab functions, that you call with yield). So I.seeElement will fail the test if it doesn't see it.

Besides that, I functions are not called as they come in code, they are all added to a chain of promised to later be executed, so logic like the one you are trying to do is a bit complicated to do.

Usually you should know how many clicks you need to do before the element appear, unless there is a random logic attach to it, then I'm not sure how to solve it.

divad4686 avatar Nov 11 '16 17:11 divad4686

Nothing to add. Using loops inside tests is a bad smell. If you need to use something like that: probably you need to have implement that in custom helper

DavertMik avatar Nov 12 '16 22:11 DavertMik

For those who came here from Google this Gist might be helpful: Example of custom helper to perform conditional click (without throwing an error).

tometchy avatar Jul 27 '20 14:07 tometchy