且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

赛普拉斯获得href属性

更新时间:2022-06-13 00:03:48

下面的代码应该做你想做的事情实现。还有一整个食谱,提供有关如何测试在新标签页中打开的链接的建议

The code below should do what you're trying to achieve. There is also an entire recipe with suggestions on how to test links that open in new tabs.

it('Advertise link should refer to Contact page', () => {
   cy.get('div.footer-nav > ul > li:nth-child(2) > a')
     .should('have.attr', 'href').and('include', 'contact')
     .then((href) => {
       cy.visit(href)
     })
})

我还建议阅读赛普拉斯文件关于分配和使用变量的***方法: https://on.cypress.io/variables-和 - 别名

I would also suggest reading through the Cypress document on the best ways to assign and work with variables: https://on.cypress.io/variables-and-aliases