![](/img/trans.png)
[英]How to reuse a function from an existing Cypress test, and call it in a new one?
[英]How can we test a new tab that is redirected from an existing tab in cypress?
需要测试从现有选项卡重定向的新选项卡。 我们如何在柏树中测试它?
你不能测试那个。 赛普拉斯不支持新窗口和/或选项卡。 作为解决方法,您可以做的是:
如果它被重定向到一个new url/tab
(即一个新的子域),并且在 cypress 中,如果它作为一个新选项卡打开,您仍然可以使用 cypress 进行测试。 我以邮递员网站为例来说明这一点。 在 postman 站点中,单击“ Learning Center
”选项卡将打开一个新选项卡。 下面的测试示例将在您现有的测试运行器选项卡中打开。 请参考下面我的代码:
context('New tab actions', () => {
it('Test to open a new tab in cypress and test the page', () => {
cy.visit('https://www.getpostman.com/');
cy.get('#mobile-menu-button').click();
cy.get('#mobileNav > #siteNav > nav > ul > li').contains("Product ");
cy.get('#mobileNav > #siteNav > .site-nav__secondary-menu > a').first().then(($a)=>{
const newUrl = Cypress.$($a).attr('href');
console.log(newUrl);
cy.visit(newUrl);
cy.get('.header__title').invoke('text').then((text)=>{
const headerText = text;
expect(headerText).to.contain('Learning Center');
//Similarly you can follow the same mechanism and start writing all of remaining tests related to that page....
})
})
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.