Video summary

Session 42 - Selenium with Java | TestNG Integration & Setup | @Test annotation

Main summary

Key takeaways

Technology

What TestNG is (and why integrate with Selenium)

  • TestNG is introduced as a Java-based unit testing framework (“test new generation”).
  • It’s designed for writing test cases at the code/method level.
  • Compared to Selenium WebDriver (which focuses on web automation), Selenium alone doesn’t offer complete test management capabilities.

By integrating TestNG + Selenium, you gain:

  • Test case & test suite organization
  • Grouping / selective execution (e.g., sanity, regression, UI—conceptually mentioned)
  • Prioritization of test methods
  • Parameterization (pass browser/app URL/env data at runtime)
  • Parallel testing (including multiple browsers, using TestNG features)
  • Report generation
    • TestNG provides built-in reports
    • The plan is also to use ExtentReports for improved reporting
  • A cleaner automation structure than placing everything inside main()

Selenium scope vs TestNG scope

  • Selenium WebDriver
    • Interacts with web elements and performs validations.
  • TestNG
    • Manages how tests are executed and reported (order, grouping, parallelism, parameters, etc.).

Eclipse + Project Setup (Installation & Configuration)

Mandatory steps

  1. Install the TestNG plugin in Eclipse

    • Go to: Help > Eclipse Marketplace
    • Search for: “TestNG for Eclipse”
    • Install, accept the license, and restart Eclipse.
    • Verify: Window > Preferences should show a TestNG section/plugin option.
  2. Associate TestNG with the current project

    • Option A (recommended for IDE)
      • Right-click project → Properties > Java Build Path > Libraries > Add Library > TestNG
    • Option B (Maven dependency)
      • Add a testng dependency in pom.xml (version referenced around “7.1.0” in the transcript).

Recommendation: Use both IDE association (Eclipse library) and the Maven dependency to avoid issues when running outside Eclipse.


Writing Tests in “TestNG style” (no main())

Core concept: @Test replaces main() execution

  • In TestNG, test classes do not use a Java main() method.
  • Execution is driven by methods annotated with @Test.
  • The tutorial focuses on creating methods like:
    • openApp()
    • login()
    • logout()
  • Each method is annotated with @Test and requires importing it from:
    • org.testng.annotations

How TestNG executes methods by default (important)

  • Default execution order: alphabetical order of method names (not the order written in code).
  • To control execution, use priority in @Test(priority = X).

Priority rules (key points)

  1. If priority is not specified, TestNG runs methods in alphabetical order.
  2. If you set priority, TestNG uses priority value as the main ordering rule.
  3. Once priority is set, the order of methods in the code does not matter.
  4. Priority numbers do not need to be consecutive (they can be any values).
  5. Priority numbers can be random.
  6. If two methods share the same priority, TestNG falls back to alphabetical order.
  7. Negative priority values are allowed (TestNG runs the lowest number first).
  8. Default priority when priority is omitted is 0.
  9. TestNG executes only methods annotated with @Test.
    • If no methods have @Test, it reports: “No tests were found”.

Example Test Workflow (Selenium + TestNG integration)

A conceptual OrangeHRM scenario is used:

  • Open application
  • Verify logo presence
  • Login using username/password
  • Close application

Key coding guidance:

  • WebDriver scope

    • If WebDriver driver = new ChromeDriver() is created as a local variable inside openApp(), other @Test methods won’t be able to access it.

    • The WebDriver must be a class-level variable shared across test methods.

    • Use driver.get(URL) inside openApp().
    • Validate logo using:
    • driver.findElement(...).isDisplayed()
    • Use sendKeys() and click() for login actions.

Execution is demonstrated using “Run as TestNG Test.”


Running Tests with testng.xml (Test suite execution + reports)

Why XML matters

The speaker emphasizes that many TestNG features—especially running multiple suites/classes and producing suite-level reports—are typically driven via testng.xml.

Benefits:

  1. Run single or multiple test classes in one run
  2. Automatically generate TestNG reports in the test-output folder

How to create/run XML

Automatic generation

  • Right-click test/package → TestNG > Convert to TestNG
  • This generates a testng.xml template.
    • The speaker notes Eclipse may require a workaround/forced download link if external resources are disabled.

Manual creation

  • Create an empty .xml file and include a base template structure such as:
    • <suite name="...">
    • <test name="...">
    • <classes>
    • <class name="package.ClassName"/>

Execution

  • Use: “Run as TestNG suite” for XML-based runs.

Reports produced only when using XML

Reports appear under test-output/, typically including:

  • emailable report (HTML)
  • index.html (HTML report)

These include:

  • pass/fail counts
  • exception details
  • chronological execution view (order + timing)

Note: You may need to refresh the project to see updated contents in test-output.

XML as “test suite”

The transcript maps TestNG concepts to XML structure:

  • XML file = test suite
  • <test> tags = groupings of tests
  • <classes> / <class> entries = individual test units
  • @Test methods inside classes = the actual test steps

Main speakers / sources

  • Main speaker: The video instructor (not named in the transcript).
  • Primary sources discussed:
    • TestNG framework
    • Selenium WebDriver
  • Additional mentions:
    • Maven pom.xml
    • ExtentReports (planned future reporting tool)
    • Apache POI as an external library example

Rate this summary

Your feedback will help improve summaries.

Improve this summary

Reprocess with a stronger model when the summary feels incomplete or inaccurate.

Pro

Translate summary in another language

Pro

Ask questions to this video

Chat for follow-up questions, clarifications, and source-backed answers.

Coming soon

Share this summary

Original video