我对Cypress相当陌生,但我完全不明白为什么我的测试在本地通过,但在CI中都失败了。我试着跑过头也没头。
这是我登录的简单代码
describe('The Login Page', () => {
it('successfully logs in via API', () => {
cy.request('POST', `http://localhost:4000/users/login`, {
user: {
email: "USERNAME",
password: "PASSWORD"
}
}).then(({ body }) => {
window.localStorage.setItem('__auth_provider_token__', body.token)
window.localStorage.setItem('user', JSON.stringify(body))
})
cy.visit('/profile')
cy.get('h1').contains('Account')
})
it('Can login using the UI', () => {
cy.visit('/')
cy.intercept('POST', 'http://localhost:4000/users/login').as('postReq')
cy.get('#mui-2').type('USERNAME')
cy.get('#mui-3').type('PASSWORD')
cy.get('form').submit()
cy.wait('@postReq')
cy.get('@postReq')
cy.visit('/profile')
cy.get('h1').contains('Account')
})
it('Should not allow bad credentials', () => {
cy.visit('/')
cy.get('#mui-2').type('foo@example.com')
cy.get('#mui-3').type('wrongpass')
cy.get('form').submit()
cy.get('.MuiAlert-message').contains("Invalid login attempt")
})
})测试1失败测试2失败测试3通过
API调用没有失败,登录后似乎没有加载页面。
发布于 2022-10-12 16:15:04
等待之后,浏览器视图中出现了什么?也许您需要等待更长时间才能加载页面,您可以将pageLoadTimeout: 60000添加到cypress.config中
https://stackoverflow.com/questions/74043656
复制相似问题