How to get the token from response header or local storage? #28328
wanghaomiao27
started this conversation in
General
Replies: 1 comment
-
you can use the query cy.window() to get the current localStorage that already exist on your browser and wrap all your code on that callback window(). the details of code :
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a scenario:when I make a login request,I get a token,the token will be generated at response headers,or you can find it at local storage.I want to get the token,because for next request ,it shall use this token.Could anyone give me some detailed code snippets to
get this token and for next request use?Belows are some screenshots for this;
it('登录请求',()=>{
//cy.wrap(localStorage.getItem())
cy.request({
method:'POST',
url:'http://wolf.test.datatist.cn/analyzer/analyzer/account/login.do',
headers:{"Project-Id":"Jevf4ghaKT091r5E",
"Content-Type":"application/json"
},
failOnStatusCode:false,
body:{
"password": "abcd1234",
"rememberMe": true,
"scope": "",
"username": "[email protected]"
}
}).then((response)=>{
expect(response.status).to.eq(200)
}
)
Beta Was this translation helpful? Give feedback.
All reactions