Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

Cypress: Is it possible to extract a URL of a new browser tab that will be opened by a click?

I need to extract a URL of a new browser tab that will be opened by a double click on an element. Element is not a link so there is no any "href" attr. Once we dblclick on this item, we will have a proper url that I need to extract (and parse further).

    cy.visit("Runtime/Runtime/Form/Home/");
    cy.contains("item").should('be.visible').dblclick(); 
    const url = // to do
   

I know that cypress does not support multiple tabs testing but I don't need to do any testing on a tab...just what to get that url. Is it possible?

question from:https://stackoverflow.com/questions/65907993/cypress-is-it-possible-to-extract-a-url-of-a-new-browser-tab-that-will-be-opene

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

One way to test that is use Chrome and disable Web security in cypres.json:

"chromeWebSecurity": false

Then you could do:

cy.contains("item").should('be.visible').dblclick()
cy.url()
.then((url) => {
  expect(url).to.contain('some-string')
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...