Video summary
Session 42 - Selenium with Java | TestNG Integration & Setup | @Test annotation
Main summary
Key takeaways
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
-
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 > Preferencesshould show a TestNG section/plugin option.
- Go to:
-
Associate TestNG with the current project
- Option A (recommended for IDE)
- Right-click project →
Properties > Java Build Path > Libraries > Add Library > TestNG
- Right-click project →
- Option B (Maven dependency)
- Add a testng dependency in
pom.xml(version referenced around “7.1.0” in the transcript).
- Add a testng dependency in
- Option A (recommended for IDE)
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
@Testand 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
priorityin@Test(priority = X).
Priority rules (key points)
- If
priorityis not specified, TestNG runs methods in alphabetical order. - If you set
priority, TestNG uses priority value as the main ordering rule. - Once
priorityis set, the order of methods in the code does not matter. - Priority numbers do not need to be consecutive (they can be any values).
- Priority numbers can be random.
- If two methods share the same priority, TestNG falls back to alphabetical order.
- Negative priority values are allowed (TestNG runs the lowest number first).
- Default priority when
priorityis omitted is 0. - TestNG executes only methods annotated with
@Test.- If no methods have
@Test, it reports: “No tests were found”.
- If no methods have
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 insideopenApp(), other@Testmethods won’t be able to access it. -
The WebDriver must be a class-level variable shared across test methods.
- Use
driver.get(URL)insideopenApp(). - Validate logo using:
driver.findElement(...).isDisplayed()- Use
sendKeys()andclick()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:
- Run single or multiple test classes in one run
- Automatically generate TestNG reports in the
test-outputfolder
How to create/run XML
Automatic generation
- Right-click test/package →
TestNG > Convert to TestNG - This generates a
testng.xmltemplate.- The speaker notes Eclipse may require a workaround/forced download link if external resources are disabled.
Manual creation
- Create an empty
.xmlfile 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@Testmethods 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
- Maven
Rate this summary
Your feedback will help improve summaries.
Improve this summary
Reprocess with a stronger model when the summary feels incomplete or inaccurate.
Translate summary in another language
Ask questions to this video
Chat for follow-up questions, clarifications, and source-backed answers.