需要测试从现有选项卡重定向的新选项卡。我们如何在赛普拉斯中进行测试?
答案 0 :(得分:0)
如果将其重定向到new url/tab
(即新的子域),并且在cypress中以新标签页的形式打开,您仍然可以使用cypress进行测试。
我以邮递员网站为例来说明这一点。在邮递员站点中,单击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....
})
})
})
})
答案 1 :(得分:-1)
您无法测试。赛普拉斯不支持新窗口和/或选项卡。您可以采取的解决方法是:
答案 2 :(得分:-2)