Bird
0
0

How can you achieve this in TestNG?

hard📝 Application Q9 of 15
Selenium Java - TestNG Integration
Consider you have tests assigned to groups 'ui', 'api', and 'integration'. You want to run only tests that belong to both 'ui' and 'integration' groups simultaneously (tests that have both groups assigned). How can you achieve this in TestNG?
AUse a custom listener to filter tests with both groups
BAssign a new group 'ui-integration' to those tests and include it
CRun tests with either 'ui' or 'integration' groups using multiple <include> tags
DUse <include> for 'ui' and <include> for 'integration' with <and> condition in XML
Step-by-Step Solution
Solution:
  1. Step 1: Understand TestNG group filtering

    TestNG includes tests that belong to any included group (logical OR), not AND by default.
  2. Step 2: Identify how to run tests with both groups

    To run tests with both 'ui' and 'integration', assign a new group like 'ui-integration' to those tests.
  3. Step 3: Include the new group in XML

    Include 'ui-integration' group in XML to run only those tests.
  4. Final Answer:

    Assign a new group 'ui-integration' to those tests and include it -> Option B
  5. Quick Check:

    TestNG groups filter = OR logic, use new group for AND [OK]
Quick Trick: TestNG groups combine with OR; use new group for AND logic [OK]
Common Mistakes:
MISTAKES
  • Expecting XML to support AND logic directly
  • Using multiple includes expecting AND behavior
  • Not assigning combined group to tests

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes