Theory without practice is useless. Here are 4 exercises that cover everything from this chapter. Do them in order — each builds on the previous one.
Exercise 1: CSV-Driven Shopping Search
Create a CSV file with at least 8 search terms for the Shopping Portal. Include valid products (laptop, headphones), invalid terms (xyznoexist), empty string, special characters (<script>), and case variations (LAPTOP). Write a DataProvider that reads the CSV. Write a test that searches each term on the Shopping Portal and verifies the results.
Create test-data/shopping-search.csv with columns: searchTerm, expectResults, minCount
Write a DataProvider method that reads this CSV using BufferedReader
Write testShoppingSearch() that navigates to /shopping and searches each term
Assert that valid terms return results and invalid terms show "no results"
Run the test and verify all 8 data sets execute
Exercise 2: Excel-Driven Insurance Quote
Create an Excel file with insurance quote scenarios. Include different age groups, coverage amounts, and expected premium ranges. Use ExcelUtils to read the data. Test the PolicyDekho quote calculator at /insurance.
Create test-data/insurance-quotes.xlsx with a sheet named "QuoteScenarios"
Add at least 6 rows with different scenarios (young/old, low/high coverage)
Write a DataProvider using ExcelUtils.readSheet()
Write testInsuranceQuote() that fills the quote form and verifies the premium is within range
Exercise 3: JSON-Driven Banking Transfer
Create a JSON file with banking transfer scenarios. Use nested objects for account details. Include success cases, insufficient balance, invalid account, and negative amount. Parse with Jackson ObjectMapper.
Create test-data/banking-transfers.json with nested fromAccount and toAccount objects
Include at least 5 scenarios: valid transfer, insufficient funds, invalid account, negative amount, zero amount
Write a DataProvider that reads JSON and flattens nested objects into Object[][] parameters
Write testBankingTransfer() that performs each transfer and asserts success or failure
Exercise 4: ConfigReader + Cross-Browser
Build a ConfigReader that loads config.properties with System property overrides. Create two testng.xml files — one for Chrome and one for Firefox. Run the same Banking login test on both browsers using @Parameters.
Create config.properties with base.url, browser, headless, and timeout settings
Build ConfigReader with get(), getInt(), getBoolean() methods and System property override
Create BaseTest that uses ConfigReader for setup and @Parameters for browser override
Create testng-chrome.xml and testng-firefox.xml with different browser parameters
Run: mvn test -DsuiteXmlFile=testng-chrome.xml and verify Chrome launches
Run: mvn test -DsuiteXmlFile=testng-firefox.xml and verify Firefox launches
Start with Exercise 1 (CSV search) — it is the simplest. Once comfortable, move to Excel and JSON. Exercise 4 ties everything together with configuration management.