【问题标题】:How to turn off console printing in Laravel Dusk testing?如何在 Laravel Dusk 测试中关闭控制台打印?
【发布时间】:2018-12-28 08:05:41
【问题描述】:

当我运行我的 laravel 黄昏测试时,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)

如何防止这种情况发生?它会在测试时通过每个页面显示此内容

【问题讨论】:

  • 这其实是个严重的问题……

标签: laravel laravel-5 vue.js laravel-dusk


【解决方案1】:

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

您可以将参数传递给 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
        )
    );
}

...

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

【讨论】:

  • 我添加了它,它似乎对我不起作用。还有其他想法吗?
  • 这可能有changed with v75。尝试添加$options->setExperimentalOption('excludeSwitches', [enable-logging']);
猜你喜欢
  • 2019-12-22
  • 1970-01-01
  • 2014-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-12
  • 2017-07-08
相关资源
最近更新 更多