我是赛普拉斯的新手。我的应用程序作为“路由系统”手动更改window.location.hash
。在某个时候,我单击了一个按钮,该按钮更改了哈希值,因此应该在测试期间更改页面。我可以看到在执行过程中出现了一个“新网址”条目,但是如何使柏树访问该网址?
简而言之:如何使cypress跟随重定向?
这是测试代码
context("Workflow", () => {
it("login", () => {
cy.visit("http://localhost:3000/src/#login")
cy.get("#username").type("demo").should("have.value", "demouser")
cy.get("#password").type("demo{enter}").should("have.value", "demo") // this should redirect to "/#home"
//cy.wait(10000)
cy.get(".subtitle").should("have.value", "Welcome") //this line fails as ".subtitle" is an element of "/#home"
})
})
有一些方法可以做到这一点。基本方法之一是这样的:
cy.visit(`your_login_page`)
cy.get('[data-testid="input-username"]').type(`demo`, { force: true })
cy.get('[data-testid="input-password"]')
.type(`demo`, {
force: true,
})
.wait(1000)
.then(() => {
cy.location().should((loc) => {
expect(loc.pathname).to.eq(your_new_url)
})
})