Написание функционального теста на Laravel 4 с кодовым восприятием.
мой tests/functional/UserSignUpCept.php
файл.
<?php
$I = new FunctionalTester($scenario);
$I->am('a guest');
$I->wantTo('sign up for a musician account');
$I->amOnPage('/');
$I->click('Sign Up as User');
$I->seeCurrentUrlEquals('/user/register');
$I->fillField(['name' => 'email'], '[email protected]');
$I->fillField(['name' => 'password'], '123456');
$I->fillField(['name' => 'password_confirmation'], '123456');
$I->fillField(['name' => 'first_name'], 'jon');
$I->fillField(['name' => 'last_name'], 'deo');
$I->selectOption(['form select[name=gender]'], 'm');
$I->selectOption(['name' => 'zipcode_id'], '1');
$I->fillField(['name' => 'phone'], '01234567891');
$I->click('Register');
$I->seeCurrentUrlEquals('');
$I->see('The user has been successfully created. Activation mail has been sent to your email address.');
Мой регистр просмотра
{{ Form::open(array('route' => 'user.register', 'class' => 'form-horizontal', 'role' => 'form')) }}
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<div class="form-group">
<label for="email" class="col-sm-4 control-label"><i class='small glyphicon glyphicon-asterisk' style='color: red;'></i> E-mail Address:</label>
<div class="col-sm-8">
{{ Form::email('email', null, array('id' => 'email', 'class' => 'form-control', 'placeholder' => '[email protected]', 'tabindex' => 1)) }}
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-4 control-label"><i class='small glyphicon glyphicon-asterisk' style='color: red;'></i> Password:</label>
<div class="col-sm-8">
{{ Form::password('password', array('id' => 'password', 'class' => 'form-control', 'placeholder' => '******', 'tabindex' => 2)) }}
</div>
</div>
<div class="form-group">
<label for="password_confirmation" class="col-sm-4 control-label"><i class='small glyphicon glyphicon-asterisk' style='color: red;'></i> Password (Confirm):</label>
<div class="col-sm-8">
{{ Form::password('password_confirmation', array('id' => 'password_confirmation', 'class' => 'form-control', 'placeholder' => '******', 'tabindex' => 3)) }}
</div>
</div>
<div class="form-group">
<label for="first_name" class="col-sm-4 control-label"><i class='small glyphicon glyphicon-asterisk' style='color: red;'></i> First Name:</label>
<div class="col-sm-8">
{{ Form::text('first_name', null, array('id' => 'first_name' , 'class' => 'form-control', 'tabindex' => 4)) }}
</div>
</div>
<div class="form-group">
<label for="last_name" class="col-sm-4 control-label"><i class='small glyphicon glyphicon-asterisk' style='color: red;'></i> Last Name:</label>
<div class="col-sm-8">
{{ Form::text('last_name', null, array('id' => 'last_name', 'class' => 'form-control', 'tabindex' => 5)) }}
</div>
</div>
<div class="form-group">
<label for="gender" class="col-sm-4 control-label">Gender:</label>
<div class="col-sm-8">
<label class="radio-inline" for="gender_ns">
{{ Form::radio('gender', '', true, array('id' => 'gender_ns', 'tabindex' => 6)) }} Not Specified
</label>
<label class="radio-inline" for="gender_m">
{{ Form::radio('gender', 'm', false, array('id' => 'gender_m', 'tabindex' => 6)) }} Male
</label>
<label class="radio-inline" for="gender_f">
{{ Form::radio('gender', 'f', false, array('id' => 'gender_f', 'tabindex' => 6)) }} Female
</label>
</div>
</div>
<div class="form-group">
<label for="zipcode" class="col-sm-4 control-label">Zipcode:</label>
<div class="col-sm-8">
{{ Form::select('zipcode_id', $zipcodes, null, array('id' => 'zipcode', 'class' => 'form-control', 'placeholder' => 'Start typing your zipcode', 'tabindex' => 7)) }}
</div>
</div>
<div class="form-group">
<label for="phone" class="col-sm-4 control-label">Phone:</label>
<div class="col-sm-8">
{{ Form::text('phone', null, array('id' => 'phone', 'class' => 'form-control', 'tabindex' => 8)) }}
<p class="help-block">Eg. "02099999999"</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-8 col-sm-offset-4 control-label checkbox-inline" for="newsletter">
{{ Form::checkbox('newsletter', '1', null, ['id' => 'newsletter', 'tabindex' => 9]) }} I want to subscribe to Musician newsletter
</label>
</div>
<div class="form-group pull-right">
<div class="col-sm-4">
{{ Form::submit('Register', array('class' => 'btn btn-default', 'tabindex' => 10)) }}
</div>
</div>
</div>
{{ Form::close() }}
Я запускаю кодекс на терминале
vagrant@homestead:~/Code/musician$ vendor/bin/codecept run functional
Codeception PHP Testing Framework v2.0.11
Powered by PHPUnit 4.4.5 by Sebastian Bergmann.
Functional Tests (1) -------------------------------------------------------------------------------------------------
Sign up for a musician account (UserSignUpCept) Fail
----------------------------------------------------------------------------------------------------------------------Time: 2.58 seconds, Memory: 32.25Mb
There was 1 failure:
---------
1) Failed to sign up for a musician account in UserSignUpCept (/home/vagrant/Code/musician/tests/functional/UserSignUpCept.php)
Couldn't select option "form select[name=gender]"],"m":
Element with 0 'form select[name=gender]' was not found on page.
Scenario Steps:
10. I select option "form select[name=gender]"],"m"9 . I fill field {"name":"last_name"},"deo"8 . I fill field {"name":"first_name"},"jon"7 . I fill field {"name":"password_confirmation"},"123456"6 . I fill field {"name":"password"},"123456"5 . I fill field {"name":"email"},"[email protected]"4 . I see current url equals "/user/register"
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Я осмотрел http://codeception.com/docs/modules/Laravel4. Но я не мог решить.
Как я могу исправить этот тест для группы переключателей?
Заранее спасибо.
Проблема заключается в используемом вами селекторе. HTML для Пол это что-то вроде:
<div class="form-group">
<label for="gender" class="col-sm-4 control-label">Gender:</label>
<div class="col-sm-8">
<label class="radio-inline" for="gender_ns">
<input id="gender_ns" tabindex="6" checked="checked" name="gender" type="radio" value=""> Not Specified
</label>
<label class="radio-inline" for="gender_m">
<input id="gender_m" tabindex="6" name="gender" type="radio" value="m"> Male
</label>
<label class="radio-inline" for="gender_f">
<input id="gender_f" tabindex="6" name="gender" type="radio" value="f"> Female
</label>
</div>
</div>
Ты используешь form select[name=gender]
в коде. Проблема в том, что у вас нет поля выбора. У вас есть входы.
Вы должны использовать form input[name=gender]
и проблема должна быть решена.
Других решений пока нет …