我的表单没有提交按钮。相反,我使用了锚标记。
<a href="#"
onclick="javascript:submitOfQuestion();"
data-toggle="dropdown"
class="btn btn-primary dropdown-toggle"><i
class="fa fa-upload icon-white"></i> Upload </a>
我写了下面的测试方法。
/** @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!');
}
但我收到以下错误。
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.
答案 0 :(得分:2)
你现在可能已经想到了这一点。但是其他用户可能会遇到类似的问题,请尝试更换您的: - &gt;按(&#39;上传&#39;)到 - &gt;点击(&#39;上传&#39 ;)当你说&#34; - &gt;按&#34;它希望收到一个按钮。
试试这个,看看它是否有效。如果我是你,我也会去视图并给我的href链接 id =&#34;上传&#34; ,这样当我说 - &gt;点击(&#39;上传&#39)
我希望这会有所帮助。 〜Ť