我正在尝试将测试写入登录页面。只有输入字段和提交按钮。
我的.yml文件:
actor: AcceptanceTester modules:
enabled:
- phpBrowser:
url: https://myloginpage.test
- \Helper\Acceptance
我的测试文件:
<?php class SigninCest {
public function loginSuccessfully(AcceptanceTester $I)
{
$I->amOnPage('https://myloginpage.test');
$I->see('Enter e-mail');
$I->fillField('userIdentifier','[email protected]');
$I->click('button[type=submit]');
$I->see('Successful login');
}}
在这种情况下,我收到此错误:找不到Label表单字段或带有'userIdentifier'的CSS元素。
我知道
$I->fillField('userIdentifier','[email protected]');
也可以写成
$ I-> fillField(“// input [@ type ='text']”,“[email protected]”);
要么
$ I-> fillField(['name'=>'userIdentifier'],'[email protected]');
所以在我做出改变之后
我的测试文件
<?php class SigninCest {
public function loginSuccessfully(AcceptanceTester $I)
{
$I->amOnPage('https://myloginpage.test');
$I->see('Enter e-mail');
$I->fillField("//input[@type='text']", "[email protected]");
$I->click('button[type=submit]');
$I->see('Successful login');
}}
在这种情况下,我得到相同的错误:找不到Label或带有'// input [@ type ='text']'的CSS元素的表单字段。
在第三种情况
我的测试文件:
<?php class SigninCest {
public function loginSuccessfully(AcceptanceTester $I)
{
$I->amOnPage('https://myloginpage.test');
$I->see('Enter e-mail');
$I->fillField(['name' => 'userIdentifier'], '[email protected]');
$I->click('button[type=submit]');
$I->see('Successful login');
}}
错误消息:找不到名为“userIdentifier”的失败元素。
请帮我找到我在这里缺少的东西。
函数amOnPage
相对于yml配置中的设置获取URL。要提供完整的URL,您应该使用函数amOnUrl
函数。所以你可能想用以下方式编写测试
public function loginSuccessfully(AcceptanceTester $I)
{
$I->amOnPage('/');
$I->see('Enter e-mail');
$I->fillField("//input[@type='text']", '[email protected]');
$I->click('button[type=submit]');
$I->see('Successful login');
}