Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • About Us
  • Toggle search form

Advanced TestNG Tutorials 35: How To Pass Multiple Group Names to be Run at Runtime in TestNG XML Using Beanshell

Posted on 03/16/2025 By admin

Hello Folks,

Before continuing this post, you must go through below posts:

Integration of TestNG and Beanshell

How To Pass a Group Name to be Run at Runtime in TestNG XML Using Beanshell

Problem statement:

You have created so many test methods with different groups. You do not need to run all group every time. You need to include or exclude groups as per requirements. You need to add include or exclude tags in testng xml which is not easier always. It will be even more difficult for a beginner or a business analyst or people with less technical knowledge to update testng xml to run. In this post, we will see how can we pass multiple group names.

Problem Solution:

WIll it not be good if you can pass group names at run time and no need to change anything in testng xml? Yes, its possible using beanshell.

TestNG class:

;

Testng XML:

  • “groupToRun” is a VM arguments which we can be passed through run configuration. Beanshell script will read it at run time and will execute group which we pass.
  • If no VM argument is passed, it will run all groups. So this testng xml can be used to run all groups as well as selected groups.
  • If a method belongs to any of passed group names, that method will be executed otherwise ignored.

Passing VM arguments in Run configurations:

Navigate to Run -> Run Configurations:

Select testng xml for which arguments need to be passed:

Click or Arguments tab and type in VM arguments as -DgroupToRun=,,. Pass multiple group names separated by comma.

Output:

Method tagged to either groups run.

More about TestNG in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below. If you like my posts, please like, comment, share and subscribe. #ThanksForReading

#HappySelenium

Uncategorized

Post navigation

Previous Post: Frequently Asked Java Program 28: Java Program to Remove Duplicate Characters From Word Using Collection Concept
Next Post: Java Interview Question 4 – What is HashCode of an Empty String?

Related Posts

June 10, 2018 – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized
Postman Tutorial Part 4 – Sending GET Request With Query Params in Postman Uncategorized
March 12, 2019 – Make Selenium Easy Uncategorized
Understand Defect Life Cycle In Testing Uncategorized
Why Do We Require Browser Driver Executable File To Launch A Browser In Selenium WebDriver? Uncategorized

Recent Posts

  • How to Set Up Selenium WebDriver with Python Step by Step
  • How to Set Up Selenium WebDriver with Java from Scratch
  • What Is Selenium and Why It Is the Most Popular Test Automation Framework
  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark