How to Run selenium test from command line in Selenium Webdriver

Hello Welcome to Selenium Tutorials, today we will discuss how to Execute Selenium test from command line.

Before executing testcases from command line you should have setup ready, if you still have not done then please follow the below link and complete setup part-

Selenium Webdriver Setup

Once you start designing test case continuously  your test cases count will increase so you have to manage your test cases accordingly.

TestNG having very interesting concept of creating  xml file based on your requirement and put all relevant test cases inside testng.xml file and run it as a Test Suite.

Scenario – If you have 50 test case for application 1 and 70 test case for application 2 and 100 test case for application3 so in this case we can create 3 xml (1 xml for each app) and run them either individually or run all xml in one shot.
Precondition-

1- TestNG should be installed.
2- Multiple xml file should be created.
3- Class-path should be set.

Run selenium test from command line

 

Step 1- Create multiple testng.xml files and store all xml into project home directory as given below.
Execute Selenium test from command line

Step 2- Set classpath now

Some key points to remember-

1-Put all the jars (Selenium jars) into separate folder and  put that folder into project home directory

in my case- I created lib folder (you can keep name based on your choice) and I kept all jars inside it which we downloaded from Selenium website.

Refer below screenshot of Lib folder and I have shown only some jars but you have to kept all files.

Execute Selenium test from command line

Execute Selenium test from command line

 

2- Open command prompt and type cd\ and press enter.

Execute Selenium test from command line

Execute Selenium test from command line

Now go to project home directory for this type cd directory path and enter

Execute Selenium test from command line

Execute Selenium test from command line

Now we can set classpath for this,specify bin folder

Home Directory > set classpath=Home Directory\bin; and press enter

Execute Selenium test from command line
Specify lib folder where all jars is available

Home Directory > set classpath=Home Directory\lib\*; and press enter

Execute Selenium test from command line

Execute Selenium test from command line

Step 3-Now run xml file using below command

Home-directory > java org,testng.TestNG testng.xml testng2.xml testng2.xml and hit enter

Execute Selenium test from command line

Execute Selenium test from command line

 

Thanks for visiting my blog. If you find this post informative then please share with your friends.:)

 

For more updates like our Facebook Page.

For any Selenium related query Join Facebook Group.

8 Comments

  1. Neha Agarwal
  2. palani
  3. Anoop Jain
  4. Alaka

Leave a Reply