admin管理员组文章数量:1403493
I'm trying to test print functionality of a button, like:
it('print document', function(){
element(by.id('print-button')).click();
expect(window.print());
});
I want to test browser print dialog box. How to do this?
I'm trying to test print functionality of a button, like:
it('print document', function(){
element(by.id('print-button')).click();
expect(window.print());
});
I want to test browser print dialog box. How to do this?
Share Improve this question edited May 14, 2015 at 8:08 alecxe 474k127 gold badges1.1k silver badges1.2k bronze badges asked May 14, 2015 at 8:02 Naveen KumarNaveen Kumar 3,0004 gold badges22 silver badges24 bronze badges 2- You can with the help of Sikuli JAVA API in selenium. Please check this my post and also my answer: stackoverflow./questions/23213535/… – nitin chawda Commented May 14, 2015 at 8:32
- @nitinchawda yup, but this is not java or python, so Sikuli is probably not the best option. Plus, the solution would be not quite reliable since it would depend on a specific browser, hence a specific image of a print dialog. – alecxe Commented May 14, 2015 at 8:32
1 Answer
Reset to default 8Browser's print dialog is out of scope of selenium, it is not under selenium's control. There is no way to solve your problem reliably with protractor
/selenium
only.
Besides, you don't need to test the browser and it's ability to open print dialogs. What you can do (not tested), is to test whether window.print
is called on print-button
click by redefining window.print()
(reference):
browser.setScriptTimeout(10);
var printButton = element(by.id('print-button'));
var result = browser.executeAsyncScript(function (elm, callback) {
function listener() {
callback(true);
}
window.print = listener;
elm.click();
}, printButton.getWebElement());
expect(result).toBe(true);
See also:
- Handling Print Dialog Using Protractor
- Selenium WebDriver : Verify Print Window dialog displayed on the page
- How to handle print dialog in Selenium?
本文标签: javascriptProtractor How to test windowprint()Stack Overflow
版权声明:本文标题:javascript - Protractor: How to test window.print() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744387380a2603809.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论