Cannot get a Codeception to populate the form fields.

I am trying to perform a simple acceptance test for the purpose of training. This is a simple authentication scenario: the user enters /admin , if he is not registered, he is redirected to /login to fill out the form.

When I run the test, I get this error:

 1) Couldn't login with a password protected area in LoginCest.loginUserWithProperCredentials Guy couldn't fill field "username","rafael": Field matching id|name|label|value or css or xpath selector does not exist Scenario Steps: 5. I fill field "username","rafael" <==== RED 4. I see current url equals "/login" 3. I am on page "/admin" 2. So that I Perform administrative tasks 1. As a Site Owner 

Now here is my view:

 //create.blade.php <!doctype html> <html> <head> <meta charset="utf-8"> <title>Login</title> </head> <body> <h1>Login</h1> {{ Form::open() }} <div> {{ Form::Label('username', 'Username') }} {{ Form::Text('username', '') }} </div> <div> {{ Form::label('password', 'Password') }} {{ Form::password('password', '') }} </div> <div> {{ Form::submit('Login') }} </div> {{ Form::close() }} </body> </html> 

And here is the test:

 class LoginCest { public function loginUserWithProperCredentials(WebGuy $I){ $I->am("Site Owner"); $I->wantTo("Login with a password protected area"); $I->lookForwardTo("Perform administrative tasks"); $I->amOnPage('/admin'); $I->seeCurrentUrlEquals('/login'); $I->fillField('username', 'rafael'); $I->fillField("password", "123456"); $I->click("Login"); $I->seeCurrentUrlEquals("/admin"); $I->see("Admin area", "h1"); } } 

Any help would be appreciated.

+6
source share
2 answers

You can copy XPath from the username from html and write:

 $I->fillField('//*[@id="addPosDialog"]/div/button','Username'); 

' //*[@id="addPosDialog"]/div/button ' - insert xpath there. You can use xpath, name, id and other locators. When I have problems with fillField , I usually do something like this.

HTML in this case is more important than presentation code. If my advice does not solve the problem, you need to see the HTML code.

+1
source

I had a problem when the html syntax was wrong. Then phpbrowser does not work reliably. Even so, it does not look like this.

0
source

Source: https://habr.com/ru/post/953938/


All Articles