How to run JUnit Parameterized Test in Selenium
On This Page What Are JUnit Parameterized Tests in Selenium?June 26, 2026 · 10 min read · Tool Comparison
In Selenium, executing the same trial with multiple inputs oftentimes results in code duplication and care overhead. JUnit Parameterized Tests helps overcome this by dynamically injecting test information, cut redundancy. JUnit Parameterized Tests in Selenium JUnit Parameterized Tests in Selenium is a quiz access that lets you run the same test multiple times with various sets of input data. This way you can minimize code duplication and streamline tests. Why Use JUnit Parameterized Tests in Selenium? JUnit Parameterized Tests in Selenium is a testing approach that lets you run the same test multiple clip with diverse sets of stimulus data. This way you can minimize code duplication and streamline tests. To achieve parameterization in, we can always use spreadsheet / to hold data, read it in the automation script and perform read and write functions. However, loading such huge file to act with a small information set would be time-consuming as it takes considerable time to load while executing Selenium hand. JUnit parameterization comes to rescue against this trouble, providing various inbuiltcontroversy sourcesfor parameterized tests. Apart from this key benefit, JUnit Parameterized Test also volunteer various other advantages like: Also Read: JUnit5 Parameterized Test helps to run the like test multiple times with different arguments/values. They are announce just like the veritable @ Test method but instead of @ Test annotation @ ParameterizedTest is used. All supported argument sources are configured utilize annotations from theorg.junit.jupiter.params.provider package. Adding JUnit5 Dependencies If it is a Maven undertaking, we need to addjunit-jupiter-paramsdependency under & lt; colony & gt; tag in pom.xml along withjunit-jupiter-engineandjunit-platform-launcher. Make sure to use Java version 8 or above and add JUnit5 library to the project build path before go with the program. Here are the four popular JUnit 5 JUnit5 Argument Sources: For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users. Read More: How to compose Parameterized Test in JUnit5: Example: Let us enforce all four argument sources in a to validate search event in Google. In the below programme, 3 values are passed as search data via@ ValueSourceto the trial methodtestSearch (). Later, it is asserted via the JUnit5 Assertions class that the page title contains the string value passed. testSearch () method is parametrized with the@ ParameterizedTest and @ ValueSourceannotation. JUnit5 exam runner executestestSearch ()method three times, each time assigning different values from the@ ValueSource array. This means Google Chrome will launch three times, and each time it will search with 3 different datum and asseverate it too. JUnit5 exam runner executestestSearch ()method three times, each time assigning different value from the@ EnumSourceraiment which is enumSearchData The assertion will fail as we hold maintain that the page title is adequate to the string value passed which is not true. If we want to specify the enum value that are passed to our test method, we can specify the enum values by setting the value of the@ EnumSourceannotation & # 8217; s names attribute. This time JUnit5 test runner will run the testSearch method only once with value as “ JUnit5 ” and ignoring early 2 values. Also Read: JUnit5 tryout contrabandist executestestSearch ()method 3 times, each time assigning 2 argument values from the@ CsvSource array. JUnit5 test contrabandist executestestSearch ()method 3 clip, each time assigning 3 argument values from the@ CsvFileSource array. Read More: Here are some better practices to follow while using parameterized tests in Selenium: In this article, we hold con what parameterization is and why it is necessary to implement that in any automation model. We also hear how to create parameterized tests in Selenium script using various JUnit5 argument sources. Refer to the to hear more about executing JUnit 5 Tests on Real device With likewise coming into the picture, instead of running tests sequentially, opt for for simultaneous test execution. By running JUnit Tests on of multiple real browser-device combinations simultaneously, important time and effort can be reduced. # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.How to run JUnit Parameterized Test in Selenium
Overview
What Are JUnit Parameterized Tests in Selenium?
Benefits of JUnit Parameterized Test
How to Run JUnit5 Parameterized Test in Selenium?
& lt; dependencies & gt; & lt; dependency & gt; & lt; groupId & gt; org.seleniumhq.selenium & lt; /groupId & gt; & lt; artifactId & gt; selenium-java & lt; /artifactId & gt; & lt; version & gt; 4.3.0 & lt; /version & gt; & lt; /dependency & gt; & lt; dependency & gt; & lt; groupId & gt; io.github.bonigarcia & lt; /groupId & gt; & lt; artifactId & gt; webdrivermanager & lt; /artifactId & gt; & lt; version & gt; 5.2.1 & lt; /version & gt; & lt; /dependency & gt; & lt; dependency & gt; & lt; groupId & gt; org.junit.jupiter & lt; /groupId & gt; & lt; artifactId & gt; junit-jupiter-engine & lt; /artifactId & gt; & lt; version & gt; 5.9.0 & lt; /version & gt; & lt; scope & gt; test & lt; /scope & gt; & lt; /dependency & gt; & lt; dependency & gt; & lt; groupId & gt; org.junit.platform & lt; /groupId & gt; & lt; artifactId & gt; junit-platform-launcher & lt; /artifactId & gt; & lt; version & gt; 1.7.0 & lt; /version & gt; & lt; scope & gt; test & lt; /scope & gt; & lt; /dependency & gt; & lt; dependency & gt; & lt; groupId & gt; org.junit.jupiter & lt; /groupId & gt; & lt; artifactId & gt; junit-jupiter-params & lt; /artifactId & gt; & lt; version & gt; 5.9.0 & lt; /version & gt; & lt; scope & gt; test & lt; /scope & gt; & lt; /dependency & gt; & lt; /dependencies & gt;
Four widely used JUnit5 Argument Sources
@ DisplayName (`` Verifying lookup functionality in Google. Search data is fetched from @ ValueSource '') @ ParameterizedTest (name = `` index= & gt; str= '' {0} '' '') @ ValueSource (strings = {`` Selenium '', `` JUnit4 '', `` JUnit5 ''}) void testSearch (String str) {srchBox.sendKeys (str + '' \n ''); // Printing the title of the Search page String title = driver.getTitle (); System.out.println (`` The title is: `` + title); Assertions.assertTrue (title.contains (str)); driver.close ();}@ ValueSource
significance org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; significance org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import io.github.bonigarcia.wdm.WebDriverManager; @ DisplayName (`` Pass the method argument render by the @ ValueSource annotation '') class ValueSourceTest {WebDriver driver; WebElement srchBox; @ BeforeEach public emptiness init () {WebDriverManager.chromedriver () .setup (); driver = new ChromeDriver (); driver.get (`` https: //www.google.com/ ''); driver.manage () .window () .maximize (); System.out.println (`` Search start now ''); //Search string in google srchBox= driver.findElement (By.cssSelector (`` input.gLFyf ''));} @ DisplayName (`` Verifying search functionality in Google. Search data is fetched from @ ValueSource '') @ ParameterizedTest (name = `` index= & gt; str= '' {0} '' '') @ ValueSource (twine = {`` Selenium '', `` JUnit4 '', `` JUnit5 ''}) void testSearch (String str) {srchBox.sendKeys (str + '' \n ''); // Printing the rubric of the Search page String rubric = driver.getTitle (); System.out.println (`` The title is: `` + title); Assertions.assertTrue (title.contains (str)); driver.close ();}}@ EnumSource
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; signification org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import io.github.bonigarcia.wdm.WebDriverManager; @ DisplayName (`` Pass the method parameters render by the @ EnumSource annotation '') public category EnumSourceTest {WebDriver driver; WebElement srchBox; enum SearchData {Selenium, JUnit4, JUnit5;} @ BeforeEach public void init () {WebDriverManager.chromedriver () .setup (); driver = new ChromeDriver (); driver.get (`` https: //www.google.com/ ''); driver.manage () .window () .maximize (); System.out.println (`` Search begins now ''); //Search in goole srchBox= driver.findElement (By.cssSelector (`` input.gLFyf ''));} @ DisplayName (`` Verifying hunting functionality in Google. Search information is get from @ EnumSource '') @ ParameterizedTest (gens = `` index= & gt; data= '' {0} '' '') @ EnumSource (SearchData.class) void testSearch (Object data) {srchBox.sendKeys (data + '' \n ''); // Printing the title of the new page String title = driver.getTitle (); System.out.println (`` The title is: `` + rubric); Assertions.assertTrue (title.equals (data)); driver.close ();}}Assertions.assertTrue (title.equals (data));
@ DisplayName (`` Verifying hunt functionality in Google. Search information is fetched from @ EnumSource '') @ ParameterizedTest (name = `` index= & gt; data= '' {0} '' '') @ EnumSource (value=SearchData.class, names = {`` JUnit5 ''}) void testSearch (Object data) {srchBox.sendKeys (data + '' \n ''); // Printing the rubric of the new page String title = driver.getTitle (); System.out.println (`` The title is: `` + title); Assertions.assertTrue (title.equals (data)); driver.close ();}@ CsvSource
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; importation org.junit.jupiter.params.provider.CsvSource; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; meaning org.openqa.selenium.WebElement; significance org.openqa.selenium.chrome.ChromeDriver; import io.github.bonigarcia.wdm.WebDriverManager; @ DisplayName (`` Pass the method parameters provided by the @ CsvSource annotation '') public class CSVSourceTest {WebDriver driver; WebElement srchBox; @ BeforeEach public vacuum init () {WebDriverManager.chromedriver () .setup (); driver = new ChromeDriver (); driver.get (`` https: //www.google.com/ ''); driver.manage () .window () .maximize (); System.out.println (`` Search begins now ''); //Search in goole srchBox= driver.findElement (By.cssSelector (`` input.gLFyf ''));} @ DisplayName (`` Verifying search functionality in Google. Search data is fetched from @ CsvSource '') @ ParameterizedTest (gens = `` index= & gt; str1= '' {0} '', str2= '' {1} '' '') @ CsvSource ({'' Selenium, Testing '', '' JUnit4, Testing '', '' JUnit5, Testing '',}) void testSearch (String str1, String str2) {srchBox.sendKeys (str1 + str2 + '' \n ''); // Printing the title of the new page String title = driver.getTitle (); System.out.println (`` The title is: `` + title); Assertions.assertTrue (title.contains (str1)); driver.close ();}}@ CsvFileSource
import org.junit.jupiter.api.Assertions; spell org.junit.jupiter.api.BeforeEach; importation org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvFileSource; import org.openqa.selenium.By; significance org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import io.github.bonigarcia.wdm.WebDriverManager; @ DisplayName (`` Pass the method parameters cater by the @ CsvFileSource annotation '') public class CSVFileSourceTest {WebDriver driver; WebElement srchBox; @ BeforeEach public vacuum init () {WebDriverManager.chromedriver () .setup (); driver = new ChromeDriver (); driver.get (`` https: //www.google.com/ ''); driver.manage () .window () .maximize (); System.out.println (`` Search begins now ''); //Search in goole srchBox= driver.findElement (By.cssSelector (`` input.gLFyf ''));} @ DisplayName (`` Verifying search functionality in Google. Search data is fetched from @ CsvFileSource '') @ ParameterizedTest (gens = `` index= & gt; str1= '' {0} '', str2= '' {1} '', str3= '' {2} '' '') @ CsvFileSource (resources = `` /testdata.csv '') void testSearch (String str1, String str2, String str3) {srchBox.sendKeys (str1 + str2 +str3+ '' \n ''); // Printing the title of the new page String rubric = driver.getTitle (); System.out.println (`` The title is: `` + title); Assertions.assertTrue (title.contains (str1)); driver.close ();}}Best Practices for Using Parameterized Tests in Selenium
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously