Video summary
Session 44 - Selenium with Java | TestNG | Dependency Methods | Grouping Tests
Main summary
Key takeaways
Main ideas / lessons conveyed
1) TestNG Dependency Methods (dependsOnMethods)
Problem with default TestNG behavior
- By default, TestNG runs every method annotated with
@Testin a class. - If an early “setup” test fails (e.g.,
openApp), dependent later tests (e.g.,login,search, etc.) will logically fail too—but TestNG will still attempt to run them, wasting time.
Goal
- If a dependency test method fails, then methods that depend on it should be skipped, not executed.
Concept of dependencies
Example dependency chain:
logindepends onopenAppsearchandadvancedSearchdepend onloginlogOutdepends onlogin
Methodology / implementation steps shown (practical approach)
- Create a TestNG class containing multiple
@Testmethods (e.g.,openApp,login,search,advancedSearch,logOut). - Assign
priorityvalues (used for ordering, though dependency controls skipping/execution). - Demonstrate behavior using assertions:
- A failing assertion in a dependency method represents “dependency failed”.
- Add dependency control:
- For
login, set in@Test:dependsOnMethods = {"openApp"}
- For dependent methods:
searchdepends onloginadvancedSearchdepends onloginlogOutdepends onlogin
- For
Expected outcomes
- If
openAppfails →login(and its dependents) are skipped. - If
openApppasses butloginfails →search,advancedSearch,logOutare skipped.
Multiple dependencies
- Use
@Test(dependsOnMethods = {"login", "search"})to run a method only if both dependencies succeed. - If any specified dependency is skipped/failed, the dependent method is skipped.
Advantage emphasized
- Avoid running tests that are guaranteed to fail due to earlier failures.
- Saves time/effort, especially when there are many dependent tests.
Key attribute mentioned
dependsOnMethodsis a parameter/attribute of the@Testannotation only.
2) TestNG Grouping of Tests (executed via XML)
Purpose of grouping
- In real projects you might have many test methods and you don’t want to run everything every time.
- Group test methods into categories based on testing type and execution needs.
Typical groups discussed
- Sanity: quick/basic functionality checks (e.g., login/signup)
- If sanity fails, deeper checks shouldn’t proceed.
- Regression: rerun tests to verify fixes after developers provide a build.
- Functional (combined category): methods that belong to both sanity and regression (created as a combined group for execution).
Where grouping is defined
- In the test code using the
groupsattribute inside@Test. - Selection is controlled in a TestNG XML file.
Methodology / implementation steps shown (end-to-end)
-
Create multiple test classes, each containing several
@Testmethods. Example classes:LoginTest,SignUpTest,PaymentTest -
Assign group tags to each test method using
@Test(groups = "..."):- login by email/facebook/twitter →
groups = "sanity" - sign up by email/facebook/twitter →
groups = "regression" - payment in rupees/dollars →
groups = {"sanity","regression"}(a method can belong to multiple groups)
- login by email/facebook/twitter →
-
Create an XML suite (manually or via Eclipse auto-generation):
- Base XML structure includes:
<!suite name="..."><test name="..."><classes><class name="fully.qualified.ClassName"/>
- Base XML structure includes:
-
Filter which groups run in XML:
- Add a
<groups>section (placed before the<classes>tag in the suite/test setup). - Use:
<run>with<include>to select only certain groups<run>with<exclude>to skip certain groups
- Add a
XML filtering behavior demonstrated
-
Run only one group
- Include
sanity→ executes only sanity-tagged tests across all classes.
- Include
-
Run one group but exclude another
- Include
sanityand excluderegression - Runs sanity tests that are NOT also regression (excludes tests tagged with both).
- Include
-
Run “regression but not sanity”
- Include
regressionand excludesanity - Keeps only regression-only tests (excluding overlap).
- Include
-
Run only tests that belong to BOTH groups
- Including both groups in XML alone doesn’t enforce a logical “AND” (it behaves like a union).
- Solution: create a new combined group name (e.g.,
functional) and tag the overlap methods with it:- In code:
groups = {"sanity","regression","functional"} - In XML: include only
functional
- In code:
Key attribute mentioned
groupsis an attribute of the@Testannotation.- XML
include/excludetags control which group-labeled methods execute.
Speakers / sources featured
- No specific person’s name is provided in the subtitles (speaker is referenced generically as the instructor).
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.