[英]Handling Cypress url redirect
我有一個 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
是導致 Cypress 崩潰/失敗的原因,而 Cypress 嘗試轉到https://localhost:9002/__/
我想知道如何單擊此圖像並重定向到 url 而不會在 Cypress 中導致此崩潰/失敗。
賽普拉斯不支持跨域。
示例:第 1 步:您導航到 google 第 2 步:搜索 Gmail 第 3 步:點擊 gmail 鏈接
您正在從 Google.com 切換到 gmail.com - cypress 不支持此功能。
解決方法 1:您可以將 set href 屬性值刪除為空白,如下所示:
target="_blank" 以便在同一頁面中打開。
解決方法 2:
將第 1 步和第 2 步放在一個測試迭代中
並將步驟 3 放在另一個迭代中
他們是http
到https
的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.