Thursday, January 16, 2014

Running Selenium Script from command prompt using .class instead of .java file - TestNG

Sometimes we need to run our automation script at client machine to demonstrate our ability to automate but we don't want to share our code without JDK (required - JRE). We can achieve this by following below steps. With this we can run the script from .class instead of .java file.

We can achieve this using both JUnit and TestNG. In this example we are working with TestNG.

Here my example is GoogleSearch.java

Step 1: Prepare required script using any IDE (eclipse) and compile
Step 2: Open command prompt in another system and check whether JRE is available
Step 3: Prepare testng.xml file as follows

< !DOCTYPE suite SYSTEM "
http://testng.org/testng-1.0.dtd">
<suite name="Google">
<test name="GoogleSearch">
<classes>
<class name="GoogleSearch"/>
</classes>
</test>
</suite>

Step 3: Copy selenium standalone server, TestNG.jar, .class and testng.xml files to a folder(D:\Google\)


Step 4: Open command prompt and change to D:\Google\

Step 5: Set path using the following command
set classpath=%classpath%;D:\Google\selenium-server-standalone-2.39.0.jar;D:\Google\testng-6.8.jar;.;

*Note: update the paths of the .jar files and .class file according to your path.

Step 6: Run the class file using the following command

java org.testng.TestNG java org.testng.TestNG testng.xml

Now, you can see the bowser will open and perform the required operation without code and eclipse.

No comments:

Post a Comment