如何使用柏树关闭当前窗口/选项卡



每次测试后,我需要关闭选项卡/窗口,这样我就可以从头开始下一次

describe('theImplementationIamTesting', () => {
after(() => {
// CLOSE THE TAB AFTER THE TEST...
});
});

我正在寻找一种在测试后关闭当前选项卡的方法。我不是在说关闭子选项卡/窗口。我说的是初始标签。

在硒中,它将类似于webdriver.close()

我在网上找不到一个地方,包括柏树网站,上面写着如何关闭标签浏览器。

感谢您帮助

如果在不同的测试文件中分离案例,它将关闭整个浏览器,并每次重新打开。到目前为止,这是我找到的唯一方法,对我来说,从零开始每个案例非常有效,因为有时它会在第二个案例开始后继续运行第一个案例中未完成的API请求。

缺点是每次都需要对系统进行初步准备,这会增加运行时间。

我解决这一问题的方法是在每个测试的末尾添加一行,单击该行可以导航到其他测试可以继续的页面,比如"主页"。

describe('Test Inline Text Entry Interactions', () => {
beforeEach('Log in as CypressEditor', () => {
cy.MockLoginUser('cypressEditor');
cy.visit('http://localhost:4200/homepage');
})
it('should test 1st thing', () => {
//Test something, then...
cy.get('#logo-label').click(); //To navigate back to http://localhost:4200/homepage
});
it('should test the 2nd thing', () => {
//Test something else...
cy.get('#logo-label').click(); //To navigate back to http://localhost:4200/homepage
});
it('should test the 3rd thing', () => {
//Test some more stuff, then...
cy.get('#logo-label').click(); //this might not be necessary since it's the last one.
});

对我来说,这确保了每次测试都能完成并继续下一次。

最新更新