Override Cypress.config().baseUrl with environment variable (process.env) - cypress

I was to set the baseURL of my cypress tests to be read from .env file.
I can't set it directly in the cypress.json file.
And when I try to use cy.visit(process.env.MYAPPURL), I get an this error
cy.visit() must be called with a url or an options object containing a
url as its 1st argument

you can leave cy.visit() empty but you just need to set this env CYPRESS_BASE_URL with the base url instead like this for example:
CYPRESS_BASE_URL=$VUE_APP_BASE_URL
check this for explanation https://docs.cypress.io/guides/guides/environment-variables

Related

How to make Gitlab CI not apply variable when the variable is in file

I have created a GitLab pipeline and predefined variable (type file). That file contains a variable ${myVar} that should not has to be applied before some steps of the job.
I found that when I open that file using cat, the ${myVar} disappeared. Looks like it was applied but with an empty string since its content has not yet been generated.
Question: how to tell GitLab CI to ignore variables in the variable file
The issue is fixed. All you need to do is to add one more $ sign before the variable. Hence instead of ${myVar} you need to specify $${myVar} in this case GitLab CI will not apply the variable
As of Gitlab 13.7 you can disable variable expansion for the variable (enabled by default). See:
https://gitlab.nposervices.com/help/ci/variables/index#expand-cicd-variables

Variable in library path with JMeter is not working

My JMeter plan config looks like this:
as you can see from the picture the mypath variable has a default value /somehwere which may change based on the machine that hosts JMeter.
So I added it as variable in the ${mypath}/bin below for Library.
However if I run a command like:
jmeter -n ... -Jmypath=/newpath/elsewhere
it is not working. Is there any way to put that path as variable?
You need to amend the variable using __P() function like:
${__P(mypath,/somepath)}
This way you will be able to override the value using -J command-line argument and if you don't provide the override value it will default to /somepath
More information:
Configuring JMeter
Apache JMeter Properties Customization Guide
Overriding Properties Via The Command Line
I answer myself as the solution required is using the parameter -Juser.classpath=some_path which avoid the need to create an external parameter for that case.

How to make Laravel read .env file again?

I'm changing Laravel .env variable after a process, and checking that variable everytime, if it's true code doing one thing, if it's false another thing. But after changing the .env variable I have to restart with php artisan serve, I don't want to do this. Why Laravel does not read the new env variable, it changes on the .env file itself.
You shouldn't have to manipulate environment variables during runtime. If you're trying to manipulate an environment variable, you should probably instead utilize a config value. These configuration files are placed in the config/ directory of your project.
Then during runtime, you can use the following built-in config helper to get/set your config variable.
$value = config('app.timezone');
// To set configuration values at runtime, pass an array to the config helper
config(['app.timezone' => 'America/Chicago']);
$newValue = config('app.timezone');
You can read more about this process here (you can change the version to your version):
https://laravel.com/docs/5.5/configuration#accessing-configuration-values

env helper returns null even if providing default value

Inside my .env I got these two
ATLAS_RELEASES=null
ATLAS_DOWNLOAD=null
Inside my own config file I have this
'releases_url' => env('ATLAS_RELEASES', $baseUrl . 'atlas/raw/master/releases.json'),
'download_url' => env('ATLAS_DOWNLOAD', $baseUrl . 'atlas/releases/download'),
Once some code runs, that uses
$relasesUrl = config('releases_url');
$downloadUrl = config('download_url');
null is returned instead of the second option, which I've specified in the config file. Since I'm not using .env outside of config files, I wonder why I get this behavior?
The above only works if I remove these two completely from the .env file
ATLAS_RELEASES
ATLAS_DOWNLOAD
Any ideas why this strange behavior happens?
As long as the key exists in the .env file no matter if if is null or no value at all, that one will be used.
https://laravel.com/docs/6.x/configuration#retrieving-environment-configuration
The second value passed to the env function is the "default value". This value will be used if no environment variable exists for the given key.

How to Get Environment Value in Config File

Currently, I have an environment variable in my .env file.
MY_NAME_TEST=Testing
How do I pass that variable as part of a path in a config file? I'm trying to get a path similar to below:
base_path('Plugins/Testing/Database/Migrations/')
Notice the "Testing" part of the path in the sample above; I need that name to be different each time.
You're able to retreive the values anywhere in your laravel project by making use of the env function.
env('MY_NAME_TEST'); // returns "Testing"
In your case it would be used like so:
base_path('Plugins/' . env('MY_NAME_TEST') . '/Database/Migrations/'
The second parameter the env function takes is a default value if a value is not already set.

Resources