1 week ago

How to update environment/config variable in Cypress?

Posted 1 week ago by squibby

Is there anyway to set config variables either before or during Cypress tests? It may not be possible but this is what I have tried...

I have a some routes like:

    Route::get('/_testing/config', 'Cypress\[email protected]');
    Route::post('/_testing/config', 'Cypress\[email protected]');

Then in controller:

    public function getConfig()
        return config()->get(request('key'));

    public function setConfig()
        config()->set(request('key'), request('value'));
        return config()->get(request('key'));

Then from a Cypress test I want to update some config like:

            method: 'POST',
            url: '/_testing/config?key=somekey&value=somevalue',
            form: true,
        }).its('body').then((res) => {

            // 'somevalue'


When running this the correct config item is returned and I assume should be then reflected in the app (I have some environment vars to toggle sections of a site) but... it doesn't work...

Is this simply not possible. to do in this manner? I do not really want to have multiple .env files and switch them depending on test types, although this could be possible as a last resort.


Please sign in or create an account to participate in this conversation.