如何使fillField()适用于功能测试Codeception + Laravel 5.2

时间:2016-04-15 12:39:17

标签: php laravel-5.2 functional-testing codeception php-5.6

我正在编写一些功能测试来测试我的应用程序的登录系统。我尝试了以下使用fillField()的方法,但无法让它对我有用。

$I->fillField(['id' => 'loginEmail'], 'sample@mail.com');

$I->fillField("//input[@id='loginEmail']", 'sample@mail.com');

之后,当我尝试运行seeInFormFields()方法时,它给出了以下错误:

 Step  I see in form fields "form[name=loginForm]",{"email":"sample@mail.com","password":123456}
 Fail  Failed asserting that `sample@mail.com` is in input's value: array (
  0 => '',
)
Failed asserting that an array contains 'sample@mail.com'.

需要注意的是,我在同一页面上有相同name的注册表单,这就是为什么我必须使用ID

非常感谢任何帮助或建议。

使用HTML代码更新

以下是我的HTML表单代码

<form name="loginForm" class="" method="POST" action="https://domain/en-us/checkout/login">
        <div class="col-sm-12 wrapper generic-form collapse-form" ng-controller="mobileController">
            <fieldset>
                <legend
                    class="legend-login">
                    I have an account
                </legend>
                <div class="collapse-panel">
                    <div class="col-xs-12 control-group">
                        <div class="row form-group" ng-class="{ 'has-error' : loginForm.email.$error.required && submitted }">
                            <div class="col-sm-4 col-xs-12 text-right">
                                <label for="email">E-Mail</label>
                            </div>
                            <div class="col-sm-8 col-xs-12">
                                <input
                                        name="email"
                                        type="email" class="form-control"
                                        id="loginEmail"
                                        required>
                                <small class="ico-buttons ico-error red">
                                    Mandatory
                                </small>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <div class="row form-group" ng-class="{ 'has-error' : loginForm.password.$error.required && submitted }">
                            <div class="col-sm-4 col-xs-12 text-right">
                                <label for="password">Password</label>
                            </div>
                            <div class="col-sm-8 col-xs-12">
                                <input  name="password"
                                        type="password"
                                        class="form-control"
                                        id="password"
                                        required>
                                <small class="ico-buttons ico-error red">
                                    Mandatory
                                </small>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <div class="row form-group">
                            <div class="col-xs-12 col-sm-8 col-sm-offset-4">
                                <input type="button" value="Login" name="submitWelcomeLoginForm">
                            </div>
                        </div>
                                <br>
                                <a href='https://domain.com/' class='pull-right'>Forgot Password?</a>
                    </div>
                </div>
            </fieldset>
        </div>
        <div class="clearfix"></div>
    </form>

2 个答案:

答案 0 :(得分:0)

第一个参数是字段

的字符串名称
$I->fillField('email', 'sample@mail.com');

您可以在此处找到许多测试脚本:https://github.com/satrun77/tinyissue/blob/master/tests/functional

使用的测试脚本fillField https://github.com/satrun77/tinyissue/blob/master/tests/functional/CrudIssueCest.php

答案 1 :(得分:0)

你的问题不在于fillField不起作用,
这是seeInFormFields没有看到填充值,它只能看到页面原始HTML中的值。