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-
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.
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.
2- Open command prompt and type cd\ and press enter.
Now go to project home directory for this type cd directory path and enter
Now we can set classpath for this,specify bin folder
Home Directory > set classpath=Home Directory\bin; and press enter
Specify lib folder where all jars is available
Home Directory > set classpath=Home Directory\lib\*; and press enter
Step 3-Now run xml file using below command
Home-directory > java org,testng.TestNG testng.xml testng2.xml testng2.xml and hit enter
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.
Praful says
Could you please tell me how to run junit selenium TestRunner from command line?
Mukesh Otwani says
Hi Praful,
First do compilation step ->> javac -cp;. TestClass1.java TestClass2.java ;;. org.junit.runner.JUnitCore TestClass1 TestClass2
Then run step –>> java -cp
Dileep kumar says
you can start giving linux commands also where now-a-days more people are using the linux
Mukesh Otwani says
Hi Dileep,
Yes, you are right. I am preparing to come up with some linux stuffs…:)
Neha Agarwal says
How to run selenium scripts in linux from command prompt
Mukesh Otwani says
Hi Neha,
No idea on linux I will try and get back to you soon on this.
palani says
how to run selenium scripts in command prompts
Mukesh Otwani says
Post is describing the same. What are the issues you are facing?
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
Mukesh Otwani says
Hey Anoop,
Compile the program again and then run the same program.
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 ???
Mukesh Otwani says
Hi Alaka,
I would suggest you to use Maven and then run maven clean install test