Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Cypress – Handling Child tabs

Category: Cypress
//This is applicable when new window opens in new tab and the element has target attribute
For Example:
Open New Window

Option 1 - Remove target attribute and the new window will open in the same browser window. It doesn't open the new tab.
cy.get('link').invoke('removeAttr', 'target').click();
//Verify the child window url
cy.url().should('include', 'child window url');
cy.wait(5000);
cy.go('back'); //back to parent tab

Option 2 - Get href value and use it
cy.visit('parenturl');
cy.get('link').then((e) => {
   let childurl = e.prop('href');
   cy.visit(childurl)
}

cy.url().should('include','childurl');
cy.wait(5000);
cy.go('back);

Note: Option -2 should have same domain

Leave a Reply

Your email address will not be published. Required fields are marked *