testing - 如何在 Cypress 中只保存部分 URL(没有域名)

标签 testing url automation path cypress

我正在编写 CY 测试,并试图自己解决几个小时但没有成功。你能帮我一下吗:)

每次我运行测试时,我都会得到新的 URL,例如

https://website.com/en/info/is/here/

我只需要保存

/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/

相关文章:

git - 最佳实践 - Git + 构建自动化 - 保持配置独立

sql-server - 包含测试用例的 SQL Server .sql 文件

r - 如何让 stopifnot() 在调用列表的缺失 (NULL) 元素时返回错误?

winforms - 界面测试工具?

php - .htaccess 文件更改 url 字符串在某些页面上不起作用

python - django.core.urlresolvers.NoReverseMatch

c# - 在 C#/.Net 中以编程方式模拟浏览器

python - 无效参数异常 : Message: invalid argument: 'using' must be a string

VB.NET 应用程序性能测试

java - 如何替换 URL 字符串中的特定 '&' 进行解析