Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 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 Reply

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')
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...