当页面中有两个表单时,Laravel测试无法访问的字段错误

时间:2017-01-14 11:44:10

标签: php laravel laravel-5.1

我想测试一个有两种形式的页面。 当我想测试我的一个表单时,会发生以下错误:

Unreachable field "count"

哪个count是该格式的字段(它不会以其他形式退出)。当我完全删除另一个表单时,它可以正常工作,但我需要在页面中同时使用它们。

这是我的观点:

    <section class="content">
        <div class="row">
            <div class="col-md-6">
                <div class="panel panel-green">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            Passenger Credit Adjustment
                        </h3>
                    </div>
                    <div class="panel-body">
                        <form method="post" action="{{route('credits.passenger.post', ['id' => $passenger->id])}}">
                            {{csrf_field()}}
                            <div class="form-group">
                                <label for="amount">Name</label>
                                <input type="text" class="form-control" id="name" name="name" disabled="disabled"
                                       title="" value="{{$passenger->fullname}}">
                            </div>
                            <div class="form-group">
                                <label for="amount">Credit</label>
                                <input type="text" class="form-control" id="cashable" name="name" title=""
                                       disabled="disabled" value="{{number_format($credit) . ' RLS'}}">
                            </div>
                            <div class="form-group">
                                <label for="amount">Add/DeductAmount</label>
                                <input type="text" class="form-control" id="amount" name="amount">
                            </div>
                            <div class="form-group">
                                <label for="description">Description</label>
                                <input type="text" class="form-control" id="description" name="description">
                            </div>
                            <button type="submit" class="btn btn-danger">Apply</button>
                        </form>
                    </div>
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <i class="livicon" data-name="money" data-loop="true" data-color="#fff"
                               data-hovercolor="#fff" data-size="18"></i>
                            Voucher
                        </h3>
                    </div>
                    <div class="panel-body">
                        <form method="post"
                              action="{{route('credits.rideVoucher.post', ['id' => $passenger->id])}}">
                            {{csrf_field()}}
                            <div class="form-group">
                                <label for="type">Type</label>
                                <select id="single-prepend-text" class="form-control select2" title=""
                                        name="type">
                                    <option value="5k">5k</option>
                                    <option value="10k">10k</option>
                                    <option value="20k">20k</option>
                                    <option value="15p">15%</option>
                                    <option value="20p">20%</option>
                                    <option value="25p">25%</option>
                                    <option value="30p">30%</option>
                                    <option value="50p">50% (Max 10k)</option>
                                    <option value="100p">100% (Max 20k)</option>
                                </select>
                            </div>
                            <button type="submit" class="btn btn-danger" name="generate">Generate</button>
                        </form>
                    </div>
                </div>
            </div>

            <div class="col-md-6">
                <div class="panel panel-green">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            Free Ride
                        </h3>
                    </div>
                    <div class="panel-body">
                        <form method="post"
                              action="{{route('credits.passenger.freeRide.post', ['id' => $passenger->id])}}">
                            {{csrf_field()}}
                            <div class="form-group">
                                <label>Number of free ride(s):</label>
                                <input type="number" name="count" value="1" title="Count"  id="count"
                                       class="form-control">
                            </div>
                            <div class="form-group">
                                <label>Cap:</label>
                                <select class="form-control" name="cap" title="">
                                    <option value="">[NOT SELECTED]</option>
                                    <option value="50000">5,000 T</option>
                                    <option value="100000">10,000 T</option>
                                    <option value="150000">15,000 T</option>
                                    <option value="200000">20,000 T</option>
                                </select>
                            </div>
                            <input type="submit" class="btn btn-danger" name="generate" value="Generate">
                        </form>
                    </div>
                </div>
            </div>
        </div>

这是我的考验:

$this->visit($uri)
        ->type(3, 'count')
        ->select($cap, 'cap')
        ->press('Generate')

我正在使用Laravel 5.1。

1 个答案:

答案 0 :(得分:0)

两个提交按钮都具有相同的名称。尝试使用不同的名称。此外,您可以使用submitForm方法

,而不是使用press