我正在尝试使用 Cypress 为这个应用程序编写端到端测试:https://app.gotphoto.com/admin/auth/login
当我从浏览器访问上述 url 时,会显示一个登录表单,正如预期的那样。
当我通过 Cypress 访问上述网址时:
https://app.gotphoto.com/admin/auth/login
https://app.gotphoto.com/__/
并且登录表单未显示 这是 Cypress 内部的两个屏幕截图:
我的问题是:为什么它在我的浏览器中的运行方式与它在 Cypress / Cypress 的浏览器中的运行方式之间存在差异?
我使用的浏览器是 Chrome 89,无论在有和没有 Cypress 的情况下运行。
我正在运行的整个测试是这样的:
describe('login screen', () => {
it('logs in', () => {
cy.visit('/admin/auth/login');
});
});
使用 cypress.json:{
"baseUrl": "https://app.gotphoto.com"
}
我创建了一个 repo使用上述配置,因此很容易重现。
最佳答案
/__/
https://app.gotphoto.com/__/
的一部分被称为 客户端路由 是 Cypress 的内部配置项。
您可以在 cypress.json
中将其关闭。配置文件
{
...
"clientRoute": "/"
}
这有效地保留了您的原始网址并允许页面正确加载。cy.visit('https://app.gotphoto.com/admin/auth/login')
cy.get('input#username', { timeout: 10000 }).type('admin') // long timeout
// wait for page to load
cy.get('input#password').type('password')
cy.intercept('POST', 'api.getphoto.io/v4/auth/login/user').as('user')
cy.contains('button', 'Submit').click()
cy.wait('@user').then(interception => {
// incorrect credentials
expect(interception.response.body.detail).to.eq('Login failed!')
})
我不确定更改 clientRoute
是否有任何不良副作用,如果我找到它会发布更多信息。
关于javascript - 柏树中的应用程序重定向,外部没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66613875/