倚天杖
2021-12-02 19:19:10
print window單擊柏樹中的打印按鈕時(shí),如何關(guān)閉打開的窗口。我正在調(diào)用一個js函數(shù)來關(guān)閉窗口并且它沒有執(zhí)行關(guān)閉,有人可以就如何解決問題提出建議嗎?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(); })})//關(guān)閉打開窗口的Javascript函數(shù):function printClose(){ window.close(); }
1 回答

慕勒3428872
TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超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 });
});
});
添加回答
舉報(bào)
0/150
提交
取消