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

Swicth tab/windows workaround not working #6

Open
iburahim786 opened this issue Feb 9, 2023 · 0 comments
Open

Swicth tab/windows workaround not working #6

iburahim786 opened this issue Feb 9, 2023 · 0 comments

Comments

@iburahim786
Copy link

@jakedowns @mtrojanowski
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

1 participant