我有一个测试用例,其中有一个在新选项卡中打开的链接.由于赛普拉斯不支持多个选项卡,我想获取该链接的 href 属性,然后在同一个选项卡中打开它.我正在尝试这样做,但由于某种原因它不起作用.
I have a test case in which I have a link which opens in a new tab. Since Cypress doesn't support multiple tabs, I want to get the href attribute of that link and then open it in the same tab. I'm trying to do it this way, but for some reason it doesn't work.
it('Advertise link should refer to Contact page', () => {
var link = document.querySelector("div.footer-nav > ul > li:nth-child(2) > a").href;
cy.visit(link);
cy.title().should('include', 'Text');
});
下面的代码应该可以实现您想要实现的目标.还有一个完整的 提供有关如何测试在新标签页中打开的链接的建议.
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)
})
})
我还建议通读 Cypress 文档,了解分配和使用变量的最佳方法:https://on.cypress.io/variables-and-aliases
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
这篇关于赛普拉斯获取 href 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 Angular 2/Typescript 中使用 IScrollUse IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
Anime.js 在 Ionic 3 项目中不起作用anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 项目中不起作用)
Ionic 3 - 使用异步数据更新 ObservableIonic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用异步数据更新 Observable)
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?)
将 ViewChild 用于动态元素 - Angular 2 &离子2Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(将 ViewChild 用于动态元素 - Angular 2 amp;离子2)