Using Selenium and Facebook WebDriver with Codeception, I had the same problem – the test scenario would stop running because the print dialog prevented any interaction with the page.
I ended up not opening the print dialog in the test
environment (example using Symfony and Twig):
{# Selenium can't interact with the OS native print dialog. #}
{# Therefore, it's disabled in the test environment. #}
{% if app.environment != 'test' %}
$(document).ready(function () {
var orderShouldBePrinted = window.location.href.indexOf(
'print=true'
) !== -1;
if (orderShouldBePrinted) {
window.print();
}
});
{% endif %}
This has the advantage of not stopping the test. However, it doesn't allow testing that the print dialog actually appears.
As a smoke test, I added $I->seeInCurrentUrl('print=true');
(because this URL parameter triggers window.print()
).