Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
How to verify url without navigating to page in cypress

I want to check the url without visiting the actual page, basically application is on angularJS and navigates using ng-click method ($state.go). I have seen too many documentations of cypress stub and intercept but haven't found any thing regarding this type of problem statement.

I have tried below

cy.window().then((win) => {
  cy.stub(win, 'open').as('redirect');
});
cy.get('@redirect').should(
  'be.calledWith',
  'myUrl'
);

but this is use for new tab, i need it for same tab, can anyone help regarding this issue.

Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to prevent the navigation, it does depend on how the app does it.

One example for stubbing window.location.replace is shown here

Deal with window.location.replace

Can also be used with window.location.href.

it('replaces', () => {
  cy.on('window:before:load', (win) => {
    win.__location = {
      replace: cy.stub().as('replace')
    }
  })

  cy.intercept('GET', 'index.html', (req) => {
    req.continue(res => {
      res.body = res.body.replaceAll(
        'window.location.replace', 'window.__location.replace')
    })
  }).as('index')

  cy.visit('index.html')
  cy.wait('@index')
  cy.contains('h1', 'First page')
  cy.get('@replace').should('have.been.calledOnceWith', 'https://www.cypress.io')
})

This is more complicated than a simple stub, because window.location can't be stubbed (a security measure in the browser).

Gleb Bahmutov shows how to intercept the page load to get around the problem.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!