如何在 Laravel Dusk 测试中关闭控制台打印?

Raj*_*Raj 2 laravel vue.js laravel-5 laravel-dusk

当我运行 laravel dusk 测试时,cmd 显示许多控制台消息,例如:

DevTools listening on ws://127.0.0.1:12802/devtools/browser/dbffc66a-0b29-4149-a1b5-8f20259770c2
[0720/101840.929:INFO:CONSOLE(44479)] "Download the Vue Devtools extension for a better development
experience:
https://github.com/vuejs/vue-devtools", source: http://localhost:8000/js/app.js (44479)
[0720/101840.929:INFO:CONSOLE(44490)] "You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html", source: http://localhost:8000/js/app.js (
44490)
Run Code Online (Sandbox Code Playgroud)

我怎样才能防止这种情况发生?它在测试时浏览每个页面时显示此内容

dr_*_*mio 5

这个回复有点晚了,但我现在才想到这个问题。

您可以将参数传递给 Chrome 驱动程序以防止控制台日志记录,如下所示。

在 Laravel 5.8 上

测试\DuskTestCase.php

...


/**
 * Create the RemoteWebDriver instance.
 *
 * @return \Facebook\WebDriver\Remote\RemoteWebDriver
 */
protected function driver()
{
    $options = (new ChromeOptions)->addArguments([
        '--disable-gpu',
        '--headless',
        '--window-size=1920,1080',
        '--log-level=3', // Add this line
        '--silent' // Add this line
    ]);

    return RemoteWebDriver::create(
        'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
            ChromeOptions::CAPABILITY, $options
        )
    );
}

...
Run Code Online (Sandbox Code Playgroud)

这将关闭所有控制台消息。

  • 这可能已[随着 v75 的改变](/sf/answers/3993073171/)。尝试添加 `$options->setExperimentalOption('excludeSwitches', [enable-logging']);` (2认同)