javascript - 处理 Cypress url 重定向
问题描述
我有一个赛普拉斯测试,它点击图像导致重定向到特定网址。然后测试检查 url 是否包含特定的字符串。
但是,单击此图像会导致测试停止/失败,并显示“哎呀,没有要运行的测试”。重定向发生时的消息。
Cypress 测试非常简单:
/* global describe, it, cy */
import loadStory from '../../../config/cypress/helpers/loadStory'
const component = 'product-card'
const productCardImage = '[data-test=component-product-card_imageContainer]'
describe(`${component} component interaction tests`, () => {
it('clicking the image should open the products page', () => {
loadStory(component, 'Default')
cy.get(productCardImage).should('be.visible')
cy.get(productCardImage).click()
cy.url().should('contain', '/product')
})
})
我的测试继续运行,http://localhost:9002
似乎http://localhost:9002/product/productId
在测试套装运行时重定向到是导致赛普拉斯崩溃/失败的原因,而赛普拉斯试图去https://localhost:9002/__/
我想知道如何单击此图像并重定向到 url 而不会导致赛普拉斯崩溃/失败。
解决方案
赛普拉斯不支持跨域。
示例:第 1 步:您导航到 google 第 2 步:搜索 Gmail 第 3 步:点击 gmail 链接
您正在从 Google.com 切换到 gmail.com - cypress 不支持此操作。
解决方法 1:您可以将设置 href 属性值删除为空白,如下所示:
target="_blank" 以便它将在同一页面中打开。
解决方法 2:
将步骤 1 和步骤 2 放在一个测试迭代中
并将步骤 3 放在另一个迭代中
推荐阅读
- c# - 自定义 IRouteConstraint:返回自定义响应而不是 404[NotFound]
- asp.net-core - 使用 ASP.NET Core 身份模型测试密码
- javascript - 如何在 JS 中获取 CosmosDB 中的帐户名
- javascript - 未捕获的 SyntaxError:预期的表达式,得到 ','
- docker - 如何在 docker-compose 中使用本地环境变量
- android - 如何更改 Android 设备蓝牙模块的 TxPower
- java - 处理命令时发生未知的服务器端错误。原始错误:未知错误:设备已在使用中
- javascript - 在 react native 中存储和访问本地存储中的压缩 json 文件
- python - 如何根据 Python Pandas 中其他行的值在 Pandas Data Frame 中添加新的索引行?
- python - CoinOR cbc 不接受期权 (pyomo)