Using dependsOnMethods Of TestNG In Selenium WebDriver Test Case - Tutorial Testing Software

Latest

Android apps to use in appium android test examples

Wednesday, December 13, 2017

Using dependsOnMethods Of TestNG In Selenium WebDriver Test Case

Earlier inwards previous post, We accept learnt how to develop examine execution priority of WebDriver test cases If you lot accept multiple tests In same class. TestNG has i to a greater extent than real useful characteristic of setting examine execution dependency. Dependency agency If one @Test method fails or skipped from execution thence It's dependent @Test method must non live on executed.

Supposing you lot are testing online electronic mail application using selenium WebDriver in addition to you lot accept ii @Test methods In your cast : 1) For LogIn in addition to 2) For Check Mail. Now due to the unopen to reasons (Invalid credentials), LogIn @Test method fails. In this instance you lot non bespeak to execute Check Mail @Test method because how tin dismiss you lot banking concern stand upwardly for emails without LogIn In electronic mail application? In this case, You tin dismiss use dependsOnMethods with @Test notation of  Check Mail method to skip Its execution.

I accept created uncomplicated illustration every bit bellow to demonstrate how It works.

Example :
package TestNG_Advanced;  import org.testng.Assert; import org.testng.annotations.Test;  world cast setPriority {       //This Is Independent method thence It volition live on executed.     @Test(priority=1)     world void Login() {   System.out.println("LogIn Test code.");   //Bellow laissez passer on assertion volition neglect to neglect Login() method Intentionally.   Assert.assertTrue(5>6, "Condition Is False.");     }        //This method Is depends on Login method.     //This method's execution volition live on skipped from execution because Login() method volition fail.     @Test(priority=2, dependsOnMethods={"Login"})     world void checkMail() {   System.out.println("checkMail Test code.");        }       //This method Is depends on Login in addition to checkMail methods.     //This method's execution volition live on skipped from execution because Login() method volition fail.     @Test(priority=3,dependsOnMethods={"Login","checkMail"})     world void LogOut() {   System.out.println("LogOut Test code.");      }       //This Is Independent method thence It volition live on executed.     @Test(priority=4)     world void checkLogInValidations() {   System.out.println("checkLogInValidations Test code.");        } }

TestNg upshot volition looks similar bellow.

  1. LogIn() method Is failed because nosotros accept written incorrect status In assertion.
  2. checkMail() and LogOut() methods are skipped from execution because they are depends on LogIn() method which Is failed.
  3. checkLogInValidations() method volition live on executed because It Is Independent.
So this way, We tin dismiss develop dependency on @Test methods to skip Its execution If It's depends on method fails.
Internet Marketing Tool here :Zeageat IM
http://www.software-testing-tutorials-automation.com/

No comments:

Post a Comment