Batch Script to Start Selenium RC Server on Windows
Notes on some work I've been doing...at work. Posted for their potential use to posterity.
Friday, 2009-10-30 | Programming, Testing
| "toconnell@lana:~/demongin/blog$ fortune |
Basically, as part of a work project, I'm working on doing automated testing of a certain internal-use web-based application.
Now, I'm no developer--I am but a humble QA engineer--so I am not responsible for unit tests or anything like that. I am also not responsible for so-called "sapient testing" (i.e. "exploratory testing", "bug hunting" or, as I like to call it, "dicking around"). What I am responsible for is setting up checks to make sure that important parts of this application don't die after re-deployments and restarts.
Ultimately, what this means, is that I've got to run browser tests. A bunch of them. And so, since anything that I have to do more than once has to be scripted, I've devised a small piece of software that walks a directory for test scripts (generated by Selenium IDE) and then fires them all off and records their results to a.) a log file and b.) a dynamically generated HTML form that allows for quick review of the results.
But that piece of the project isn't what I'm going to describe right now. What I'm going to describe right now is the batch script that starts up the Selenium server on the Windows PC from which my automatic browser-based tests are executed.
Without further ado:
SET selenium="C:\Documents and Settings\tim.oconnell\My Documents\SharedDocuments\selenium-remote-control-1.0.1\selenium-server-1.0.1\selenium-server.jar" SET profile="C:\Documents and Settings\tim.oconnell\Application Data\Mozilla\Firefox\Profiles\pmqpikeu.selenium" java -jar %selenium% -singlewindow -port 555 -firefoxProfileTemplate %profile% cmd \K
Part of that is my fault: I know very little about Windows, batch scripts and using cmd windows for anything other than cocktail party punch-lines. A bigger part of that, however, is the fault of the inherent limitations of batch scripting: Microsoft's built-in scripting language is a.) not like posix at all, b.) inflexible and user-hostile as all get-out and c.) lacks the basic functionality you could probably find in the oldest stable release of ksh. Another important part of why the above code took so long to write has to do with the fact that almost everything up there is a work-around of some type (and therefore required troubleshooting, researching, trial-and-error, etc.).
That having been said, here's the line-by-line breakdown. I offer this in the hopes that it'll save some other Linux guy some of the headaches that working around Windows has caused me:
SET selenium="C:\Documents and Settings\tim.oconnell\My Documents\SharedDocuments\selenium-remote-control-1.0.1\selenium-server-1.0.1\selenium-server.jar"
Basically, I'm Dorothy, this script is Toto and, seeing as how we're not in Kansas (i.e. posix) anymore, Toto isn't a dog: he's literally every fucking character that follows the equal sign (that isn't escaped with a carat).
SET profile="C:\Documents and Settings\tim.oconnell\Application Data\Mozilla\Firefox\Profiles\pmqpikeu.selenium"
This is something that a lot of professional testers do, as it enables them to create a unique about:config and tweak other settings within a Firefox profile that make for a smoother automated browser testing experience.
What's remarkable here (other than the fact that the double quotes are included as part of the variable) is that the trailing slash is missing after "pmqpikeu.selenium". This is key. If you feed a selenium server that's supposed to run on a Windows machine a path with a trailing slash, the server will not start.
java -jar %selenium% -singlewindow -port 555 -firefoxProfileTemplate %profile%
cmd \K
I may write more about my big selenium project at some later time/date, but for now, it's important for me to get that batch ugliness a.) off my chest, b.) out into the world and c.) into the dog-house where all batch scripts belong.
Thanks for listening.
