admin管理员组文章数量:1335386
I have a Cypress test which clicks on an image causing a redirect to a specific url. The test then checks the url contains a specific string.
However, clicking this image causes the tests to stop/fail with a "Whoops, there is no test to run." message when the redirect happens.
The Cypress test is very simple:
/* global describe, it, cy */
import loadStory from '../../../config/cypress/helpers/loadStory'
const ponent = 'product-card'
const productCardImage = '[data-test=ponent-product-card_imageContainer]'
describe(`${ponent} ponent interaction tests`, () => {
it('clicking the image should open the products page', () => {
loadStory(ponent, 'Default')
cy.get(productCardImage).should('be.visible')
cy.get(productCardImage).click()
cy.url().should('contain', '/product')
})
})
My tests run on http://localhost:9002
and it seems that redirecting to http://localhost:9002/product/productId
while the test suit is running is what causes Cypress to crash/fail and instead Cypress tries to go to https://localhost:9002/__/
I am wondering how I can click this image and redirect to the url without causing this crash/fail in Cypress.
I have a Cypress test which clicks on an image causing a redirect to a specific url. The test then checks the url contains a specific string.
However, clicking this image causes the tests to stop/fail with a "Whoops, there is no test to run." message when the redirect happens.
The Cypress test is very simple:
/* global describe, it, cy */
import loadStory from '../../../config/cypress/helpers/loadStory'
const ponent = 'product-card'
const productCardImage = '[data-test=ponent-product-card_imageContainer]'
describe(`${ponent} ponent interaction tests`, () => {
it('clicking the image should open the products page', () => {
loadStory(ponent, 'Default')
cy.get(productCardImage).should('be.visible')
cy.get(productCardImage).click()
cy.url().should('contain', '/product')
})
})
My tests run on http://localhost:9002
and it seems that redirecting to http://localhost:9002/product/productId
while the test suit is running is what causes Cypress to crash/fail and instead Cypress tries to go to https://localhost:9002/__/
I am wondering how I can click this image and redirect to the url without causing this crash/fail in Cypress.
Share Improve this question asked Aug 13, 2019 at 11:28 alexr89alexr89 4101 gold badge5 silver badges14 bronze badges 7- You can set follow redirect = false in visit or request – N.. Commented Aug 13, 2019 at 18:04
- Ive been playing around and now have the image inside an a tag with an href. This didn't explicitly fix the problem, however explicitly adding target _self to the a tag has fixed it. As of yet I have no idea why that is. – alexr89 Commented Aug 14, 2019 at 10:25
- Have you try to do similar this ? cy.location('pathname').should('eq', '/newthing/:id') – N.. Commented Aug 15, 2019 at 14:54
- Yes I have - because cypress redirected the entire browser it seemed, looking for the location always failed. For some reason target _self is the only way to get around this. – alexr89 Commented Aug 16, 2019 at 12:00
- In this case, you should start your test with authentication calls and open localhost:9002/product/productId. If you don't know ids, in this case, make API calls and add products and open with that Ids – N.. Commented Aug 16, 2019 at 15:17
2 Answers
Reset to default 1Cross domain is not supported in Cypress.
Example: step 1: You navigate to google step 2: Search for Gmail step 3: clicked on gmail link
You are switching from Google. to gmail. - cypress doesn't support this.
Workaround 1: You can remove set href attribute value to blank as below:
target="_blank" so that it will open in same page.
Workaround 2:
put step 1 and step 2 in one test iteration
and put step 3 in another iteration
Their is an issue of http
to https
.
本文标签: javascriptHandling Cypress url redirectStack Overflow
版权声明:本文标题:javascript - Handling Cypress url redirect - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742389302a2465669.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论