26
Dec

Configure Timeout duration for TestNG testmethods

TestNG allows user to configure a time period to wait for a test to completely execute. Timeout can be configured in two ways:

#1. At TestMethod level:

@Test(timeout=500)
public void testmethodOne(){
Thread.sleep(1000);
System.out.println(“This testmethod will timeout”);
}

#2. At suite level:

Step1: define testmethods

@Test
public void testmethodTwo(){
Thread.sleep(1000);
System.out.println(“This testmethod will timeout”);
}

@Test(
public void testmethodThree(){
Thread.sleep(500);
System.out.println(“This testmethod will execute properly”);
}

Step2: Configure testng.xml for timeout settings as follow:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”>
<suite name=”Suite” time-out=”500″ verbose=”1″ >
<test name=”GroupTest”>
<classes>
<class name=”com.project.CustomFindBy.JSClickExample” />
</classes>
</test> <!– GroupTest –>
</suite> <!– Suite –>