{"id":3844,"date":"2020-06-26T20:45:46","date_gmt":"2020-06-26T15:15:46","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=3844"},"modified":"2024-10-09T18:32:20","modified_gmt":"2024-10-09T13:02:20","slug":"data-provider-and-testng-xml-parameterization-in-selenium","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/data-provider-and-testng-xml-parameterization-in-selenium\/","title":{"rendered":"Data provider and TestNG XML: Parameterization in Selenium"},"content":{"rendered":"\n<p>When we create any software, we create it in a way that it should work differently with a different set of data. When it comes to testing the same created software, we can\u2019t test it just with one set of data. Here, we need to verify our created software with all the combinations that it is expected to support. This is where parameterization comes into the picture. We need to parameterize our test scripts to pass multiple data to the application at runtime. In Selenium, <strong>Data Provider and TestNG XML<\/strong> are essential tools for enabling this parameterization, making it easier to handle diverse data sets efficiently during testing. The concept achieved by <a href=\"https:\/\/en.wikipedia.org\/wiki\/Parametrization\" rel=\"nofollow noopener\" target=\"_blank\">parameterization <\/a>is called <strong>Data<\/strong>&#8211;<strong>Driven Testing.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Type of Parameterization in TestNG&nbsp;&nbsp;<\/strong><\/h2>\n\n\n\n<p>To get more clear on parameterization, we will go through the parameterization options in <strong>TestNG<\/strong> framework using Selenium WebDriver.<\/p>\n\n\n\n<p>There are two ways in TestNG to achieve parameterization<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>With the help of Parameters annotation and TestNG XML file.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/pHj8ogVa6CRGxLSMONDMIUX106lAYm4KN03f7K9HXqjfm_1_KKZtS4kJFI6UxeibojQkzqj6ESE6z57PSxFTRrRkBFGsI5KRyyUxzVg7ro5Q7kuAg9hqd0h6Ixz0cViDAAKSJMKYXWkyQ3rnOQ\" alt=\"parameters.PNG\" title=\"\"><\/figure>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>With the help of DataProvider annotation.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/7dXIJN9fRD0jZYrZbIGPrdJJn5Dzcp8o7SDteSnVFUnKm-87F5fh4dHluM-5VuIXM0VCskweIg4ysfcMw8eHQyZgfCcSr9rU8tO2yX-AXjgjhh0HPR4l5bIypjMb7OKxuSeBXejEE_g0LZdgow\" alt=\"searchkey.PNG\" title=\"\"><\/figure>\n\n\n\n<p>Parameters from Testng.xml can be suite level or test level<\/p>\n\n\n\n<p>Parameter from DataProvider can take Method and ITestContext as a parameter.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Parameters annotation with Testng.xml<\/strong><\/h2>\n\n\n\n<p>Select parameterization using annotations when you deal with complexity and the number of input combinations is less.<\/p>\n\n\n\n<p>Let consider the below scenario to Open google.com in your browser and search 3 keywords separately. To complete the scenario, below are the steps that our script has to perform.<\/p>\n\n\n\n<p>Step 1: Launch the browser and go to the Google.com site<\/p>\n\n\n\n<p>Step 2: Enter a search Keyword as input in the search box and click search.<\/p>\n\n\n\n<p>Step 3: Verify the input value on UI to be the same as test data.<\/p>\n\n\n\n<p>Step 4: Repeat the 2 and 3 steps for the other 2 keywords.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>KEYWORD TO SEARCH<\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Selenium<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">JMeter<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">QTP<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><em>The below code shows how we can do it without parameterization in TestNG.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> parameterization;\n\n<strong>import<\/strong> java.util.concurrent.TimeUnit;\n\n<strong>import<\/strong> org.openqa.selenium.By;\n<strong>import<\/strong> org.openqa.selenium.WebDriver;\n<strong>import<\/strong> org.openqa.selenium.WebElement;\n<strong>import<\/strong> org.openqa.selenium.firefox.FirefoxDriver;\n\/\/import org.testng.Assert;\n<strong>import<\/strong> org.testng.AssertJUnit;\n<strong>import<\/strong> org.testng.annotations.Test;\n\n<strong>public<\/strong> <strong>class<\/strong> WithoutParameter {\nString driverPath = \"F:\\\\drivers\\\\geckodriver.exe\";\nWebDriver driver;\n\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0@Test\n\u00a0\u00a0\u00a0\u00a0<strong>public<\/strong> <strong>void<\/strong> testNoParameter() <strong>throws<\/strong> InterruptedException{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0String author = \"test\";\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0String keyWord = \"Selenium\";\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.<em>setProperty<\/em>(\"webdriver.gecko.driver\", driverPath);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0driver= <strong>new<\/strong> FirefoxDriver();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0driver.manage().timeouts().implicitlyWait(10, TimeUnit.<strong><em>SECONDS<\/em><\/strong>);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0driver.get(\"https:\/\/google.com\");\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0WebElement searchText = driver.findElement(By.<em>name<\/em>(\"q\"));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/Searching text in google text box\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0searchText.sendKeys(keyWord);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.<strong><em>out<\/em><\/strong>.println(\"Greeting ->\"+author+\" The Search key is->\"+keyWord);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.<strong><em>out<\/em><\/strong>.println(\"Thread will sleep now\");\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Thread.<em>sleep<\/em>(3000);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.<strong><em>out<\/em><\/strong>.println(\"Value in Google Search Box = \"+searchText.getAttribute(\"value\") +\" ::: Value given by input = \"+keyWord);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/verifying the value in google search box\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0AssertJUnit.<em>assertTrue<\/em>(searchText.getAttribute(\"value\").equalsIgnoreCase(keyWord));\n}\n}<\/code><\/pre>\n\n\n\n<p>To pass the other 2 keywords, we\u2019ll have to write the same piece of code again with different keyword values for the string \u2018<strong>keyWord<\/strong>\u2019, which would result in a lengthy and repetitive code.<\/p>\n\n\n\n<p>Let us now simplify our problem bypassing these keywords as parameters in our testng.xml and adding&nbsp;<strong>@parameters<\/strong>&nbsp;annotation in our test.<\/p>\n\n\n\n<p><strong>Java Code:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> parameterization;\n\n<strong>import<\/strong> java.util.concurrent.TimeUnit;\n\n<strong>import<\/strong> org.openqa.selenium.By;\n<strong>import<\/strong> org.openqa.selenium.WebDriver;\n<strong>import<\/strong> org.openqa.selenium.WebElement;\n<strong>import<\/strong> org.openqa.selenium.firefox.FirefoxDriver;\n\/\/import org.testng.Assert;\n<strong>import<\/strong> org.testng.AssertJUnit;\n<strong>import<\/strong> org.testng.annotations.Optional;\n<strong>import<\/strong> org.testng.annotations.Parameters;\n<strong>import<\/strong> org.testng.annotations.Test;\n\n<strong>public<\/strong> <strong>class<\/strong> ParameterizedClass {\nString driverPath = \"F:\\\\drivers\\\\geckodriver.exe\";\nWebDriver driver;\n\u00a0\u00a0\u00a0\u00a0@Test\n\u00a0\u00a0\u00a0\u00a0@Parameters({\"author\",\"keyWord\"})\n\u00a0\u00a0\u00a0\u00a0<strong>public<\/strong> <strong>void<\/strong> testParameterizationWithXML( @Optional(\"Abc\") String author,String keyWord) <strong>throws<\/strong> InterruptedException{\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.<em>setProperty<\/em>(\"webdriver.gecko.driver\", driverPath);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0driver = <strong>new<\/strong> FirefoxDriver();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0driver.manage().timeouts().implicitlyWait(10, TimeUnit.<strong><em>SECONDS<\/em><\/strong>);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0driver.get(\"https:\/\/google.com\");\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0WebElement searchText = driver.findElement(By.<em>name<\/em>(\"q\"));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/Searching text in google text box\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0searchText.sendKeys(keyWord);\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.<strong><em>out<\/em><\/strong>.println(\"Greeting ->\"+author+\" The search key is->\"+keyWord);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.<strong><em>out<\/em><\/strong>.println(\"Thread will sleep now\");\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Thread.<em>sleep<\/em>(3000);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.<strong><em>out<\/em><\/strong>.println(\"Value in Google Search Box = \"+searchText.getAttribute(\"value\") +\" ::: Value given by input = \"+keyWord);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/verifying the value in google search box\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0AssertJUnit.<em>assertTrue<\/em>(searchText.getAttribute(\"value\").equalsIgnoreCase(keyWord));\n\n}\n}<\/code><\/pre>\n\n\n\n<p>Below is the TestNG.xml which we used to perform parameterization in TestNG for Selenium automation testing.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=<em>\"1.0\"<\/em> encoding=<em>\"UTF-8\"<\/em>?>\n&lt;!DOCTYPE suite SYSTEM \"http:\/\/testng.org\/testng-1.0.dtd\">\n&lt;suite name=<em>\"TestSuite\"<\/em> thread-count=<em>\"3\"<\/em> >\n&lt;parameter name=<em>\"author\"<\/em> value=<em>\"test\"<\/em> \/>\n&lt;parameter name=<em>\"KeyWord\"<\/em> value=<em>\"Selenium\"<\/em> \/>\n&lt;test name=<em>\"test\"<\/em>>\n\n&lt;classes>\n&lt;class name=<em>\"parameterization.ParameterizedClass\"<\/em>>\n&lt;\/class>\n&lt;\/classes>\n&lt;\/test>\n&lt;\/suite><\/code><\/pre>\n\n\n\n<p>We follow below instructions to run the script by selecting the XML file and Run as Test NG Suite<strong>Right Click on testng.xml file -> Run as -><\/strong><a href=\"https:\/\/www.h2kinfosys.com\/blog\/testng-tutorial\/\"><strong>\u00a0Testng\u00a0<\/strong><\/a><strong>Suite (Note : Suite)<\/strong><\/p>\n\n\n\n<p><img fetchpriority=\"high\" decoding=\"async\" width=\"602\" height=\"278\" alt=\"parametertestng.PNG\" src=\"https:\/\/lh4.googleusercontent.com\/F6rBxgt31iFJ54utKQLeS9ERftshM8NS2mCI5u0CYlFBiymJZdYnwR0OC-Byf4-DZDeuW755-EfkVivl9oH8yK3L1TV_m36TKiByG-p8i2F-A-qG6YpOiClcryL84mqQVkwSzRd-_hqb5VGBfg\" title=\"\"><\/p>\n\n\n\n<p>Now, parameters can be defined at 2 levels<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Suite level \u2013 The parameters inside the &lt;suite> tag of TestNG XML file will be a suite level parameter.<\/li>\n\n\n\n<li>Test Level &#8212; The parameters inside the &lt;Test> tag of testing XML file will be a Test level parameter.<\/li>\n<\/ol>\n\n\n\n<p>Here is a similar test with suite level parameters<\/p>\n\n\n\n<p><img decoding=\"async\" width=\"547\" height=\"237\" alt=\"thread1.PNG\" src=\"https:\/\/lh6.googleusercontent.com\/JeddWfcTB7pREa7x7AVQhlvO9SEVz4MYNpxtgHAIBI9RIfRA_dH_i5NZNHwhiq6FhZE42BTVtQgaNUblamMVVSDFM9QwvtG2pYoeG3z37lSN1IukJ9LFtl4t5m3XUgHUWQ148OzmRr3SFjAz-g\" title=\"\"><\/p>\n\n\n\n<p><strong><em>NOTE:&nbsp;<\/em><\/strong>In the case, if the parameter name is the same in the suite level and test level then the test level parameter will get preference over the suite level. So, in such a case, all the classes inside that test level will share the overridden parameter, and other classes that are outside the test level will share the suite level parameter.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/Bt-foCm1q9lbddp_UHXqDRpSyRgWmTRQz92OIAO-n2R1J3LlOw3M3ki4BT_0HtVEe9K7yB0Q1plr2TrLrCpyOvJc_ca9YH82-VS2RlkLNfz7ZPp4hR2fA58ZRYaCYb2rihnKGBN5SO9YzY2cTA\" alt=\"thread2.PNG\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Troubleshooting<\/strong><\/h2>\n\n\n\n<p><strong>Issue 1:<\/strong> It will throw an error if the parameter value in testng.xml cannot be typecasted to the corresponding test methods parameter.<\/p>\n\n\n\n<p>Consider the example below<\/p>\n\n\n\n<p><img decoding=\"async\" width=\"602\" height=\"217\" alt=\"author.PNG\" src=\"https:\/\/lh3.googleusercontent.com\/PxJ6_wZhR0TfRPFR9oXRQaPey76chI2wVrnJ4qKM_9ckPgvj-ayRrWu8J7beg03RmZqj9Hl1d74Tc9RRM0NcDyml9mychOaaH_C7fnbXaaTP5utV3CqLTec3bmmvCpRjVX1n2lJA6-DW2Tvl3w\" title=\"\"><\/p>\n\n\n\n<p>When you run the TestNG.xml file it will throw a below exception<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/kEXLD_PzTBiKUOlBk6y6CM_iIv6sZPAbCqZRZcpirLyipK6rvgRpNOi72QHt03qzuYhlHa8KEWRZhAxRNlb_AOqPntjBjG8rlY3CezbJ3ooThlMteaZdtZZ5JzmBLmWvTKN0D45WfEJuRTEvJA\" alt=\"errorauthor.PNG\" title=\"\"><\/figure>\n\n\n\n<p>Here, the &#8216;author&#8217; attribute is equal to &#8216;Test&#8217; which is a string and in the corresponding test method it is expecting an integer value, so we will get an exception.<\/p>\n\n\n\n<p><strong>Issue 2: <\/strong>Your @Parameters do not have a corresponding value in testing.xml.<\/p>\n\n\n\n<p>You can overcome this situation by adding&nbsp;<strong>@optional<\/strong>&nbsp;<strong>annotation<\/strong>&nbsp;in the corresponding parameter in the test method.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/OQj6DVO60VVtjflOhBuFlL4lS1qToNai7cS90QnRTyqgXQHc6hWJjknL72RbWGKwIqcpUYO9tC8rwslE2646bP6M5N_F9huMDHXMGACFo1tWkauKka83B9P23Bb_7J9lgfTsjDxY4jQfh0g67w\" alt=\"issue2.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Issue 3<\/strong><strong><em>:<\/em><\/strong><strong>&nbsp;<\/strong>Using<strong> <\/strong>Testng.xml if you want to test multiple values for the same parameter.<\/p>\n\n\n\n<p>You can have multiple and different parameters, but each parameter can only have a single value. This can help by hardcoding values into the script which makes the code reusable. If you want to use multiple values for the same parameter we will use DataProviders.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Parameterization in TestNG scripts for automated browser testing<\/strong><\/h2>\n\n\n\n<p>Let us consider the below scenario by printing a specific browser value by passing the browser name as a parameter.<\/p>\n\n\n\n<p><strong>Java Code:<\/strong><\/p>\n\n\n\n<p><strong>Step 1: <\/strong>Create a Package (parameterization)<strong>Step 2: <\/strong>Create a Class (PassingParameter)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> parameterization;\n\n<strong>import<\/strong> org.testng.annotations.Parameters;\n<strong>import<\/strong> org.testng.annotations.Test;\n\n<strong>public<\/strong> <strong>class<\/strong> PassingParameter {\n@Parameters(\"browser\")\n\u00a0 @Test\n\u00a0 <strong>public<\/strong> <strong>void<\/strong> test(String browser) {\n\u00a0 \u00a0 \u00a0 <strong>if<\/strong>(browser.equalsIgnoreCase(\"FF\"))\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.<strong><em>out<\/em><\/strong>.println(\"The browser value is : \" +browser);\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<strong>else<\/strong> <strong>if<\/strong>(browser.equalsIgnoreCase(\"Chrome\"))\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.<strong><em>out<\/em><\/strong>.println(\"The browser value is : \" +browser);\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<strong>else<\/strong> <strong>if<\/strong>(browser.equalsIgnoreCase(\"IE\"))\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.<strong><em>out<\/em><\/strong>.println(\"The browser value is : \" +browser);\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <strong>else<\/strong>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 System.<strong><em>out<\/em><\/strong>.println(\"Incorrect browser value passed.\");\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0\n\u00a0 }\n}<\/code><\/pre>\n\n\n\n<p><em><strong>Step 3:<\/strong> Create a TestNG.xml file<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=<em>\"1.0\"<\/em> encoding=<em>\"UTF-8\"<\/em>?>\n&lt;!DOCTYPE suite SYSTEM \"http:\/\/testng.org\/testng-1.0.dtd\">\n&lt;suite name=<em>\"Suite\"<\/em>>\n\u00a0\u00a0&lt;test name=<em>\"Firefox Test\"<\/em>>\n\u00a0\u00a0\u00a0&lt;parameter name=<em>\"browser\"<\/em> value=<em>\"FF\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0&lt;classes>\n\u00a0\u00a0 &lt;class name=<em>\"parameterization.PassingParameter\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0&lt;\/classes>\n\u00a0\u00a0&lt;\/test>\n\u00a0\n\u00a0\u00a0&lt;test name=<em>\"IE Test\"<\/em>>\n\u00a0\u00a0\u00a0&lt;parameter name=<em>\"browser\"<\/em> value=<em>\"IE\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0&lt;classes>\n\u00a0\u00a0 &lt;class name=<em>\"parameterization.PassingParameter\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0&lt;\/classes>\n\u00a0\u00a0&lt;\/test>\n\u00a0\u00a0&lt;test name=<em>\"Incorrect Browser\"<\/em>>\n\u00a0\u00a0&lt;parameter name=<em>\"browser\"<\/em> value=<em>\"ABC\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0&lt;classes>\n\u00a0\u00a0 &lt;class name=<em>\"parameterization.PassingParameter\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0&lt;\/classes>\n\u00a0\u00a0&lt;\/test>\n\u00a0&lt;\/suite><\/code><\/pre>\n\n\n\n<p>Run the above Testng.xml file and you will see the below output in console:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/JMlfTzpeDmSgsj6DD2RzMZD77TO2pK-9-YTT1DDDdibtWvR4mWcaVCuTUitmQTOsz-Y8Y01Eu2T2ez5cbdV9ElZiBaJa8Jgy6jtwpJY8HdqtFbvmYYFsKUD7oyXhX3c9EqlYdy-QzWoYb2KXpw\" alt=\"Output1.PNG\" title=\"\"><\/figure>\n\n\n\n<p>In the test results summary you\u2019ll see that the parameter values passed in the XML is also printed when you go by the detailed results:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/8r3HYi2VVHTzmXB4Ncr9pu7pp059fZaKMrJbeTJIQh_bKWlvNYY5aQi5Wsiq4ABA88rZiScMN7hr8mVSvYLvVioOmVCLNnNRKvybQtsw8EFr1MihXWWXGxOUFVim6lD7UdUw0P3BScJ06A0H2g\" alt=\"output2.PNG\" title=\"\"><\/figure>\n\n\n\n<p>The emailable report shows that the different parameters are passed to different tests to consolidate the results easy:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/3QPJUNLzQtxA19zKdbUvMeDqmqLMXa7pR5NfHHnNWqCkqeHKhwN6T791d5u6KBWDRlUXBjZ01J7dhPgCCQBfqDrLnxNCNNpFs_y2gTEkPtgoHX0yLDVjUo_kpyhGLlxeLNZPXT2XuPiO8iM_XQ\" alt=\"output3.PNG\" title=\"\"><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/dL_Q1NuOoc8pcp6whK1eyYF-FBkxj6p8LfBXztFSt9gec_PS8SKSgwCDHC58SlNt_fpZZCZlynS1UEaVEIbDQiHareVQ3cQFH2GL5uN5Wt0Nf1szF9s5u7LjIMkxGqOuddqwUE7_YVs_96h3tQ\" alt=\"output4.PNG\" title=\"\"><\/figure>\n\n\n\n<p>Now let us try to understand how we can leverage combinations of parameters for Selenium automation testing by passing 2 parameters to our test. Make note that whatever number of parameters you pass to your test you need to accept the same number of parameters in your test method in a correct sequence.<\/p>\n\n\n\n<p>Let us consider the below scenario by printing a specific browser and URL value by passing the browser name as well as URL as a parameter.<\/p>\n\n\n\n<p>Step 1: Create a Package (parameterization<\/p>\n\n\n\n<p>Step 2: Create a Class (PassingMultipleParameters)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> parameterization;\n\n<strong>import<\/strong> org.testng.annotations.Parameters;\n<strong>import<\/strong> org.testng.annotations.Test;\n\n<strong>public<\/strong> <strong>class<\/strong> PassingMultipleParameters {\n@Parameters({\"url\",\"browser\"})\n@Test\n<strong>public<\/strong> <strong>void<\/strong> test1(String url,String browser)\n{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>if<\/strong>(browser.equalsIgnoreCase(\"FF\"))\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"The browser value is : \" +browser);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>else<\/strong> <strong>if<\/strong>(browser.equalsIgnoreCase(\"Chrome\"))\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"The browser value is : \" +browser);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>else<\/strong> <strong>if<\/strong>(browser.equalsIgnoreCase(\"IE\"))\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"The browser value is : \" +browser);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>else<\/strong>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"Incorrect browser value passed.\");\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n}\n}<\/code><\/pre>\n\n\n\n<p><em><strong>Step 3:<\/strong> Create a TestNG.xml file<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=<em>\"1.0\"<\/em> encoding=<em>\"UTF-8\"<\/em>?>\n&lt;!DOCTYPE suite SYSTEM \"http:\/\/testng.org\/testng-1.0.dtd\">\n&lt;suite name=<em>\"Suite\"<\/em>>\n\u00a0\u00a0&lt;test name=<em>\"Firefox Test\"<\/em>>\n\u00a0\u00a0\u00a0&lt;parameter name=<em>\"url\"<\/em> value=<em>\"http:\/\/www.yahoo.com\"<\/em>\/>\n\u00a0\u00a0\u00a0&lt;parameter name=<em>\"browser\"<\/em> value=<em>\"FF\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0&lt;classes>\n\u00a0\u00a0 &lt;class name=<em>\"parameterization.PassingMultipleParameters\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0&lt;\/classes>\n\u00a0\u00a0&lt;\/test>\n\u00a0\n\u00a0\u00a0&lt;test name=<em>\"Chrome Test\"<\/em>>\n\u00a0\u00a0\u00a0&lt;parameter name=<em>\"url\"<\/em> value=<em>\"http:\/\/www.google.com\"<\/em>\/>\n\u00a0\u00a0\u00a0&lt;parameter name=<em>\"browser\"<\/em> value=<em>\"Chrome\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0&lt;classes>\n\u00a0\u00a0 &lt;class name=<em>\"parameterization.PassingMultipleParameters\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0&lt;\/classes>\n\u00a0\u00a0&lt;\/test>\n&lt;\/suite><\/code><\/pre>\n\n\n\n<p>Run the above Testng.xml file and you will see the below output in console:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/fsY-SDxlW4SKOGIpDJmEpB3KscAVECH-0oHr9TSmxuo7wedoEaDIdgfURvBmI7nDLbKKuCqn3q9VqZUMGIG8YrT-QAG5g4KB3miE4PMPg86Ii16uFPx6pi3Fg6vNQLSmYbMW0NqJ_kax-xgkrA\" alt=\"output5.PNG\" title=\"\"><\/figure>\n\n\n\n<p>In the test results summary you\u2019ll see that the parameter values passed in the XML are also printed when you go by the detailed results:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/PrQWdgw2sZAAn4OcDGF4EzZqK8kg8ayeOvibGGwmiH9wjfWUxdmEq3yppsI8yXYTUq5cQ102JCISXPX4vYqnkejBRze38Mrm4m-XhWVlTmysXHzBzhcSeKLRKG4wMDhCnu3JiCxtxf8SN134EQ\" alt=\"output6.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Email Report:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/NAOTu165sbMnrR6DLSJzUeUZ4okwGNjltn6Ph5pM7VpbpETRfU5njDNLpHFdfvBzQCfHzwKds5h14pI53IkZCY10yHX0W85cYaqL1vltw86EuqaXoOxQNGIZC3gt9z8GIyNQ8HbZsOGO_7BXEg\" alt=\"emailoutput.PNG\" title=\"\"><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/UyI71b_-_OcFigYgi1aDgHMrMl_uneWFqVPKVId31iMkyibq_EaKrG2XPeUkKUqzLJ98YJSESIAxrOLLfLn-l4Tmi5wnobQRsSFDaCcNmU7atq5uUuNGrIVZZQFAhhS0-Fd7SGRcYUyvSLR8_Q\" alt=\"emailoutput1.PNG\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Parameterization using Data Providers in TestNG<\/strong><\/h2>\n\n\n\n<p>In the above session, we have seen how to use the @Parameters annotation in our framework to get various results. Now, going further we will come across cases where we will have to use test scripts against multiple sets of data. Sometimes we might need huge sets of data to be used in a single execution. This type of testing is also called Data-Driven Testing. This can be achieved by using @DataProvider annotation in our TestNG framework.<\/p>\n\n\n\n<p><strong>&nbsp;The Syntax for @DataProvider annotation.<\/strong><\/p>\n\n\n\n<p>@DataProvider(name=\u201dSearchProvider\u201d)<\/p>\n\n\n\n<p>public Object[ ][ ] TestDataFeed(){<\/p>\n\n\n\n<p>Before we start using it for parameterization in TestNG first we need to note two points. @DataProvider has only one attribute i.e \u2018<strong>name<\/strong>\u2019 and secondly, it is optional and in that case, you do not specify it, then the name would be the same as the corresponding method name. This Data Provider returns a 2-Dimensional array object.<\/p>\n\n\n\n<p>Now let us try to understand by using a simple example where we will try to pass the monument and city name using data provider. You can further use this example as a base to login to Gmail or Facebook using different email ID and passwords.<\/p>\n\n\n\n<p>Let us consider the scenario to Open google.com and search 3 keywords with separate combinations.<\/p>\n\n\n\n<p>Let us follow the below steps to get this executed:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Launch the browser to open\u00a0<a href=\"http:\/\/www.google.com\/\" rel=\"nofollow noopener\" target=\"_blank\">www.google.com<\/a><\/li>\n\n\n\n<li>Search the first keyword combination.<\/li>\n\n\n\n<li>Get the page title.<\/li>\n\n\n\n<li>Repeat steps 2 &amp; 3 for the other 2 keywords combination.<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u00a0<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>&nbsp; &nbsp; MONUMENT<\/td><td>CITY<\/td><\/tr><tr><td>GateWay Of India<\/td><td>Mumbai<\/td><\/tr><tr><td>Konark Sun Temple<\/td><td>Konark<\/td><\/tr><tr><td>Statue Of Unity<\/td><td>Gujarat<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Java Code:<\/p>\n\n\n\n<p><strong>Step 1:<\/strong> Create a Package (dataprovider)<strong>Step 2:<\/strong> Create a Class Data_Provider<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> dataProvider;\n\n<strong>import<\/strong> org.openqa.selenium.By;\n<strong>import<\/strong> org.openqa.selenium.WebDriver;\n<strong>import<\/strong> org.openqa.selenium.WebElement;\n<strong>import<\/strong> org.openqa.selenium.firefox.FirefoxDriver;\n<strong>import<\/strong> org.testng.annotations.DataProvider;\n<strong>import<\/strong> org.testng.annotations.Test;\n\n<strong>public<\/strong> <strong>class<\/strong> Data_Provider {\n\u00a0 WebDriver driver;\n\u00a0\u00a0\n\u00a0 @Test(dataProvider=\"searchText\")\u00a0\n\u00a0 <strong>public<\/strong> <strong>void<\/strong> paramByDataProvider(String monument,String city) <strong>throws<\/strong> InterruptedException {\n\u00a0 \/\/Initializing Driver\nSystem.<em>setProperty<\/em>(\"webdriver.gecko.driver\",\"F:\\\\drivers\\\\geckodriver.exe\");\u00a0\u00a0\n\u00a0 \u00a0 \u00a0 \u00a0 driver = <strong>new<\/strong> FirefoxDriver();\n\u00a0 \u00a0 \u00a0 \u00a0 \/\/Opening search engine\n\u00a0 \u00a0 \u00a0 \u00a0 driver.get(\"https:\/\/google.com\");\n\u00a0 WebElement searchBox=driver.findElement(By.<em>name<\/em>(\"q\"));\n\u00a0 searchBox.sendKeys(monument +\" \"+city);\n\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"You are trying to search \" +monument+ \" which is in \" +city);\n\u00a0 \u00a0\n\u00a0 WebElement srchBtn = driver.findElement(By.<em>name<\/em>(\"btnK\"));\n\u00a0 srchBtn.submit();\n\u00a0 Thread.<em>sleep<\/em>(3000);\n\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"The page title is: \" +driver.getTitle());\n\u00a0 \u00a0 driver.quit();\n\u00a0 }\n\u00a0\n\u00a0\n\u00a0 \/*Data Provider which returns Object&#91;]&#91;] wherein\n\u00a0 * The first column has 'monument' and the second one has 'city'\n\u00a0 **\/\n\u00a0 @DataProvider(name=\"searchText\")\n\u00a0 <strong>public<\/strong> Object&#91;]&#91;] getDataProviderData(){\n\u00a0 \u00a0 \u00a0 \u00a0 Object&#91;]&#91;] searchWords=<strong>new<\/strong> Object&#91;3]&#91;2];\n\u00a0 \u00a0 \u00a0 \u00a0 \/\/Enter data into Object Array\n\u00a0 \u00a0 \u00a0 \u00a0 searchWords&#91;0]&#91;0]=\"Gate Way Of India\";\n\u00a0 \u00a0 \u00a0 \u00a0 searchWords&#91;0]&#91;1]=\"Mumbai\";\n\u00a0 \u00a0 \u00a0 \u00a0 searchWords&#91;1]&#91;0]=\"Konark Sun Temple\";\n\u00a0 \u00a0 \u00a0 \u00a0 searchWords&#91;1]&#91;1]=\"Konark\";\n\u00a0 \u00a0 \u00a0 \u00a0 searchWords&#91;2]&#91;0]=\"Statue of Unity\";\n\u00a0 \u00a0 \u00a0 \u00a0 searchWords&#91;2]&#91;1]=\"Gujarat\";\n\u00a0 \u00a0 <strong>return<\/strong> searchWords;\n\u00a0 \u00a0\n\u00a0 }\n\n}<\/code><\/pre>\n\n\n\n<p><strong>Step 3:<\/strong> Create a TestNG.xml file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=<em>\"1.0\"<\/em> encoding=<em>\"UTF-8\"<\/em>?>\n&lt;!DOCTYPE suite SYSTEM \"http:\/\/testng.org\/testng-1.0.dtd\">\n&lt;suite name=<em>\"Suite\"<\/em>>\n\u00a0\u00a0&lt;test name=<em>\"Firefox Test\"<\/em>>\n\u00a0\u00a0\u00a0 &lt;classes>\n\u00a0\u00a0 &lt;class name=<em>\"dataprovider.Data_Provider\"<\/em>\/>\n&lt;\/classes>\n\u00a0\u00a0&lt;\/test>\n\u00a0&lt;\/suite> &lt;!-- Suite --><\/code><\/pre>\n\n\n\n<p>We will get the output like below which summarizes the data providers passed and the corresponding results:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/QtKY0h69AqN00wEGt-xJdsddSVSonIGOVmrf2ujKMIZUTBg8nPPSGu0Q6JdEc1NuLZFRRvCSnnPJJeaYrU0M4a65zweOnDdf71hmuywF8pIsUzCZbXklQJE5pB0n4U5enGdqSm2Hukm_mTcu0Q\" alt=\"dataprov1.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Emailable Report:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/lt-RGjJdvWJsJE2BCYM7mm1D7JGHacnF28yMGwL5EiF5Eyw17dlYRgpsxWI0JdCjaRjGVlzPzITZ2p1Ozoq23PkZEwzoAFh97NOGID1AJR5fbGpbpsMvlra1aFMnbJfCKRC1NY9_Fv7diqoDLQ\" alt=\"dataprov2.PNG\" title=\"\"><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/NXtBg33LE8VvxClujQendf5Y5a3ftTx2D5H0nSedra22Dgk81n46mUR_LUsSwtsHDtHn4txQRSAYKxl5M9v4N5ZZkOua1vptMcRCqPG4cFVt--C5ejqiPLjqtyqyYr1mWUtAO-8VTo38vn_QJw\" alt=\"dataprov3.PNG\" title=\"\"><\/figure>\n\n\n\n<p>In the above example, we tried with data providers being invoked from the same class. You can also invoke data providers from another class by simply making the data provider method static and provide the data provider class in the test method annotation.&nbsp;<\/p>\n\n\n\n<p>Let us consider the example by creating a different class for our data provider.<\/p>\n\n\n\n<p><strong>Java Code for Data Provider Class:Step 1: <\/strong>Create a Class<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> dataprovider;\n\n<strong>import<\/strong> org.testng.annotations.DataProvider;\n\n<strong>public<\/strong> <strong>class<\/strong> DataProviderClass {\n@DataProvider(name=\"searchText\")\n\u00a0 <strong>public<\/strong> <strong>static<\/strong> Object&#91;]&#91;] getDataProviderData(){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Object&#91;]&#91;] searchWords=<strong>new<\/strong> Object&#91;3]&#91;2];\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Enter data into Object Array\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 searchWords&#91;0]&#91;0]=\"Gate Way Of India\";\n\u00a0 \u00a0 \u00a0 \u00a0 searchWords&#91;0]&#91;1]=\"Mumbai\";\n\u00a0 \u00a0 \u00a0 \u00a0 searchWords&#91;1]&#91;0]=\"Konark Sun Temple\";\n\u00a0 \u00a0 \u00a0 \u00a0 searchWords&#91;1]&#91;1]=\"Konark\";\n\u00a0 \u00a0 \u00a0 \u00a0 searchWords&#91;2]&#91;0]=\"Statue of Unity\";\n\u00a0 \u00a0 \u00a0 \u00a0 searchWords&#91;2]&#91;1]=\"Gujarat\";\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<strong>return<\/strong> searchWords;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 }\n\n}<\/code><\/pre>\n\n\n\n<p><strong>Step 2:<\/strong> Create a TestNG.xml file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=<em>\"1.0\"<\/em> encoding=<em>\"UTF-8\"<\/em>?>\n&lt;!DOCTYPE suite SYSTEM \"http:\/\/testng.org\/testng-1.0.dtd\">\n&lt;suite name=<em>\"Suite\"<\/em>>\n\u00a0\u00a0&lt;test name=<em>\"Firefox Test\"<\/em>>\n\u00a0\u00a0\u00a0 &lt;classes>\n\u00a0\u00a0 &lt;class name=<em>\"dataprovider.ClassLevelDataProvider\"<\/em>\/>\n&lt;\/classes>\n\u00a0\u00a0&lt;\/test>\n\u00a0\u00a0&lt;\/suite> &lt;!-- Suite --><\/code><\/pre>\n\n\n\n<p>Run the above TestNG.xml file and you can see that we receive the same results as we got before.<\/p>\n\n\n\n<p><strong>Data Provider annotation with parameters using&nbsp;<\/strong>Method<strong>&nbsp;and&nbsp;<\/strong>ITestContext<strong>.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 1: Using Method Parameter in TestNG<\/strong><\/h3>\n\n\n\n<p>We use method parameters in TestNG if we want the same data provider to work differently for different methods like in a case where we test different data sets for different test methods.&nbsp;<\/p>\n\n\n\n<p>Let us consider the below example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check if the method name is domesticMonuments<\/li>\n\n\n\n<li>If it returns one set of value<\/li>\n\n\n\n<li>If not then return another set of value<\/li>\n<\/ul>\n\n\n\n<p><strong>Java Code:Step 1: <\/strong>Create a Class (dataProviders)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> dataprovider;\n\n<strong>import<\/strong> java.lang.reflect.Method;\n\n<strong>import<\/strong> org.openqa.selenium.By;\n<strong>import<\/strong> org.openqa.selenium.WebDriver;\n<strong>import<\/strong> org.openqa.selenium.WebElement;\n<strong>import<\/strong> org.openqa.selenium.firefox.FirefoxDriver;\n<strong>import<\/strong> org.testng.annotations.AfterMethod;\n<strong>import<\/strong> org.testng.annotations.BeforeMethod;\n<strong>import<\/strong> org.testng.annotations.DataProvider;\n<strong>import<\/strong> org.testng.annotations.Test;\n\n<strong>public<\/strong> <strong>class<\/strong> dataProviders {\nWebDriver driver;\n\u00a0\u00a0\u00a0 @BeforeMethod\n\u00a0\u00a0 <strong>public<\/strong> <strong>void<\/strong> setUp(){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Initializing Driver\nSystem.<em>setProperty<\/em>(\"webdriver.gecko.driver\",\"F:\\\\drivers\\\\geckodriver.exe\");\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver = <strong>new<\/strong> FirefoxDriver();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Opening search engine\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.get(\"https:\/\/google.com\");\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n\u00a0\u00a0 @AfterMethod\n\u00a0\u00a0 <strong>public<\/strong> <strong>void<\/strong> tearDown(){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.quit();\n\u00a0\u00a0 }\n\u00a0\u00a0 @Test(dataProvider=\"destinations\")\n\u00a0\u00a0 <strong>public<\/strong> <strong>void<\/strong> domesticMonuments(String monument,String city) <strong>throws<\/strong> InterruptedException{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebElement searchBox=driver.findElement(By.<em>name<\/em>(\"q\"));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 searchBox.sendKeys(monument +\" \"+city);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"You are trying to search \" +monument+ \" which is in \" +city);\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebElement srchBtn = driver.findElement(By.<em>name<\/em>(\"btnK\"));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 srchBtn.submit();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Thread.<em>sleep<\/em>(3000);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"The page title is: \" +driver.getTitle());\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 }\n\u00a0\u00a0 @Test(dataProvider=\"destinations\")\n\u00a0\u00a0 <strong>public<\/strong> <strong>void<\/strong> intlDestinations(String location) <strong>throws<\/strong> InterruptedException{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebElement searchBox=driver.findElement(By.<em>name<\/em>(\"q\"));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 searchBox.sendKeys(location);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"You are trying to search : \" +location);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebElement srchBtn = driver.findElement(By.<em>name<\/em>(\"btnK\"));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 srchBtn.submit();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Thread.<em>sleep<\/em>(3000);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"The page title is: \" +driver.getTitle()); \u00a0\n\u00a0\u00a0 }\n\u00a0\u00a0 @DataProvider(name=\"destinations\")\n\u00a0\u00a0 \u00a0 <strong>public<\/strong> Object&#91;]&#91;] getDataProviderData(Method m){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>if<\/strong>(m.getName().equalsIgnoreCase(\"domesticMonuments\")){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>return<\/strong> <strong>new<\/strong> Object&#91;]&#91;]{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { \"Gate Way of India\", \"Mumbai\" },\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { \"Konark Sun Temple\", \"Konark\" },\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { \"Statue of Unity\", \"Gujarat\" }\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 };\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>else<\/strong>{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>return<\/strong> <strong>new<\/strong> Object&#91;]&#91;]{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\"London\"},\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\"Australia\"},\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\"Dallas\"}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 };\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } \u00a0\n\u00a0\u00a0 \u00a0 }\n\n}<\/code><\/pre>\n\n\n\n<p><strong>Step 2:<\/strong> Create a TestNG.xml file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=<em>\"1.0\"<\/em> encoding=<em>\"UTF-8\"<\/em>?>\n&lt;!DOCTYPE suite SYSTEM \"http:\/\/testng.org\/testng-1.0.dtd\">\n&lt;suite name=<em>\"Suite\"<\/em> >\n\u00a0\u00a0&lt;test name=<em>\"Firefox Test\"<\/em>>\n\u00a0\u00a0\u00a0 &lt;classes>\n\u00a0\u00a0 &lt;class name=<em>\"dataprovider.dataProviders\"<\/em>\/>\n&lt;\/classes>\n\u00a0\u00a0&lt;\/test>\n\u00a0\u00a0&lt;\/suite><\/code><\/pre>\n\n\n\n<p>When you run the above TestNG.xml file you will be able to see the details of the data providers used.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/IrCn9Ez7ik4Tnu1sVvGAMSvD1ICo26oUxEIR_6tWL9T2hnKtbwV5QjjJT_pYpJJUe0h21y5jdiNxz9STpz9cI_fWnrUBpNpqj917wFyJ2rCEv32qiFGCp5OmTJ3pikkpjT9Xwkw0QA_5pQrDtw\" alt=\"Method.PNG\" title=\"\"><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/sYkR9h8BSFGs7wDtRmlvkMaXbESNihWSdNt237g1oFarG-w2ASZoirfhWgJtpKU_7c3jLf8zSGJ7h-Ixmlk4cZRAyG_nacAmiA33_ekU_amOj_or2eqXFPzWViNqo5GhwAkGfmahk2RBAZ_EKg\" alt=\"method1.PNG\" title=\"\"><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/-TcCiiFZ6APFgut_i6qrOo2qou2rkn6keCBKObQnuW39Lt7Do-fg4qf2o_DZM3dnhvPpAb8lY7yjIYXkj0TwI6M-D2kJUWn07K835pw3jMybSDhrsk-GBPOoEFXSNUQjGJd85xX7sM6eVzVagA\" alt=\"destinations.PNG\" title=\"\"><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example 2: Using ITestContext Parameter in TestNG<\/strong><\/h3>\n\n\n\n<p>Suppose my test methods are assigned to different groups and I need to use different test data for different groups. In such scenario we can use&nbsp;<strong>ITestContext<\/strong>&nbsp;parameter with our Data Provider annotation.&nbsp;<\/p>\n\n\n\n<p>Let us consider the below example.<\/p>\n\n\n\n<p><strong>Java Code:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> dataprovider;\n\n<strong>import<\/strong> org.openqa.selenium.By;\n<strong>import<\/strong> org.openqa.selenium.WebDriver;\n<strong>import<\/strong> org.openqa.selenium.WebElement;\n<strong>import<\/strong> org.openqa.selenium.firefox.FirefoxDriver;\n<strong>import<\/strong> org.testng.ITestContext;\n<strong>import<\/strong> org.testng.annotations.AfterMethod;\n<strong>import<\/strong> org.testng.annotations.BeforeMethod;\n<strong>import<\/strong> org.testng.annotations.DataProvider;\n<strong>import<\/strong> org.testng.annotations.Test;\n\n<strong>public<\/strong> <strong>class<\/strong> ITestContext_DataProvider {\nWebDriver driver;\n\u00a0\u00a0 @BeforeMethod(groups={\"One\",\"Two\"})\n\u00a0\u00a0 <strong>public<\/strong> <strong>void<\/strong> setUp(){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Initializing Driver\nSystem.<em>setProperty<\/em>(\"webdriver.gecko.driver\",\"F:\\\\drivers\\\\geckodriver.exe\");\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver = <strong>new<\/strong> FirefoxDriver();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Opening search engine\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.get(\"https:\/\/google.com\");\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n\u00a0\u00a0 @AfterMethod(groups={\"One\",\"Two\"})\n\u00a0\u00a0 <strong>public<\/strong> <strong>void<\/strong> tearDown(){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.quit();\n\u00a0\u00a0 }\n\u00a0\u00a0\n\u00a0\u00a0 @Test(dataProvider=\"searchKey\" , groups=\"One\")\n\u00a0\u00a0 <strong>public<\/strong> <strong>void<\/strong> testMethodOne(String monument,String city) <strong>throws<\/strong> InterruptedException{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebElement searchBox=driver.findElement(By.<em>name<\/em>(\"q\"));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 searchBox.sendKeys(monument +\" \"+city);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"You are trying to search \" +monument+ \" which is in \" +city);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebElement srchBtn = driver.findElement(By.<em>name<\/em>(\"btnK\"));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 srchBtn.submit();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Thread.<em>sleep<\/em>(3000);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"The page title is: \" +driver.getTitle());\n\u00a0\u00a0 }\n\u00a0\u00a0 @Test(dataProvider=\"searchKey\" , groups=\"Two\")\n\u00a0\u00a0 <strong>public<\/strong> <strong>void<\/strong> testMethodTwo(String location) <strong>throws<\/strong> InterruptedException{\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebElement searchBox=driver.findElement(By.<em>name<\/em>(\"q\"));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 searchBox.sendKeys(location);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"You are trying to search : \" +location);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebElement srchBtn = driver.findElement(By.<em>name<\/em>(\"btnK\"));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 srchBtn.submit();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Thread.<em>sleep<\/em>(3000);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(\"The page title is: \" +driver.getTitle()); \u00a0\n\u00a0\u00a0 }\n\u00a0\u00a0 @DataProvider(name=\"searchKey\")\n\u00a0\u00a0 \u00a0 <strong>public<\/strong> Object&#91;]&#91;] getDataProviderData(ITestContext c){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Object&#91;]&#91;] grpArr = <strong>null<\/strong>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>for<\/strong> (String grp : c.getIncludedGroups()){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>if<\/strong>(grp.equalsIgnoreCase(\"One\")){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 grpArr = <strong>new<\/strong> Object&#91;]&#91;]{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { \"Gate Way of India\", \"Mumbai\" },\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { \"Konark Sun Temple\", \"Konark\" },\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { \"Statue of Unity\", \"Gujarat\" }\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 };\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>break<\/strong>;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>else<\/strong> <strong>if<\/strong>(grp.equalsIgnoreCase(\"Two\")){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 grpArr = <strong>new<\/strong> Object&#91;]&#91;]{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\"London\"},\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\"Australia\"},\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\"Dallas\"}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0};\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>return<\/strong> grpArr;\u00a0\n\u00a0\u00a0 \u00a0 }\n}<\/code><\/pre>\n\n\n\n<p><strong>Create a TestNG.xml file<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=<em>\"1.0\"<\/em> encoding=<em>\"UTF-8\"<\/em>?>\n&lt;suite name=<em>\"Suite\"<\/em> >\n\u00a0\u00a0&lt;test name=<em>\"First DP Run\"<\/em>>\n\u00a0\u00a0\u00a0 &lt;groups>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;run>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;include name = <em>\"One\"<\/em> \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/run>\n\u00a0\u00a0 &lt;\/groups>\n\u00a0\u00a0\u00a0 &lt;classes>\n\u00a0\u00a0 &lt;class name=<em>\"dataprovider.ITestContext_DataProvider\"<\/em>\/>\n&lt;\/classes>\n\u00a0\u00a0&lt;\/test>\n\u00a0\u00a0&lt;test name=<em>\"Second DP Run\"<\/em>>\n\u00a0\u00a0\u00a0 &lt;groups>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;run>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;include name = <em>\"Two\"<\/em> \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/run>\n\u00a0\u00a0 &lt;\/groups>\n\u00a0\u00a0\u00a0 &lt;classes>\n\u00a0\u00a0 &lt;class name=<em>\"dataprovider.ITestContext_DataProvider\"<\/em>\/>\n&lt;\/classes>\n\u00a0\u00a0&lt;\/test>\u00a0\n\u00a0&lt;\/suite><\/code><\/pre>\n\n\n\n<p>After running the above xml file you will get the results like below:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/GC0B14z-Rx5edc9uZR4knGWsX1-s-IEcxrQ1xIX0ImAFI77ZtOFFyXBMAnz3hZz-T_IP8UZd2V2IC6KAZA-WzJMUMrPcVxIJRAVw8ds5LYPYeMBZEN1syz3HELtKYCvBF6lHJZmjGuhNQsqQJA\" alt=\"dallas.PNG\" title=\"\"><\/figure>\n\n\n\n<p><strong>Conclusion<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>We require Parameterization<\/strong> to create\u00a0<strong>Data Driven Testing<\/strong>.<\/li>\n\n\n\n<li>TestNG support two types of parameterization, using\u00a0<strong>@Parameter+TestNG.xml<\/strong>\u00a0and using<strong>@DataProvider<\/strong><\/li>\n\n\n\n<li>In<strong>\u00a0@Parameter+TestNG.xml\u00a0<\/strong>parameters can be placed in suite level and test level. If the same parameter name is declared in both places; first we will get preference to the test level parameter over suit level parameter.<\/li>\n\n\n\n<li>Only one value can be set at a time by using @Parameter+TestNG.xml, but @DataProvider return\u00a0<strong>the 2nd array of Object<\/strong>.<\/li>\n\n\n\n<li>If DataProvider is present in a different class then the class where the test method resides, <strong>DataProvider<\/strong>\u00a0should be\u00a0a <strong>static method<\/strong>.<\/li>\n<\/ul>\n\n\n\n<p>There are two types of parameters supported by&nbsp;<strong>DataProvider<\/strong>&nbsp;i.e.<strong> Method<\/strong>&nbsp;and&nbsp;<strong>ITestContext.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When we create any software, we create it in a way that it should work differently with a different set of data. When it comes to testing the same created software, we can\u2019t test it just with one set of data. Here, we need to verify our created software with all the combinations that it [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":3881,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[156,284,1042,1888,1041,448,974,1040],"class_list":["post-3844","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-selenium-tutorials","tag-automation-testing","tag-data-driven-testing","tag-data-provide","tag-parameterization","tag-parameterization-in-selenium","tag-selenium-webdriver","tag-testng","tag-testng-xml"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/3844","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=3844"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/3844\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/3881"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=3844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=3844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=3844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}