Laravel Dusk屏幕截图 [英] Laravel Dusk screenshot
问题描述
我正在使用laravel 5.6
和 Dusk
进行一些测试.
I'm using laravel 5.6
and Dusk
for running some tests.
我总是像这样拍摄我的屏幕截图
I'm always taking my screenshot like this
...
use Facebook\WebDriver\WebDriverDimension;
...
class LoginTest extends DuskTestCase
{
public function testLogin()
{
$user = User::first();
$this->browse(function ($browser) use ( $user ) {
$test = $browser->visit( new Login)
->resize(1920,1080)
...
->driver->takeScreenshot(base_path('tests/Browser/screenshots/testLogin.png'));
});
}
}
但是随着我的测试越来越多地使用,我不想每次都继续编写-> resize(X,Y)
和 base_path('bla/blab/bla')
.
But as my tests will be more and more used, I don't want to continue to write everytime ->resize(X,Y)
and base_path('bla/blab/bla')
.
我想为将要编写的每个测试定义 size 和 path .
I wanted to define the size and path for every tests that will be written.
我想我应该在 tests/DesukTestCase.php
中定义一些函数,但是我什至不知道如何获取驱动程序等等.
I guess I should define some function in tests/DesukTestCase.php
but I'm not even aware of how I can retrieve the driver and so on.
您有关于此的一些指导或文档吗?因为我什么都找不到...
Have you got some guidance or documentation about this? Because I can't find anything...
推荐答案
您只需在 $ options
中添加'-window-size = 1920,1080'
.这会将1920x1080的屏幕分辨率应用于您的所有Dusk测试.随时调整为所需的任何窗口大小.
You only need to add '--window-size=1920,1080'
in $options
. This will apply a 1920x1080 screen resolution to all your Dusk tests. Feel free to adjust to whatever window size you want.
因此您的DuskTestCase.php文件应如下所示:
So your DuskTestCase.php file should look like this:
protected function driver()
{
$options = (new ChromeOptions())->addArguments([
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
]);
$driver = RemoteWebDriver::create(
'http://selenium:4444/wd/hub',
DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY,
$options
)
);
}
这篇关于Laravel Dusk屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!