Time to practice. Build a complete TestNG test suite for the Shopping Portal. Follow these exercises in order — each one builds on the previous:
Exercises
Exercise 1 — Create BaseTest: Write a BaseTest class with ThreadLocal<WebDriver>. @BeforeMethod launches Chrome and navigates to /shopping. @AfterMethod calls quit() and removes the ThreadLocal.
Exercise 2 — Home Page Smoke Test: Create ShoppingHomeTest extending BaseTest. Write testHomePageLoads() — verify the page title and that at least one product card is visible. Use SoftAssert. Tag it as "smoke."
Exercise 3 — Product Search: Write testSearchReturnsResults() — search for "Laptop" and verify at least one result appears. Use explicit wait. Tag it as "smoke."
Exercise 4 — Data-Driven Search: Create a DataProvider with 3 search terms (one that returns results, one that returns many, one that returns zero). Write testSearchWithData() using this DataProvider. Tag it as "regression."
Exercise 5 — Cart Test: Write testAddToCart() — search for a product, add it to cart, verify the cart count increases. Use Hard Assert for adding to cart, Soft Assert for verifying cart details.
Exercise 6 — Create testng.xml: Write a testng.xml that runs your Shopping tests. Include a "smoke" group run and a listener.
Exercise 7 — Parallel Run: Modify testng.xml to run Banking and Shopping tests in parallel with thread-count="2". Verify both modules run simultaneously.
Start with Exercise 1 and do not skip ahead. Each exercise builds on the previous one. By the end, you will have a complete, professional-quality test suite that you can show in interviews.