如果我的网站中有一个链接。例如。<a href="//google.com" target="_blank">go to Google</a>
我想做一个测试:
a
)我知道这行不通:
cy.get('a').click();
cy.url().should('include', 'google.com');
Run Code Online (Sandbox Code Playgroud)
由于a
有一个target
属性,您可以执行此操作。
cy.get('a')
.should('be.visible')
.then(($a) => {
expect($a).to.have.attr('target','_blank')
// update attr to open in same tab
$a.attr('target', '_self')
})
.click()
cy.url().should('include', 'google.com')
Run Code Online (Sandbox Code Playgroud)
根据您的应用程序和您想要测试的内容,使用cy.request()
和检查 200 状态代码可能足以满足外部 URL 的要求。
您可以使用removeAttr
删除目标,然后单击链接并断言。就像是:
cy.get('a').invoke('removeAttr', 'target').click()
cy.url().should('include', 'google.com')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13417 次 |
最近记录: |