Search code examples
codeception

codeception do not see field but the browser does (Chrome Driver)


I have a codeception test on angular 5 application. with HTML5 pretty url.
I am testing 2 steps forms.

url: /register/ fields: first_name,email,password  
when success redirect to:  
url: /personal-details/ fields: date_of_birth 

First step goes perfectly fine. I test all the scenarios. when step one ends, the browser redirects with HTML5 redirection to /personal-details/ as expected.
The problem is that codeception does not see #date_of_birth even though it is existed.
To verify that, I puased the execution and in the console I run

  document.getElementById('date_of_birth') 

and the field was found. it is on the page.

I though that it is related to the redirection, so I have added a special redirect in order to cause the first form to have the same problem, and it is working fine.

this is the error:

Test fields second step

 Test  tests\acceptance\FirstCest.php:testFieldsSecondStep
 Step  See element "#date_of_birth"
 Fail  Failed asserting that an array is not empty.

Scenario Steps:

What could possibly go wrong?
Thanks


Solution

  • Maybe Codeception checks if element exists before the page is fully loaded.
    Try to use waitForElement instead of seeElement

    $I->waitForElement('#date_of_birth', 10);