Cypress has official announced that they will not support multiple windows or multiple tabs, they have gone saying this is an flaky practice and they don;t have any plans in the future to support them.
Despite this takeoff we can use perform test on site which has these Child windows practices. In this post we will demonstrate how we have open a new URL in the web page during the test run.
CODE
/// <reference types = "Cypress" />
describe('Child Window',function(){
context('Test Cases',function(){
it('Test 01',function(){
cy.visit('http://the-internet.herokuapp.com/windows')
cy.get('.example > a').invoke('removeAttr','target').click()
})
})
})
EXPLANATION
We will visit this Demo Site http://the-internet.herokuapp.com/windows and then click on the button to open a new window.
When the URL is loaded you will find a clickable link named New Link will be available below the header. If we click that clickable link then it will open a new tab but our control will be still on the old webpage and at this point the test won't be feasible.
Instead of opening new webpage in the new window/tab, we can force the site on opening new window in a same page by removing the property of the <a> tag's Target attribute using jQuery.
Finally we perform the click action on the web element were the target attribute was removed. This will open the new window in the current window.
This work around may or may not be applicable to your application and this is what we can do it as of now, we will explore if they provide a different way for this requirement on upcoming releases.
Download the spec file below,
https://drive.google.com/open?id=1RTfwlYzuWjHhXsxy1SFrRrT2Pzcrp1bj