• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Advance Selenium / How to Run selenium test from command line in Selenium Webdriver

How to Run selenium test from command line in Selenium Webdriver

April 2, 2015 by Mukesh Otwani 12 Comments

Execute Selenium test from command line

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

http://www.pharmacynewbritain.com/tramadol/

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

 

http://www.wolfesimonmedicalassociates.com/silagra/

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.

Filed Under: Advance Selenium Tagged With: Selenium testcase via cmd

Reader Interactions

Comments

  1. Praful says

    July 24, 2019 at 6:43 PM

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

    Reply
    • Mukesh Otwani says

      July 24, 2019 at 9:45 PM

      Hi Praful,

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

      Reply
  2. Dileep kumar says

    May 28, 2019 at 11:21 AM

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

    Reply
    • Mukesh Otwani says

      May 28, 2019 at 4:12 PM

      Hi Dileep,

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

      Reply
  3. Neha Agarwal says

    January 10, 2017 at 11:03 AM

    How to run selenium scripts in linux from command prompt

    Reply
    • Mukesh Otwani says

      January 11, 2017 at 4:12 PM

      Hi Neha,

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

      Reply
  4. palani says

    October 3, 2016 at 1:09 PM

    how to run selenium scripts in command prompts

    Reply
    • Mukesh Otwani says

      October 3, 2016 at 4:11 PM

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

      Reply
  5. Anoop Jain says

    September 30, 2016 at 3:37 PM

    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

    Reply
    • Mukesh Otwani says

      October 3, 2016 at 4:36 PM

      Hey Anoop,

      Compile the program again and then run the same program.

      Reply
  6. Alaka says

    August 22, 2016 at 12:28 AM

    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 ???

    Reply
    • Mukesh Otwani says

      August 27, 2016 at 11:26 PM

      Hi Alaka,

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

      Reply

Leave a Reply Cancel 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.

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?