Before continuing this post, you must go through below posts:
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.
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.
- “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=<Group Name1>,<Group Name2>,<Group Name3>. Pass multiple group names separated by comma.
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.
Author: Amod Mahajan
My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning