代码错误找不到Label或CSS元素的表单字段

问题描述 投票:0回答:1

我正在尝试将测试写入登录页面。只有输入字段和提交按钮。

页面上的HTML / CSS:HTML/CSS on page

我的.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元素。

Error message

我知道

$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元素的表单字段。

Error message

在第三种情况

我的测试文件:

 <?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”的失败元素。

Error message

请帮我找到我在这里缺少的东西。

php automated-tests phpstorm codeception
1个回答
0
投票

函数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');
}
© www.soinside.com 2019 - 2024. All rights reserved.