Steps For creating runtime-environment variable
In Terminal
Firstly we need to install the command npm install dotenv --save-dev . This command will install dotenv module in your node modules folder.
For setting up environment variable in runtime (during execution), we need to execute the command
type=<type name> npm run test:<test name>
Eg: type=Uitest npm run test:UI
This command will create a run time variable type with value Uitest while executing the UI test
Passing this environment variable as a parameter in test.js file
async function(){
if(process.env.type=="Uitest"){
some tasks need to be done
}
else if(process.env.type!="Uitest"){
some task need to be done
}
else{
some task need to be done
}
-----While executing the code when the environment variable is with type Uitest then the set of code under if will get executed. When the environment variable is not with type Uitest then the set of code under else if will get executed.When no environment variable is set during run time
eg:npm run test:UI
then the set of code in else will get executed.
Thanks
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…