我正在编写 CY 测试,并试图自己解决几个小时但没有成功。你能帮我一下吗:)
每次我运行测试时,我都会得到新的 URL,例如
我只需要保存
/en/info/is/here/ (so without domain name)
稍后我需要将它与另一个 href 进行比较。
你能告诉我怎么做的方式或者至少是方向吗?非常感谢!
最佳答案
cy.location()命令给你命名的部分,所以从例子中 pathname
是你需要的部分
cy.visit('http://localhost:8000/app/index.html?q=dan#/users/123/edit')
cy.location().should((loc) => {
..
cy.wrap(loc.pathname).as('url1')
...
})
如果你也有搜索或散列
cy.visit('http://localhost:8000/app/index.html?q=dan#/users/123/edit')
cy.location().should((loc) => {
..
cy.wrap(loc.pathname + loc.search + loc.hash).as('url1')
...
})
关于testing - 如何在 Cypress 中只保存部分 URL(没有域名),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74042478/