0
0
Selenium Javatesting~8 mins

Test groups in Selenium Java - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Test groups
Folder Structure
src/
└── test/
    └── java/
        └── com/
            └── example/
                ├── pages/
                │   └── LoginPage.java
                ├── tests/
                │   ├── LoginTests.java
                │   └── DashboardTests.java
                ├── utils/
                │   └── WebDriverFactory.java
                └── testng.xml
Test Framework Layers
  • Driver Layer: WebDriverFactory.java manages browser drivers and setup.
  • Page Objects: Classes like LoginPage.java encapsulate UI elements and actions.
  • Test Layer: Test classes (LoginTests.java) contain test methods grouped by functionality.
  • Utilities: Helper classes for common functions, e.g., waits or data handling.
  • Configuration: testng.xml defines test groups and execution settings.
Configuration Patterns

Use testng.xml to define test groups and control which groups run.

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" verbose="1" parallel="false">
  <test name="Regression Tests">
    <groups>
      <run>
        <include name="regression"/>
      </run>
    </groups>
    <classes>
      <class name="com.example.tests.LoginTests"/>
      <class name="com.example.tests.DashboardTests"/>
    </classes>
  </test>
</suite>

In test classes, use @Test(groups = {"groupName"}) to assign tests to groups.

Test Reporting and CI/CD Integration
  • TestNG generates HTML and XML reports showing which groups passed or failed.
  • CI tools (Jenkins, GitHub Actions) run tests by group using testng.xml files.
  • Reports help quickly identify issues in specific test groups like "smoke" or "regression".
  • Integrate with Slack or email notifications to alert team on group test results.
Best Practices for Test Groups
  1. Group by Purpose: Organize tests into meaningful groups like smoke, regression, or sanity.
  2. Keep Groups Small: Avoid very large groups to keep test runs fast and focused.
  3. Use Groups for Parallel Runs: Run different groups on separate machines to save time.
  4. Document Groups: Clearly describe what each group tests for easy maintenance.
  5. Combine with Tags: Use groups with other TestNG features like priorities for flexible runs.
Self Check

Where in this folder structure would you add a new test group called "smoke"?

Answer: In the testng.xml configuration file, add a new <test> section including tests with @Test(groups = {"smoke"}). Also, annotate test methods in test classes under src/test/java/com/example/tests/ with groups = {"smoke"}.

Key Result
Use TestNG groups in test classes and testng.xml to organize and run tests by categories.