1

Below is a submit button on the page I am trying to test.

When you click this button, a pop-up window is displayed. The URL of this pop-up is https://login.microsoftonline.com/........etc.

enter image description here

This sign in uses SSO, but we are having difficulty bypassing the sign-in process using requests.

So we are instead trying to capture the URL of the pop-up during the test.

I have seen examples where people retrieve the href attribute of a button. However, as you can see above, there is no href on this button.

I've searched the HTML for a form element too, but can't find that.

I'm just wondering, is there a way I can get the URL of the pop-up window that clicking the above button generates?

1
  • We have tried to bypass the SSO using cy.request(), but the problem is that our authentication uses Azure Active Directory, then goes to Okta, & then goes back to AAD, so it's quite complex Commented Jul 1, 2022 at 18:19

2 Answers 2

0

To catch the URL, try adding an intercept before the click

cy.intercept('POST', '*').as('submit')

cy.get('button').click()

cy.wait('@submit').then(interception => {
  console.log(interception.request.url)
})

Note this is debugging code only to help find the URL. Don't use it in a long-term test.

Additional notes:

  • I'm assuming 'POST' as it's most common for submit, but may need 'GET' instead.

  • using '*' will catch anything, so you may catch so stray requests from the page load with the first cy.wait('@submit'). If so, just add more cy.wait('@submit') or a long cy.wait() before the click.

Sign up to request clarification or add additional context in comments.

Comments

0

The new tab is likely to be trigger via javascript. If it is using [window.open][1] the you can stub it to open in the same ta

cy.window().then(win => {
    cy.stub(win, 'open').callsFake((url, target) => {
      expect(target).to.be.undefined
      // call the original `win.open` method
      // but pass the `_self` argument
      return win.open.wrappedMethod.call(win, url, '_self')
    }).as('open')
  })
  cy.get('a').click()
  cy.get('@open').should('have.been.calledOnceWithExactly', 'url')
})


  [1]: https://glebbahmutov.com/blog/cypress-tips-and-tricks/#deal-with-windowopen

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.