4

I'm trying to alter some config values before each test. However, the browser does not apply them.

In my DuskTestCase file:

abstract class DuskTestCase extends BaseTestCase
{
    use CreatesApplication;

    protected function setUp()
    {
        parent::setUp();

        config()->set('cookie-consent.enabled', false);
        config()->set('app.recaptcha', false);
        config()->set('localization.acceptLanguage', false);
    }

    /**
     * Prepare for Dusk test execution.
     *
     * @beforeClass
     * @return void
     */
    public static function prepare()
    {
        static::startChromeDriver();
    }

    ...

The config values are correctly set in each test, but not for the browser. When I remove the '--disable-gpu' I clearly see that the browser is still using the old config values.

How can this be changed as well?

Philipp Mochine
  • 4,351
  • 10
  • 36
  • 68
  • 2
    `config()` has no effect because the Dusk test and the app are running in separate processes. Do you want to set these config values for *all* Dusk tests? – Jonas Staudenmeir Jan 28 '19 at 19:48
  • @JonasStaudenmeir yes I see that and made a workaround for my specific problem. But I'm not sure what you mean with *all*? With DuskTestCase it's going to be all in my tests. But as you said it runs in a separate process so the "server-side" has still the old config files. – Philipp Mochine Jan 29 '19 at 17:21
  • 1
    What I meant: If all tests should run with these config values, the best solution is a `.env.dusk.local` file (see [documentation](https://laravel.com/docs/dusk#environment-handling)). I asked because I've seen people who wanted to change config values only for specific tests, which is more complicated. – Jonas Staudenmeir Jan 29 '19 at 17:24
  • @JonasStaudenmeir Can you please see if you know of a workaround for Dusk for https://github.com/laravel/framework/issues/27695#issuecomment-543436443 now that DotEnv is immutable? (See "Read-Only env Helper" at https://laravel.com/docs/5.8/upgrade#support) Thanks! – Ryan Oct 18 '19 at 01:20
  • @JonasStaudenmeir I wrote it as its own question here: https://stackoverflow.com/q/58450836/470749 Thanks in advance for any help! – Ryan Oct 18 '19 at 12:20

1 Answers1

0

In order to get an approach like this:

$browser
  ->withConfig(['currency' => 'EUR'])
  ->visit('/')
  // -> ..

You'll need to add and register middleware, override Browser and register it in DuskTestCase. Details here: https://gist.github.com/wrabit/e01df16858505c395b7b0d271112a023

digout
  • 4,041
  • 1
  • 31
  • 38