Bird
0
0

How can you modify a DataProvider to supply data from an external CSV file for parameterized tests?

hard📝 framework Q8 of 15
Selenium Java - TestNG Integration
How can you modify a DataProvider to supply data from an external CSV file for parameterized tests?
ARead CSV in DataProvider method and return Object[][] with parsed data
BUse @DataProvider(file = "data.csv") annotation parameter
CPlace CSV file in test resources and annotate test with @CsvSource
DDataProvider cannot read external files
Step-by-Step Solution
Solution:
  1. Step 1: Understand DataProvider flexibility

    DataProvider methods can contain any Java code, including reading files and preparing data arrays.
  2. Step 2: Identify correct approach for CSV data

    Reading the CSV file inside the DataProvider method and returning Object[][] with parsed data is the correct way.
  3. Final Answer:

    Read CSV in DataProvider method and return Object[][] with parsed data -> Option A
  4. Quick Check:

    DataProvider can read files and return data arrays [OK]
Quick Trick: Read external data inside DataProvider method [OK]
Common Mistakes:
MISTAKES
  • Assuming @DataProvider supports file parameter
  • Confusing with @CsvSource (not in Selenium)
  • Believing DataProvider cannot read files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes