ale*_*r89 5 javascript testing end-to-end reactjs cypress
我有一个 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')
})
})
Run Code Online (Sandbox Code Playgroud)
我的测试正在运行http://localhost:9002
,似乎http://localhost:9002/product/productId
在测试套件运行时重定向到导致 Cypress 崩溃/失败,而 Cypress 尝试去https://localhost:9002/__/
我想知道如何单击此图像并重定向到该网址,而不会导致赛普拉斯崩溃/失败。
Cypress 不支持跨域。
示例:第 1 步:导航到 google 第 2 步:搜索 Gmail 第 3 步:点击 Gmail 链接
您正在从 Google.com 切换到 gmail.com - cypress 不支持此操作。
解决方法 1:您可以将设置的 href 属性值删除为空白,如下所示:
target="_blank" 以便它将在同一页面中打开。
解决方法2:
将步骤 1 和步骤 2 放入一次测试迭代中
并将步骤 3 放入另一次迭代中