Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

TestNG Tutorials 46: Overriding Parameters in TestNG | Make Selenium Easy

Posted on 08/22/2018 By admin

Hello Folks,

In this post we will learn an important concept of parameters in TestNG.

We know that we can create parameterised methods in a TestNG class and pass parameters to these methods through testng xml. We can pass parameters at four levels:

  1. At suite level
  2. At test level
  3. At class level
  4. At method level

Parameter value at higher level will be overridden by value at lower level if same parameter is passed. For example: If we pass a parameter say “Param” with value say “value1” at suite level and also we pass value “value2” for same parameter “Param” at test level, then parameter “Param” will have value as “value2” at that test level.

We will see some examples below:

Scenario 1: Passing parameters at suite level:-

TestNG class:

package Parameters;

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class ParameterTest {    
        @Test
        @Parameters({"testParameters1","testParameters2"})
        public void testMethod(String testParameters1, String testParameters2)
        {
                System.out.println("Paramters one for test method: "+testParameters1);
                System.out.println("Paramters two for test method: "+testParameters2);
        }
        
}

Testng xml:




        
        
        
                
                        
                
         
 

Output:

Suite level parameters values were used by test method. 

Scenario 2: Passing parameters at both suite level and test level :-

Testng xml:




        
        
        
        
        
                
                        
                
         
 

Note here that I am passing parameters values at both levels: Suite and test.

Output:

Parameters values at test level was used by test method. Value given at suite level was ignored.

Scenario 3: Passing parameters at suite level , test level  and class level:-

Testng xml:




        
        
        
        
        
                
                        
                        
                        
                
         
 

Output:

Class level parameters values were used by test method.




        
        
        
        
        
                
                        
                        
                        
                        
                                
                                        
                                        
                                                
                                                
                                
                                
                
         
 

Output:

Parameter values at method level were used by test methods ignoring all other higher levels.

Conclusion:

You can notice in all scenarios that parameter value at lower level was used by test methods. Now you will be thinking where we can use this concept?

  1. You can reuse parameters. You can pass different values to same parameters for two different test.
  2. Suppose you have 10 test methods and want to execute first 5 in chrome and last 5 in firefox. You can divide then in two tests and pass browser parameters with browser values.

Example:




        
                
                
                        
                                
                                        
                                        
                                        
                                        
                                        
                                

                        
                
         


        
                
                
                        
                                
                                        
                                        
                                        
                                        
                                        
                                

                        
                
         
 

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

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

Uncategorized

Post navigation

Previous Post: TestNG Tutorials 2: Installation Of TestNG In Eclipse ==> Download And Add To Build Path Way | Make Selenium Easy
Next Post: TestNG Tutorials 45: Passing Parameters at Test Method Level in TestNG | Make Selenium Easy

Related Posts

SelectedGroup – Make Selenium Easy Uncategorized
REST Assured Tutorial 69 – Response Logging In Rest Assured Uncategorized
March 29, 2017 – Make Selenium Easy Uncategorized
YatraCal – Make Selenium Easy Uncategorized
mapping – Make Selenium Easy Uncategorized
Postman Tutorial Part 6 – Understand HTTP Headers in API Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

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