Running Selenium tests from the command line on Windows 7 can be slightly challenging simply due to the permissions system. By default Windows 7 tends to be locked down and there is conflicting information out there on exactly what steps to take to get Selenium tests running. The intention is that this article will provide some help for people trying to run Selenium Test Suites from the command line on Windows 7 (and other Windows versions).
1) Create a Selenium HTML test
Create a simple Selenium test (or ten) to add to your test suite. Creating a Selenium test is easy in LiquidTest. See our LiquidTest documentation on “how to record Selenium HTML tests“.
2) Create a Selenium Test Suite
Because HTML is essentially a content formatting language it contains little scope to tell any executing program exactly what to do outside of basic presentation. With this in mind and given that Selenium supports the HTML test format, the Selenium team came up with Selenium Test Suites to tell the Selenium runner (Selenium RC/Server) what tests to execute and the order of execution. Selenium Test Suites are fairly straight forward. In their simplest form they contain an HTML Table (TABLE), with a Row (TR) and some Table Data (TD).
<title>My Application Test Suite</title>
<tr><td><b>Suite Of Tests</b></td></tr>
<tr><td><a href="./Test1.html">Test Example</a></td></tr>
Notice that the tests can be grouped with the first Table Row, and then the preceding rows link to the actual test cases. This formatting helps with both execution ordering of test cases and to attach meaningful data to the results file output by the Selenium RC/Server.
3) Executing Selenium Test Suites from the Command Line
Security and Internet Explorer: Due to Windows 7 security, running tests as anything but Administrator produces sketchy results at best. I had numerous problems with Internet Explorer. Firstly Internet Explorer was loading Selenium RC/Server with many script errors regardless of configuration. The tests never replayed in this state. Firefox fared better in that it ran and produced the necessary results file. To avoid security issues with Selenium RC/Server ensure that any tests you are executing from the Command Line are through an Administrator Command Prompt (right-click on the Command Prompt and select “Run as Administrator”.
Creating a Windows Batch file to run your Selenium Test Suite
To make life a little easier we will create a simple batch file to save writing the command out by hand for each Selenium Test Suite execution. The batch file consists of Java’s JAR command (ensure Java is in your System PATH or use the full file location to your Java bin directory). We specify to Selenium RC/Server that we wish to run a Test Suite, targeting Internet Explorer with a default URL of google.com (for our test) and then we specify where our Selenium Test Suite is located, where we want our Results file written and finally the Port for executing the communication.
java -jar selenium-server-standalone-2.0b3.jar -htmlSuite "*iexplore" "http://www.google.com" "D:\selenium-2\TestSuite.html" "D:\selenium-2\results.html" -port 4445
When running a Selenium Test Suite, the browser you’re targeting will open and the test will replay.
4) Selenium test execution Results File
Selenium will start up and execute the Test Suite and write a Results file to the location you specified. The Results file looks like the following:
Hopefully this example will be enough to get you started with running your Selenium HTML tests from the command line. For information on how to run your Selenium JUnit tests against the Selenium Server from within the Eclipse IDE please view the tutorial here..