我有两个请求:一个是POST请求,另一个是get请求。首先,我通过邮寄方式获取用户访问令牌,在其他情况下,我使用此 accessToken 来登录。我的代码不起作用。
我使用的是window 7和cypress 3.3.5
我的代码:
var value;
describe("Login operation", () => {
it("Login Request with post method", () => {
cy.request({
method:'POST',
url:'https://odms.baitussalam.org:8445/api/v1/auth/login',
body: {
"userName": "faizanj",
"password": "abc"
}
})
.then(function(response){
this.value = response.body.accessToken;
console.log("Value "+this.value);
expect(response.body.name).to.equal('Faizan');
expect(response.status).to.equal(200);
});
});
it('Second test case', function() {
var authHeader='bearer ${'+this.value+'}';
const options = {
method: 'GET',
url: `https://odms.baitussalam.org:8445/api/v1/qurbani-representative`,
headers:{
authorization:authHeader,
}};
cy.request(options)
.then((response)=>{
expect(response.status).to.equal(200);6+9
});
});
});
Run Code Online (Sandbox Code Playgroud)