Shyam
Shyam

Reputation: 55

How to pass parameter to testng xml through command line

I am executing my selenium automation scripts through testng, for the same I am having a testng xml form where I am passing parameter values like which test case has to be executed and on which environment it has to be executed.

E.g of testng xml is pasted below

**<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Automation Suite">
<parameter name="tags" value="MyTestCase"/>
    <!-- Default suite -->    
<test name="GGGGG Automation Test" verbose="2">
<parameter name="Environment" value="MyEnvironment" />
<classes>
<class name="com.XXXXX.TestRunner.XXXXXX"/>
   </classes>
 </test>  
</suite>**

here I am passing 2 parameters like test cases and environment to be executed form testng example. I am looking for a command line 'command' to execute the testng xml passing those 2 parameters from commandline argument.

Upvotes: 2

Views: 8303

Answers (2)

Paras Maheshwari
Paras Maheshwari

Reputation: 1

You can pass a groupName to be run at runtime in TestNG XML using Beanshell.

For details, please refer: http://makeseleniumeasy.com/2018/07/15/advanced-testng-tutorials-34-how-to-pass-a-group-name-to-be-run-at-runtime-in-testng-xml-using-beanshell/

Upvotes: 0

Kidby
Kidby

Reputation: 189

By using JVM arguments you can pass in parameters, such as -Dname=Environment. This has been answered previously here.

This blog post has examples

Upvotes: 4

Related Questions