TestNG Annotations Helper Attributes in Selenium Webdriver

.

TestNG Annotations Attributes in Selenium With Example

 TestNG Annotations Helper Attributes Syntax

The basic syntax of testing the annotations attribute is given below.
@Test(attribute="value")
public void testcase2()
{
System.out.println("This is testcase2");
}


List of TestNG Annotations Attributes
There are multiple TestNG Annotations attributes are available.
  • description
  • timeOut
  • priority
  • dependsOnMethods
  • enabled
  • groups

TestNG Helper Attributes


description
The description is a TestNG annotation helper Attribute that describes the information about the test. Description is a string that is attached to the @Test annotation.

Example of Description
Example of Description TestNG annotation helper Attribute.

package testNGpackage;


import org.testng.annotations.Test;


public class FirstTestNGprogram {


@Test(description="This is testcase1")

public void userlogin()

{

System.out.println("This is user Login");


}

@Test (description="This is testcase2")

public void cutomerlogin()

{

System.out.println("This is cutomer Login");

}

}


timeOut
If any test case takes more than the defined time to execute and because of this the test case fails in this cases we can add the timeout for that test case only.


package testNGPackage;


import org.testng.annotations.Test;


public class FirstTestngClass {

@Test

public void usersignup() {

System.out.println("user Signup");

}

@Test

public void membersingup() {

System.out.println("This is Member singup");

}

@Test

public void customersingup() {

System.out.println("This Customer signup");

}

@Test (timeOut=4000)

public void customerdetails() {

System.out.println("This Customer Details");

}


}

  • priority
  • dependsOnMethods

enabled
enabled is used to skip any method (Test Cases ) to run. The 'enabled' attribute contains the boolean value

Example of enabled helper Attribute

package testNGPackage;


import org.testng.annotations.Test;


public class FirstTestngClass {

@Test

public void usersignup() {

System.out.println("user Signup");

}

@Test

public void membersingup() {

System.out.println("This is Member singup");

}

@Test

public void customersingup() {

System.out.println("This Customer signup");

}

@Test (enabled=false)

public void customerdetails() {

System.out.println("This Customer Details");

}


}




groups

The 'groups' attribute is used to run the test cases that belong to the same groups and different classes.

Let's understand the same with an example 

Scenario: 
Suppose we have to run a few test cases that belong to different Java classes.

Here We have created two Java classes and added the groups helper attribute to run the test cases.

Class 1

package testNGPackage;


import org.testng.annotations.Test;


public class FirstTestngClass {

@Test

public void usersignup() {

System.out.println("user Signup");

}

@Test

public void membersingup() {

System.out.println("This is Member singup");

}

@Test(groups={"signup"})

public void customersingup() {

System.out.println("This Customer signup");

}

@Test

public void customerdetails() {

System.out.println("This Customer Details");

}


}



Class 2 

package testNGPackage;


import org.testng.annotations.Test;


public class SecondTestngClass {

@Test

public void usersignin() {

System.out.println("user Sign in");

}

@Test(groups={"signup"})

public void membersingin() {

System.out.println("This is Member singin");

}

@Test

public void customersingin() {

System.out.println("This Customer signin");

}

}



.XML File

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite">

<test name="userSignup">

<groups>

<run>

<include name="signup"></include>

</run>

</groups>

<classes>

<class name="testNGPackage.FirstTestngClass"/>

<class name="testNGPackage.SecondTestngClass"/>

</classes>



Hope!!! The above tutorial on the TestNG Annotation attribute is helpful for you...

Team,
QA acharya

TestNG Annotations Helper Attributes in Selenium  


Post a Comment

0 Comments