Master Parameterization and Data-Driven Testing in Selenium with these 30 MCQs. Learn to read data from Excel/CSV, use Data Providers in TestNG, and efficiently parameterize tests for dynamic execution.
1. Reading Data from Excel/CSV
Which library is commonly used to read data from Excel in Selenium?
a) Apache POI
b) JUnit
c) TestNG
d) WebDriverManager
What is the primary purpose of data-driven testing in Selenium?
a) To simplify test case writing
b) To execute tests with multiple data sets
c) To reduce manual testing
d) To automate UI elements
In Apache POI, which class is used to open an Excel workbook?
a) WorkbookFactory
b) FileReader
c) WorkbookLoader
d) ExcelParser
How do you retrieve the value of a specific cell in an Excel sheet using Apache POI?
a) row.getCell(index).getValue()
b) sheet.getCellValue(row, column)
c) row.getCell(index).toString()
d) row.get(index).getData()
Which method is used to close the workbook in Apache POI?
a) workbook.close()
b) workbook.finish()
c) workbook.end()
d) workbook.terminate()
What is the default delimiter for a CSV file?
a) Semicolon (;)
b) Comma (,)
c) Tab (\t)
d) Pipe (|)
Which Java library is commonly used to read and write CSV files?
a) OpenCSV
b) JExcelAPI
c) Apache Commons IO
d) Selenium WebDriver
What is a common way to load CSV data into a Selenium test?
a) Using BufferedReader to read the file line by line
b) Using FileInputStream to load the entire file
c) Using HashMap to store data
d) Using ExcelDataProvider
In OpenCSV, which class is used to parse CSV files?
a) CSVParser
b) CSVReader
c) FileReader
d) CSVDataLoader
Which of the following can cause errors when reading a CSV file?
a) Missing headers
b) Malformed rows
c) Incorrect delimiters
d) All of the above
2. Data Providers in TestNG
What is the purpose of the @DataProvider annotation in TestNG?
a) To manage test configurations
b) To supply data to test methods
c) To validate test results
d) To handle exceptions
What is the return type of a @DataProvider method?
a) List<Object[]>
b) Object[][]
c) Map<Object, Object>
d) Set<Object[]>
How do you associate a test method with a @DataProvider in TestNG?
a) Use the dataProvider attribute in the @Test annotation
b) Use the @DataSource annotation
c) Call the @DataProvider method directly
d) Pass it as a parameter to the test class
How can you provide a name for a @DataProvider in TestNG?
a) Using the name attribute in the @DataProvider annotation
b) Using the @DataSource annotation
c) Using the value attribute in the test method
d) Using the testName attribute
Can you use multiple @DataProvider methods in a single TestNG class?
a) Yes
b) No
c) Only if they have different names
d) Only with XML configuration
What happens if a test method has no associated data from the @DataProvider?
a) It will skip execution
b) It will run with default values
c) It will throw an error
d) It will pass automatically
Which of the following is a valid @DataProvider example?
a)javaCopy code@DataProvider public Object[][] getData() { return new Object[][] { {"data1"}, {"data2"} }; }
b)javaCopy code@DataProvider public String[] getData() { return {"data1", "data2"}; }