skip to Main Content

I am Automating Payment Page in cypress.In that while Automating through cypress and clicking on the Make payment button it Open the full window means on the entire screen,so i cant automate that Page.I want to Open that screen in Test runner window so i can automate that Page.How to do it?

Here is my code

    cy.get(this.proceedToPay).click({force:true})

    cy.get(this.selectYourBank).select('Test Bank')

    cy.get(this.makepayment2).click()This is the Make payment Button

    cy.get(this.selectStatus).select('Success')

    cy.get(this.FinalSubmit1).click()

2

Answers


  1. If the payment page opens in a new window or a new tab when you click on the "Make payment" button, you can use Cypress commands to switch to that window and continue your automation.
    Here’s an example of how you can achieve that:

    After clicking the "Make payment" button, we can use the cy.window() command to access the current window’s properties. We then check for the newly opened window and switch to it using win.openedWindows[0].
    Once the focus is on the new window, you can continue your automation by referencing the @newWindowBody alias and using the within() command.

    cy.get(this.proceedToPay).click({ force: true });
    cy.get(this.selectYourBank).select('Test Bank');
    cy.get(this.makepayment2).click();
    
    // Switch to the newly opened window
    cy.window().then((win) => {
      const newWindow = win.openedWindows[0]; // Assuming only one window opened
      cy.wrap(newWindow).should('have.property', 'closed', false);
      cy.wrap(newWindow).then((newWin) => {
        cy.wrap(newWin.document).should('have.property', 'visibilityState', 'visible');
        cy.wrap(newWin.document.body).as('newWindowBody');
        cy.wrap(newWin).focus();
      });
    });
    
    // Continue with your automation on the new window
    cy.get('@newWindowBody').within(() => {
      cy.get(this.selectStatus).select('Success');
      cy.get(this.FinalSubmit1).click();
    });
    
    Login or Signup to reply.
  2. You need to share share DOM screenshot of that element you make click and new window opens. If it is anchor tag and has target = ‘_blank’ attribute then you need to remove this attribute in order to open it in same tab and cypress commands will work on that. try this

    cy.get(this.FinalSubmit1).invoke('removeAttr','target').click();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search