print window单击柏树中的打印按钮时,如何关闭打开的窗口。我正在调用一个js函数来关闭窗口并且它没有执行关闭,有人可以就如何解决问题提出建议吗?context('Print button tests', () => { it.only('Verify the display of Print and close the window', () => { cy.get('.timetable-filter-panel-button.btn.btn-primary > span') .contains("Print current view") .click(); printClose(); })})//关闭打开窗口的Javascript函数:function printClose(){ window.close(); }
1 回答
慕勒3428872
TA贡献1848条经验 获得超6个赞
您可以像这样使用 Cypress 测试打印弹出窗口:
it('Print button renders & opens modal', () => {
// Clicks & asserts the button that triggers the popup window to print
cy.get('[data-test="button-print"]')
.should('exist')
.and('be.visible')
.click();
// Assert printing was called once
cy.visit('/inner.html', {
onBeforeLoad: win => {
cy.stub(win, 'print');
},
});
cy.window().then(win => {
win.print();
expect(win.print).to.be.calledOnce;
// this line closes the print popup
cy.document().type({ esc });
});
});
添加回答
举报
0/150
提交
取消