vendredi 23 janvier 2015

Behat pressButton not working in laravel 5

http://ift.tt/1DVHR9c


This is the tutorial by Jeoffery Way that I am testing


This is the scenario that I am trying to test



Scenario: Adding a new school
When I add a new school with "Narendra School" "This is a cool school"
Then I should see "Add School"
And a school is created


This is my feature context file,



/**
* @When I add a new school with :arg1 :arg2
*/
public function iAddANewSchoolWith($name , $description )
{
$this->visit('school/create');
$this->fillField( 'name', $name );
$this->fillField( 'description', $description );
$this->pressButton('register');
}

/**
* @Then a school is created
*/
public function aSchoolIsCreated()
{
$school = School::all();
PHPUnit::assertEquals($school->isEmpty(), false );
}


This is my html code



<form method="post">
<h2>Add School</h2>

<input type="hidden" name="_token" value="{!! Session::getToken() !!}"/>

<input type="text" name="name" placeholder="Name">
<textarea name="description" placeholder="Description"></textarea>
<button name="register">Register</button>
</form>


This is the controller method that i am using to create the object



function create( ) {

if ( \Request::isMethod( 'post' ) ) {

$this->school->add( \Input::all() );// I am using a repository and dependency injection so this code is fine, it will add a school
}

return view('school::school.add');
}


When I hit the url, fill the form and hit register in the browser, I save a new school but when I run the test, I cannot seem to create the school. The test is running I can see the html when I do a printLastResponse()



Feature: Testing
In order to teach Behat
As a teacher
I want to add a new school

Scenario: Adding a new school # features\example.feature:6
When I add a new school with "Narendra School" "This is a cool school" # FeatureContext::iAddANewSchoolWith()
Then I should see "Add School" # FeatureContext::assertPageContainsText()
And a school is created # FeatureContext::aSchoolIsCreated()
Failed asserting that false matches expected true.

--- Failed scenarios:

features\example.feature:6

1 scenario (1 failed)
3 steps (2 passed, 1 failed)
0m3.10s (26.24Mb)


This is my terminal log What am I doing wrong?


Aucun commentaire:

Enregistrer un commentaire