Exit course
Chapter 11 of 11 Intermediate 6 min read Updated

Knowledge check

Ten questions on the decisions this course made and why; each answer explains the reasoning once you check.

1. A teammate's README says to download chromedriver and set webdriver.chrome.driver before running the suite on Selenium 4.52. What is the best advice?

Since Selenium 4.6, Selenium Manager finds or downloads the right driver automatically. A manually placed driver takes precedence and is the usual cause of "this version of ChromeDriver only supports Chrome version N".

2. You upgrade maven-surefire-plugin from 3.5.6 to 3.6.1 and mvn test now stops before running anything. Why?

From 3.6.0 all frameworks run through the JUnit Platform and suiteXmlFiles is rejected. Either stay on 3.5.x or replace suite files with groups and includes.

3. Every test method in a <test> block is unexpectedly sharing one browser. Where was the driver most likely created?

@BeforeTest runs once per <test> tag in testng.xml, not per test method. Per-test browsers belong in @BeforeMethod.

4. You run mvn test -Dgroups=smoke and every smoke test fails with a NullPointerException on the driver. What is the fix?

With a group filter, configuration methods that are not in that group are skipped unless they declare alwaysRun = true, so the driver is never created.

5. A test calls Assert.assertEquals("Received!", message.getText()) and fails with "expected [Error] but found [Received!]". What happened?

TestNG's signature is assertEquals(actual, expected). Passing them JUnit-style still fails at the right time but produces a misleading message.

6. A test creates a SoftAssert, makes five checks, three of which fail, and the test passes. What is missing?

SoftAssert only records failures. assertAll() is what throws them; without it they are discarded and the test passes.

7. You set parallel = true on a data provider while the base class still keeps the driver in a plain instance field. What do you expect?

All invocations of a data-driven test use the same instance. Without a ThreadLocal<WebDriver>, threads replace and quit each other's browsers.

8. Your suite has thread-count="3" and a parallel data provider with 20 rows, yet far more than 3 browsers open at once. Why?

The suite pool (3) and the data provider pool (default 10) are independent. Set data-provider-thread-count explicitly when browsers are a limited resource.

9. Your screenshot listener runs in onTestFailure, and the driver is quit in @AfterMethod. Does the screenshot show the failing page?

With TestNG 7.12, onTestFailure runs on the test's thread before teardown, so BaseTest.driver() still returns the live session. Where the listener is registered does not change the order.

10. On a remote grid, a test fails on an assertion but the grid's dashboard shows the session as completed without a failure. Why, and what fixes it?

Assertions run in your JVM. The grid can only know the outcome if you send it, which the final BaseTest does in @AfterMethod using ITestResult.isSuccess().

Where to go next#

Your suite now has one browser per test, safe parallelism, screenshots on failure and a switch to run on a grid. The next step is structure: once several tests touch the same pages, move locators and page interactions into page objects, which the Page Object Model course builds on top of a project like this one. If you are preparing for a job interview, the test automation interview questions course has a chapter on TestNG questions. For the reference version of the grid setup, keep the TestNG documentation at hand.

You finished Selenium Java Tutorial with TestNG

Put what you learned into practice. Run your tests on 6100+ real browsers and physical iOS and Android devices.