处理赛普拉斯URL重定向

时间:2019-08-13 11:28:19

标签: javascript reactjs testing cypress end-to-end

我有一个赛普拉斯测试,该测试单击图像导致重定向到特定的url。然后测试会检查网址中是否包含特定的字符串。

但是,单击此图像会导致测试停止/失败,并显示“糟糕,没有要运行的测试”。重定向发生时显示消息。

赛普拉斯的测试非常简单:

/* 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是导致Cypress崩溃/失败的原因,而Cypress尝试去https://localhost:9002/__/ < / p>

我想知道如何单击此图像并重定向到url,而又不会导致Cypress崩溃/失败。

2 个答案:

答案 0 :(得分:0)

赛普拉斯不支持跨域。

示例: 步骤1:您导航到Google 第2步:搜索Gmail 第3步:点击了Gmail链接

您正在从Google.com切换到gmail.com-赛普拉斯不支持此操作。

解决方法1: 您可以将set href属性值删除为空白,如下所示:

target =“ _ blank” 这样它就会在同一页面中打开。

解决方法2:

将第1步和第2步放入一个测试迭代中

然后将步骤3进行另一次迭代

答案 1 :(得分:0)

这是httphttps的问题。

See Attached