环境:
黄昏5.0.2,Laravel 5.7.28,PHP 7.2.14,PHPUnit 7.5.8,MySQL 5.7,Laravel Homestead,ChromeDriver 2.45.615279
问题:
№1
Tests \ Browser \ :: tearDownDuskClass中的异常 将http删除引发的卷曲错误抛出到/ session / e76b9bfe8c9f9af519c2901601531c6a
操作在30000毫秒后超时,收到0个字节
№2
Facebook \ WebDriver \ Exception \ WebDriverCurlException:抛出卷曲错误 用于http POST到/ session / ce9d54d51ec982ff77aa5ca202159ca4 / log 参数:{“ type”:“浏览器”}
操作在30001毫秒后超时,收到0个字节
由Facebook \ WebDriver \ Exception \ WebDriverCurlException引起:Curl HTTP GET引发错误 / session / ce9d54d51ec982ff77aa5ca202159ca4 / screenshot
操作在30001毫秒后超时,收到0个字节
测试课程:
class MyTest extends DuskTestCase
{
use DatabaseMigrations, WithFaker;
public function testExample()
{
$user = \factory(User::class)->create();
$this->browse(function (Browser $browser) use ($user) {
$browser
->loginAs($user)
->visitRoute(/**/)
->waitForText(/**/)
->type(/**/)
->type(/**/)
->type(/**/)
->attach(/**/, /**/)
->press(/**/)
->waitForText(/**/)
->assertSeeIn(/**/)
->click(/**/)
->assertSeeIn(/**/)
->click(/**/); //new tab is opened
$windows = collect($browser->driver->getWindowHandles());
//navigate to new tab
$browser->driver->switchTo()->window($windows->last());
$browser->assertPathIs(/**/);
});
}
}
随机抛出异常。通常,启动虚拟机后的第一个测试就是成功。
更新:使用暂时解决
$window = $browser->driver->getWindowHandles()[1];
$browser->driver->switchTo()->window($window);
更新2:即使在测试结束时使用此代码也会导致错误
$browser->driver->switchTo()->window($browser->driver->getWindowHandles()[1]);
$browser->screenshot('scr');
$browser->driver->switchTo()->window($browser->driver->getWindowHandles()[0]);