Run Selenium Webdriver Scripts using Command Line

Run Selenium Webdriver Scripts using Command Line

Welcome to Selenium Tutorials, today we will learn Run Selenium Webdriver Scripts using Command Line with examples.After creating Selenium script in Eclipse,you can run easily but it is not recommended every time because in case you want to run on client machine then it is recommended to use command prompt instead of opening eclipse and right click and run.

Selenium Webdriver Setup

Selenium Test Scripts from command line

Before executing Selenium Test Scripts from command line then you should’ve selenium setup in your machine, still not done then follow the below link and complete the setup.

Once you start designing Selenium Test cases Scripting continuously your Test Cases count will increase, so you’ve to manage your test cases accordingly. TestNG framework providing very helpful concept of creating testng.xml file based on requirement and put all relevant test classes inside the testng.xml file and run it as a Test Suite.

ALSO READ  Verify element is enabled in Selenium WebDriver

Trending Posts:

Write TestCase PASS/FAIL In Excel using Selenium
Solution – Testng Cannot Find ClassPath Error
Generate HTML Reports using Selenium
Webdriver Instance to Multiple Classes

Pre Requisites

1- TestNG should be installed in Eclipse.
2- testng xml file should be created.
3- Class-path should be set.

Run Selenium Webdriver Scripts using Command Line

Src – the .java files can be found here
Bin – the .class files will be generated here

Step 1- Create testng.xml files and store all xml into project home directory as given below.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Selenium Test Suite">    
<listeners>        
<listener class-name="org.uncommons.reportng.HTMLReporter" />        
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />           
</listeners>  
<test name="SeleniumRegressionTest">    
<classes>      
<class name="com.sel.Selenium.Practise.GoogleSite" />    
</classes>  
</test>
</suite>

Step 2- Set classpath now

ALSO READ  What is the default port number used by hub in Selenium?

Important points to remember

1-Put all the jars (Selenium jars) into separate folder and  put that folder into project home directory.
I’ve created Lib folder and pasted all required jars inside a folder ,downloaded from Selenium website.
Refer below screenshot of Lib folder with required jar files.
2- Open command prompt and type E: and press enter because my project work Space in E drive.

Now go to project home directory for this type directory path and enter as below.

ALSO READ  REST API testing using Rest Assured

Now we can set classpath for this,specify bin folder.

Home Directory > set classpath=Home Directory bin; and press enterSpecify 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 testng1.xml and hit enter.

Other wise you can run in single step as below command.

1.Go to Project Folder path in Command Line.
2.Enter below command in command line and hit enter.

java -cp E:QTPTutorialsSelenium_Workspace
Selenium_TutorialsLib*;E:QTPTutorialsSelenium_WorkspaceSelenium_Tutorialsbin org.testng.TestNG testng.xml

Test Results

Run Selenium Webdriver Scripts using Command Line_Test Results
Test Results

Thanks for visiting my blog. If you find this post informative then please share with your friends and provide your valuable comments on this post.

Rajesh K

Leave a Reply

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