0
votes

I'm writing the behat step definition to automate the submission of the user name and password fields on the following "Sign In" page. I got the following error by using the xpath selector. Please advise what I did wrong? Thanks!!

Fatal error: Call to undefined method LoginAuthContext::find() in /behatlogin/features/bootstrap/LoginAuthContext.php on line 20

Sign In Form

<form action="/auth" method="POST" class="ng-pristine ng-valid">
        <input type="text" name="uname" id="uname" class="form-control" placeholder="User name" required="" autofocus="">
        <input type="password" name="pass" id="pass" class="form-control" placeholder="Password" required="">
        <button class="btn btn-lg btn-primary btn-block shadow1" type="submit">Sign in</button>
</form>

LoginAuthContext Step Definitions

/**
 * @When /^I am logged in$/
 */
public function iAmLoggedIn()
{
    $this->find('xpath','uname')->setValue('testuname');
    $this->findField('xpath','pass')->setValue('testpass');
    $this->pressButton('Sign in');
}
1
This seems to be php error, not javascript. Add relevant tags to get help from concerned person. - Prabodh M
add your context class and behat file. Do you extend from correct class? - timiTao

1 Answers

0
votes

You got this error because you don't extend the right class and you cannot see the find() method in the current class.

Using an IDE editor can help you prevent these kind of issues because it should give you hints with the available methods in that class.

For example if you are using page objects your LoginAuthContext needs to extend Page, else for the classic approach I think you need to extend Context.