Use environment variables in pactumjs #122
-
Hello, I am using pactum-cucumber-boilerplate project and I have following scenario: Given base URL is "some URL" Instead of using username and password directly in gherkin json body, I am wondering is there any way to save them somewhere in file and call them here in Gherkin scenario? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
We can use DataMaps to make common data available across test cases. In global hooks: const { stash } = require('pactum');
const { Before } = require('@cucumber/cucumber');
Before(() => {
stash.addDataMap({
'App': {
'Username': process.env.APP_USERNAME || 'default-value',
'Password': process.env.APP_PASSWORD || 'default-value'
}
});
}); In feature file: Given base URL is "some URL"
When make a POST request with body to /auth/login
"""
{
"username": "$M{App.Username}",
"password": "$M{App.Password}"
}
""" |
Beta Was this translation helpful? Give feedback.
-
Thank you ASaiAnudeep, problem solved. Works like a charm 👍 |
Beta Was this translation helpful? Give feedback.
We can use DataMaps to make common data available across test cases.
In global hooks:
In feature file: