Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda