Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to tabs and windows are not working for me #4

Open
balajikrishnannewsuk opened this issue Apr 20, 2022 · 4 comments
Open

Switch to tabs and windows are not working for me #4

balajikrishnannewsuk opened this issue Apr 20, 2022 · 4 comments

Comments

@balajikrishnannewsuk
Copy link

Hi Jake,

In my application none of the command works, I need your help to fix. Please let me know your availability to connect over hangout.

Regards,
Balaji K

@balajikrishnannewsuk
Copy link
Author

Hi Jake,

Could you please help me to fix (Switch to tabs and windows), I am using same domain but still not working.

@rubelux
Copy link

rubelux commented Sep 22, 2022

Same with me

@jakedowns
Copy link
Owner

@balajikrishnannewsuk @rubelux

hey there, sorry i completely missed the notification for this issue

i've added an updated example that may help provide more context on how to use my helper

https://github.com/jakedowns/CypressHelpers/blob/master/window-open-example.js

please let me know if you have any more issues/questions

@iburahim786
Copy link

iburahim786 commented Feb 8, 2023

@jakedowns
Still not working pls find my demo code,
/ this example relies on https://github.com/jakedowns/CypressHelpers/blob/master/commands_tab_helpers.js being added to your support/commands file
describe('Example to demonstrate the handling of new browser windows in cypress', () => {

it('Handling new Browser Tab', function () {
    cy.visit('https://testproject.io/',{

        // NOTE: we define a "tab_name" for the "Root Tab" so we can switch back to it
        tab_name: 'myRootWindow',

        onBeforeLoad(win) {
            // stub window.open with a custom version
            cy.stub(win, 'open', (url, target, features)=>{
                // our custom window.open that allows cypress to switch between the windows ("called tabs in the helpers")
                cy.openTab(url, {
                    tab_name: 'MySecondWindow', // make this something you can call later to switch Cypress contexts between the parent window and the new window

                    window_features: features,
                })
            }).as('windowOpen');
        }
    })

    cy.get('@windowOpen').get('a[href*="https://blog.testproject.io/"]').first().click();

    cy.get('@windowOpen').should('have.been.calledOnce')

    const EXPECTED_WINDOW_OPEN_URL = 'https://blog.testproject.io/';
    // cy.wrap(window.callMyJSThatCallsWindowOpen()).then(()=>{
        cy.get('@windowOpen').should('be.calledWith', EXPECTED_WINDOW_OPEN_URL)

        // switch to the new window
        cy.switchToTab('MySecondWindow')

        // TEST STUFF INSIDE THE SECOND WINDOW

        // Close the Tab
        cy.closeTab('MySecondWindow')

        // Switch back to the root window
        // NOTE: you can switch back and forth without closing the tab too
        cy.switchToTab('MyRootWindow')

    // })
})

})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants