7

I'm trying to carry out a simple acceptance test for learning purpose. It's a simple authentication scenario : user enters /admin, If not logged it, He gets redirected to /login to fill 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's 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's 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.

Rafael Adel
  • 7,673
  • 25
  • 77
  • 118

2 Answers2

2

You may copy XPath of username from html, and write:

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

'//*[@id="addPosDialog"]/div/button' - paste your xpath there. You may use xpath, name, id and other locators. When I have problems with fillField i am usually doing something like this.

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

Simon East
  • 55,742
  • 17
  • 139
  • 133
FelAl
  • 31
  • 2
0

I had the issue where the html syntax was not correct. Then the phpbrowser works not reliable. Even so it does not look like it in your example.

fehrlich
  • 2,497
  • 2
  • 26
  • 44