Advance Selenium

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.

author-avatar

About Mukesh Otwani

I am Mukesh Otwani working professional in a beautiful city Bangalore India. I completed by BE from RGPV university Bhopal. I have passion towards automation testing since couple of years I started with Selenium then I got chance to work with other tools like Maven, Ant, Git, GitHub, Jenkins, Sikuli, Selenium Builder etc.

12 thoughts on “How to Run selenium test from command line in Selenium Webdriver

  1. Praful says:

    Could you please tell me how to run junit selenium TestRunner from command line?

    1. Hi Praful,

      First do compilation step ->> javac -cp ;. TestClass1.java TestClass2.java
      Then run step –>> java -cp ;;. org.junit.runner.JUnitCore TestClass1 TestClass2

  2. Dileep kumar says:

    you can start giving linux commands also where now-a-days more people are using the linux

    1. Hi Dileep,

      Yes, you are right. I am preparing to come up with some linux stuffs…:)

  3. Neha Agarwal says:

    How to run selenium scripts in linux from command prompt

    1. Hi Neha,

      No idea on linux I will try and get back to you soon on this.

  4. palani says:

    how to run selenium scripts in command prompts

    1. Post is describing the same. What are the issues you are facing?

  5. Anoop Jain says:

    HI Mukesh,
    I’ve tried the same as you said and I’m getting below error
    Cannot find class in class classpath: Stanleytools.signup

    Could you please help me here

    Thanks
    Anoop Jain

    1. Hey Anoop,

      Compile the program again and then run the same program.

  6. Alaka says:

    What all jar files are required to run a selenium script from command prompt????

    I kept selenium standard standalone server jar , selenium java 2.53.1 and testng-6.0.1jar but it is giving me error could not load main class..

    But the same script is getting successfully run in eclipse and even the XML is getting successfully run from eclipse when I do run as testNG from eclipse

    Please could specify all jar file names required to run the script from command prompt???

    Or let me know why I am getting this error ???

    1. Hi Alaka,

      I would suggest you to use Maven and then run maven clean install test

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.