Cypress使用POST方法正确记录日志,但登录后未重定向到网页。停留在登录页面上。即使我通过“ cy.visit('web /')”强行执行 保持登录状态 “ cy.get('button')” 在登录页面上找到按钮-登录后不应显示该页面
commands.js
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
offers=(List) results.values;
notifyDataSetChanged();
}
Cypress.Commands.add('login', (username, password) => {
cy.request({
method: 'POST',
url: '/admin-api/login',
headers: {
"Content-Type": "application/json"
},
body: {
username: Cypress.env('correctUsername'),
password: Cypress.env('correctPassword'),
},
retryOnStatusCodeFailure: 463
})
.then((resp) => {
window.localStorage.setItem('jwt', resp.body.user.token)
})
})
答案 0 :(得分:0)
我从上面使用方法获得的cookie中检查了令牌,并且该令牌处于活动状态-我设法通过Postman在此网站中使用了它。但是,上述问题仍然存在。
Cypress.Commands.add('login', () => {
Cypress.log({
name: 'loginViaAuth0'
})
return cy.request({
method: 'POST',
url: '/admin-api/login',
headers: {
"Content-Type": "application/json"
},
body: {
username: Cypress.env('correctUsername'),
password: Cypress.env('correctPassword'),
disposableToken: 1111,
},
retryOnStatusCodeFailure: 463
})
.then((resp) => {
document.cookie = `AuthUser=${resp.body.accessToken}`
})
})
自我测试:
describe('login using token/cookie', () => {
it('should successfully log into our app', () => {
cy.login()
.then(() => {
cy.visit('web')
})
debugger
});
})