Bird
0
0

How should you set the dependencies?

hard📝 Application Q8 of 15
Selenium Java - TestNG Integration
You have three TestNG test methods: authenticate(), performSearch(), and signOut(). You want performSearch() to execute only if authenticate() passes, and signOut() to execute only if performSearch() passes. How should you set the dependencies?
A<pre>@Test public void authenticate() {}<br>@Test(dependsOnMethods = {"authenticate"}) public void performSearch() {}<br>@Test(dependsOnMethods = {"performSearch"}) public void signOut() {}</pre>
B<pre>@Test(dependsOnMethods = {"performSearch"}) public void authenticate() {}<br>@Test(dependsOnMethods = {"signOut"}) public void performSearch() {}<br>@Test public void signOut() {}</pre>
C<pre>@Test(dependsOnMethods = {"signOut"}) public void authenticate() {}<br>@Test public void performSearch() {}<br>@Test(dependsOnMethods = {"authenticate"}) public void signOut() {}</pre>
D<pre>@Test public void authenticate() {}<br>@Test public void performSearch() {}<br>@Test public void signOut() {}</pre>
Step-by-Step Solution
Solution:
  1. Step 1: Understand dependency chain

    performSearch depends on authenticate, signOut depends on performSearch.
  2. Step 2: Apply dependsOnMethods correctly

    Each dependent method should declare dependsOnMethods with the method it depends on.
  3. Final Answer:

    Option A correctly sets dependencies in sequence. -> Option A
  4. Quick Check:

    Dependencies must follow execution order [OK]
Quick Trick: Chain dependencies with dependsOnMethods in execution order [OK]
Common Mistakes:
  • Reversing dependency directions
  • Not specifying dependencies at all
  • Assigning dependencies to wrong methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes