Cypress-暂停下一页导航

Cypress-暂停下一页导航,cypress,Cypress,假设我知道下一页导航的URL,有没有办法阻止下一个操作执行导航,而不管导航是由href还是js引导的?已尝试cy.intercept无效 // doesn't work cy.intercept({ hostname: 'cross.domain' }, (req) => {}) cy.contains('Next').click() 您可以使用: 您是否介意分享更多关于您的特定用例的信息,以及您在测试中最终要实现的目标?@Kerry,如代码所示,我试图单击某个元素,但希望阻止页面导航

假设我知道下一页导航的URL,有没有办法阻止下一个操作执行导航,而不管导航是由href还是js引导的?已尝试
cy.intercept
无效

// doesn't work
cy.intercept({ hostname: 'cross.domain' }, (req) => {})
cy.contains('Next').click()

您可以使用:


您是否介意分享更多关于您的特定用例的信息,以及您在测试中最终要实现的目标?@Kerry,如代码所示,我试图单击某个元素,但希望阻止页面导航到cypress禁止的另一个域。请参阅@NoDistriction的问题,用于javascript重定向。您不需要
Cypress.$(aTagElement).attr()
,因为
aTagElement
已经是jquery对象。按照惯例,您会在它前面加上
$
,即
。然后($aTagElement=>{
以避免混淆。您能解释一下为什么用
/
替换href值吗?
/
打开的页面与您所在的页面相同。您可以将其替换为您希望出现的任何url。很酷,谢谢!@RosenMihaylov,我想说非基于href的导航更受欢迎,例如使用location.href、window.open(),window.replace()。

    cy.get(`aTagSelector`) //This part is recommended to check if you click the required button with the link to cross origin
        .should('have.attr', 'href')
        .and('include', `expectedUrl`)
    cy.get(`aTagSelector`)
        .then($aTagElement => {
            $aTagElement.attr("href", '/');
            cy.get($aTagElement)
                .click({force: true})
        })