Skip to content

Use environment variables in pactumjs #122

Answered by ASaiAnudeep
vladparl asked this question in Q&A
Discussion options

You must be logged in to vote

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}"
}
"""

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@vladparl
Comment options

Answer selected by ASaiAnudeep
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants