1 | initial version |
To conduct playwright tests by utilizing variables from the .env file, you can follow these steps:
npm install dotenv
VARIABLE_NAME=value
For example:
USERNAME=myusername
PASSWORD=mypassword
config
method:require('dotenv').config();
process.env
followed by the name of the variable enclosed in brackets:const username = process.env.USERNAME;
const password = process.env.PASSWORD;
await page.type('#username', username);
await page.type('#password', password);
By utilizing variables from the .env file, you can keep sensitive information like usernames and passwords separate from your code and easily manage them in a central location.