Why a Test Framework

main() Is Not Enough

So far tests were main() methods printing PASS or FAIL. Real suites need much more:

NeedTestNG gives
many tests in one run@Test methods, run with mvn test
open/close browser for each test@BeforeMethod / @AfterMethod
real pass/fail with messagesAssert.assertEquals(...)
run only smoke testsgroups, testng.xml
same test with 20 data rows@DataProvider (next module)
parallel runs, reports, retriesparallel attribute, HTML reports, listeners

Note: JUnit 5 is the other popular choice (@Test, @BeforeEach, @ParameterizedTest). Selenium teams in India mostly use TestNG, so this course uses it.

Add TestNG to pom.xml

<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>7.10.2</version>
  <scope>test</scope>
</dependency>

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>3.5.1</version>
      <configuration>
        <suiteXmlFiles><suiteXmlFile>testng.xml</suiteXmlFile></suiteXmlFiles>
      </configuration>
    </plugin>
  </plugins>
</build>