Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda