Stashing a value to use across multiple tests is not returning a value #264
MeganOzanne
started this conversation in
General
Replies: 1 comment 3 replies
-
Hi @MeganOzanne, Since you are using CucumberJS, you can add the code to retrieve access token in a You can still leverage request.setDefaultHeaders('Authorization', '$S{accessToken}'); Reference: Here is an example cucmberJS implementation with PactumJS (doesn't have auth setup included and not in typescript though) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm trying to build out some tests using Pactum and my final hurdle is passing my auth token across multiple files so that I don't need to call my auth endpoint for every test. Please could someone assist me to see what I'm doing wrong?
My setup is using:
Pactum
Cucmber
Typescript
Chai
My request to get my auth token is this:
` export async function getAccessToken() {
//this.response = await s.toss()
//return this.response.body.access_token
//.returns((ctx) => { return ctx.res.body.access_token });
};`
I then attempt to use
.withHeaders('Authorization', '$S{GetAuthToken}')
within my further requests, within different files but it outputs $S{GetAuthToken} rather then the required value.I have also tried using:
`const getToken = getAccessToken().then(
function(accessToken) {return accessToken;}
);
const token = await getToken`
But this returns
TypeError: getAccessToken is not a function
Given Pactum provides a way to store and retrieve data I thought this task would be fairly simple. TIA
Beta Was this translation helpful? Give feedback.
All reactions