我有一个 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 而不会在 Cypress 中导致此崩溃/失败。