Dependency Tests in TestNG

  • Estimate Completion Time
    not found 30 minutes
  • Difficulty Level:

Write three TestNG tests and use dependsOnMethods to define the dependencies between test methods.

Steps to follow

Create four test methods: openbrowser(), login() and logout(), closebrowser(). These methods will run alphabetically by default.

Execute these methods using the TestNG dependency feature and ensure that login runs after openbrowser, logout runs after the login method, and closebrowser runs after logout.

Solution

package practice;

import org.testng.annotations.Test;

public class Exercise {

	@Test
	public void openbrowser() {
		System.out.println("Opening Chrome Browser");
		//write code
	}
	
	@Test(dependsOnMethods = "openbrowser")
	public void login() {
		System.out.println("Login page open");
		//write code
	}
	
	@Test(dependsOnMethods = "login")
	public void logout() {
		System.out.println("Logout successfully");
		//write code
	}
	
	@Test(dependsOnMethods = "logout")
	public void closebrowser() {
		System.out.println("Closing Browser");
		//write code
	}
}
TestNG Practice Exercises - QA Ads Banner

Proleed Academy

Proleed serves / offers professionally designed IT training courses
globally.

Copyright © 2023 - Proleed Academy | All Rights Reserved.