Question

How to test with (JavaScript and/or) FirefoxDriver whether the window.print() method is overridden?

It is possible to disable all print buttons on a page like with this:

window.print = function() { alert("Bazinga") }

With this a normal "Print" link like the following one is not working anymore:

<a onclick="window.print()">....</a>

I need to check whether a window.print() call executes the original print dialog.

Maybe it is possible to inject some JavaScript into the FirefoxWebdriver?

Was it helpful?

Solution

I've created a fiddle based on Luca's answer and Christoph's comment. This function will detect native print dialog even in IE6.

function isNativePrint() {
    var isNative = false;
    try {
        if (window.print.toString().indexOf('[native code]') > -1) isNative = true;
    } catch (e) {
        isNative = true;
    }
    return isNative;
}

OTHER TIPS

Since window.print is a native function you can:

if( window.print.toString().indexOf('[native code]') > -1 ) {
 //native
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top