Run Web Driver scripts from Command Prompt

The Web Driver scripts can be run easily in Eclipse after being created.

But to get the maximum benefit of having them, they should also be run from Command Prompt, maybe after each site build is generated.

How can this be done?

Let's assume that we have a JAVA project created in Eclipse with 2 test classes, each class having 2 test scripts.

The first thing to do is to open Command Prompt and make the project folder the current folder:

cd C:\Projects\workspace\ProjectWithJUNIT

ProjectWithJUNIT has the following sub-folders:

Src - the .java files can be found here
Bin - the .class files will be generated here

Then, set up the CLASSPATH variable so that it includes the following:

- path of the junit.jar file

- path of the org.hamcrest.core_1.3.0.v201303031735.jar file

- path of the selenium-java-2.44.0.jar file

- path of the selenium-server-standalone-2.44.0.jar file

- path of the project class files

The following command does the work:

set CLASSPATH=C:\Projects\workspace\ProjectWithJUNIT\bin;C:\Eclipse\plugins\org.junit_4.11.0.v201303080030\junit.jar;C:\Eclipse\plugins\org.hamcrest.core_1.3.0.v201303031735.jar;C:\Selenium\JAR\selenium-java-2.44.0.jar;C:\Selenium\JAR\selenium-server-standalone-2.44.0.jar

Next, the class files need to be generated by compiling the .java files:

javac src\ -d bin
javac src\ -d bin

The -d option is needed so that the .class files are placed in the Bin sub-folder of the project folder.

Finally, this command executes the .class files using the junit runner:

java org.junit.runner.JUnitCore Class1 Class2

Since all test methods are using the HTML UNIT DRIVER instead of the Chrome driver, no browser is launched for the execution of the test scripts.

This is the end result:

Share this