我正在为我的 laravel 应用程序中的搜索功能编写测试。我想模拟用户行为,所以在我的测试中我有类似
public function testSearchCanBeDone()
{
$this->visit('/')
->type('name', 'query')
->press('Search') //In my case press enter key
->seePageIs('/search?query=name')
->see('Results');
}
}
我的问题出在 ->press('Find')
上,因为我没有搜索按钮。就我而言,在搜索字段中输入内容后,按 Enter 键。我该怎么办呢。这是我的搜索表单的代码
<form method="GET" action="/search" role="search">
<div class="input-field">
<input name = "query" id="search" type="search" class="search" required>
<label for="search">
<i class="material-icons teal-text text-lighten-2">search</i>
</label>
<i class="material-icons">close</i>
</div>
</form>
最佳答案
我认为您跨越了 UI 测试和单元测试之间的界限。解决这个问题的一种方法是调用 $this->get('/search', $params)
关于php - Laravel phpunit 模拟键盘按键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35177026/