How can I access the token generated from 1st it
block to 2nd it
block.
here is the code:
1st it block
it('Login using new user', () => {
cy.api({
method: "POST",
url: "https://api-stg.sample.com/v1/user/login",
body:
{
"mobile_number": "+9912345678"
"password": "p@ssword"
}
})
.then((response) => {
expect(response.status).to.eq(200)
})
.then((response) => {
const bearer_token = response.body.data.user.access_token.token //
*in here where I get and put the token in var bearer_token*
cy.log("Bearer token: " + token )
})
})
2nd it block
it('Create New Mobile', () => {
cy.api({
method: "POST",
url: "https://api-stg.sample.com/v1/user/add_new_mobile_numbers",
headers: {
'Authorization': 'Bearer ' + token // *in here where I put the token*
},
body:
{
"mobile_prefix": "+991",
"mobile_number": "9912345679"
}
})
I login from 1st block, then i need to use the token to add new mobile num in 2nd block.
in cypress dashboard it returns an error:
token is not defined