相关疑难解决方法(0)

处理 Cypress url 重定向

我有一个 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/__/

我想知道如何单击此图像并重定向到该网址,而不会导致赛普拉斯崩溃/失败。

javascript testing end-to-end reactjs cypress

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

cypress ×1

end-to-end ×1

javascript ×1

reactjs ×1

testing ×1