Codeceptjs: while loop with element present assertion in page object file

Created on 10 Nov 2016  ·  3Comments  ·  Source: codeceptjs/CodeceptJS

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;
        }

Most helpful comment

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

All 3 comments

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.

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

foobarth picture foobarth  ·  4Comments

wahengchang picture wahengchang  ·  4Comments

hanthomas picture hanthomas  ·  4Comments

DioNNiS picture DioNNiS  ·  3Comments

JoeChapman picture JoeChapman  ·  3Comments