Php behat find field错误:调用未定义的方法LoginAuthContext::find()
我正在编写behat步骤定义,以便在下面的“登录”页面上自动提交用户名和密码字段。通过使用xpath选择器,我得到了以下错误。请告知我做错了什么?谢谢 致命错误:在中调用未定义的方法LoginAuthContext::find() /第20行的behatlogin/features/bootstrap/LoginAuthContext.php 签到表Php behat find field错误:调用未定义的方法LoginAuthContext::find(),php,behat,mink,Php,Behat,Mink,我正在编写behat步骤定义,以便在下面的“登录”页面上自动提交用户名和密码字段。通过使用xpath选择器,我得到了以下错误。请告知我做错了什么?谢谢 致命错误:在中调用未定义的方法LoginAuthContext::find() /第20行的behatlogin/features/bootstrap/LoginAuthContext.php 签到表 <form action="/auth" method="POST" class="ng-pristine ng-valid">
<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>
出现此错误是因为没有扩展正确的类,并且在当前类中看不到
find()
方法
使用IDE编辑器可以帮助您防止此类问题,因为它应该为您提供该类中可用方法的提示
例如,如果您使用的是页面对象,那么您的
LoginAuthContext
需要扩展page
,否则对于经典方法,我认为您需要扩展Context,这似乎是php错误,而不是javascript错误。添加相关标记以获得相关人员的帮助。添加上下文类和行为文件。您是否从正确的类扩展?我添加了use-Behat\Behat\Context\Context代码>和使用SensioLabs\Behat\PageObjectExtension\PageObject\Page代码>但仍然给出错误致命错误:未找到Trait'Behat\Behat\Context\Context
和致命错误:Trait SensioLabs\Behat\PageObjectExtension\PageObject\Page not found
请检查页面对象的文档您有好的示例吗?我试过了,但还是不起作用
/**
* @When /^I am logged in$/
*/
public function iAmLoggedIn()
{
$this->find('xpath','uname')->setValue('testuname');
$this->findField('xpath','pass')->setValue('testpass');
$this->pressButton('Sign in');
}