Selenium and Printing

One of my Se clients is a SAAS Point of Sale system and as such, printing receipts is embedded into their application. Unfortunately, Se knows how to handle things in the browsers but not things of the browser. Print dialogs and such fall into the latter category.

In this care we’re in the fortunate situation of using completely controlling the environment on the client site and can pull some tricks to make the problem of printing go away. For now, we’re only talking about Firefox on Windows (XP).

The first thing to do is install a Virtual Printer. There are a couple available, but I was pressed for time to find a solution and didn’t want to buy a commercial one so used VPrinter. I named it Virtual Printer which both describes it and is neutral enough that I could swap it out for another and not have to change any other aspects of the scripting environment — which is of course and important consideration.

Next I needed to tell Se, or more correctly the browser the Se scripts are running in about the printer. And a few other things around printing.

To this I started to use a custom Firefox profile for the scripts. This process is documented all over the place online (the magic search term is ‘firefoxProfileTemplate’) so I’ll skip it. But, what you want to do is take the profile a little bit further by creating a prefs.js in the profile which has the following:

user_pref("print.printer", "Virtual Printer");
user_pref("print.always_print_silent", true);
user_pref("print.show_print_progress", false);

These preferences for curiosity sake are part of the tweaks normally used to put Firefox into ‘kiosk mode’ and there are all sorts of interesting things to be discovered once you start exploring that.

Anyways, one thing I am not yet doing is checking the actual ‘printed’ values, so the VPrinter one might not be the best in that situation but since I am using Se-RC, any Virtual Printer that produces hackable output could be used in its place.

Comments 1

  1. Selenium boy 34 wrote:

    Hey adam! This is a very insightful look into the molecular structure of Se and how it interacts with Firefox, thank you for the interesting read.

    Posted 14 Mar 2017 at 6:38 pm

Post a Comment

Your email is never published nor shared. Required fields are marked *