Reputation: 4460
My Form doesn't have a Submit button. Instead I used an anchor tag.
<a href="#"
onclick="javascript:submitOfQuestion();"
data-toggle="dropdown"
class="btn btn-primary dropdown-toggle"><i
class="fa fa-upload icon-white"></i> Upload </a>
And I wrote the below test method.
/** @test */
public function testUploadQuestion(){
$this->visit('/upload_question')
->select('Computer', 'subject')
->select('7 - 10', 'ageCategory')
->type('Test Case Test Question 1', 'question')
->attach('C:\xampp\htdocs\IntelliKid\public\test_resources\Capture2.JPG', 'file[]')
->type('Test Case Test Answer 1', 'ans1')
->type('Test Case Test Answer 2', 'ans2')
->type('Test Case Test Answer 3', 'ans3')
->type('Test Case Test Answer 4', 'ans4')
->press('Upload')
->see('Success!');
}
But I get the following error.
1) UploadQuestionTest::testUploadQuestion
InvalidArgumentException: Could not find a form that has submit button [Upload].
C:\xampp\htdocs\IntelliKid\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:731
C:\xampp\htdocs\IntelliKid\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:711
C:\xampp\htdocs\IntelliKid\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:691
C:\xampp\htdocs\IntelliKid\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:678
C:\xampp\htdocs\IntelliKid\tests\UploadQuestionTest.php:33
C:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
C:\xampp\php\pear\PHPUnit\TextUI\Command.php:129
FAILURES!
Tests: 6, Assertions: 14, Errors: 1.
Upvotes: 0
Views: 1278
Reputation: 21
You probably figured this out by now. But another user might have a similar problem, try replacing your: ->press('Upload')
to ->click('Upload')
When you just say "->press
" it expects to receive a button.
Try this and see if it works first. If I were you I'd also go to the view and give my href link an id="Upload"
so that your unit test can identify it when I say ->click('Upload')
I hope this helps. ~T
Upvotes: 2