我正在使用 Codeception 在我的网站上进行验收测试。我试图测试登录表单,但失败了。我尝试手动按照我的测试指示进行操作,它奏效了。因此,我深入研究了 Codeception 的日志,我发现,PhpBrowser 获得的 url 与我的浏览器获得的 url 相同,但没有端口号。
我的测试:
<?php
$I = new WebGuy($scenario);
$I->wantTo('visit login page');
$I->amOnPage('/panel/login');
$I->expectTo('see title of form');
$I->see('Logowanie');
$I->expectTo('see form fields');
$I->seeElement('input[type=text]');
$I->seeElement('input[type=password]');
$I->wantTo('log in without credentials');
$I->click('button[type=submit]');
$I->expectTo('see errors');
$I->see('Pole "Login" jest wymagane');
$I->see('Pole "Hasło" jest wymagane');
$I->wantTo('log in with wrong credentials');
$I->fillField('Login', 'bla');
$I->fillField('Hasło', 'blabla');
$I->click('button[type=submit]');
$I->expectTo('see error');
$I->see('Login lub hasło nieprawidłowe.');
$I->wantTo('log in with correct credentials');
$I->fillField('login', 'admin');
$I->fillField('password', 'admin');
$I->click('button[type=submit]');
$I->expectTo('get redirected to homepage');
$I->canSeeCurrentUrlEquals('/');
$I->expectTo('be logged in');
$I->see('Zalogowano jako Administrator');
$I->see('Wyloguj');
我的表格:
{{ Form::open(['route' => 'login']) }}
<fieldset>
<legend>Logowanie</legend>
<div class="container">
<div class="form-group{{ ($errors->has('login')) ? ' has-error' : ''}}">
{{ Form::label('login', 'Login', ['class' => 'control-label']) }}
{{ Form::text('login', null, ['class' => 'form-control', 'placeholder' => 'Login']) }}
@if($errors->has('login'))
<span class="help-block">
@foreach($errors->get('login') as $error)
<p>{{ $error }}</p>
@endforeach
</span>
@endif
</div>
<div class="form-group{{ ($errors->has('password')) ? ' has-error' : ''}}">
{{ Form::label('password', 'Hasło', ['class' => 'control-label']) }}
{{ Form::password('password', ['class' => 'form-control', 'placeholder' => 'Hasło']) }}
@if($errors->has('password'))
<span class="help-block">
@foreach($errors->get('password') as $error)
<p>{{ $error }}</p>
@endforeach
</span>
@endif
</div>
<div class="checkbox">
<label>
{{ Form::checkbox('rememberMe') }} Zapamiętaj mnie
</label>
</div>
{{ Form::button('<i class="fa fa-sign-in"></i> Zaloguj', ['class' => 'btn btn-primary', 'type' => 'submit']) }}
</div>
</fieldset>
{{ Form::close() }}
如何解决?