By: Bijan Patel - In:: Selenium Java Interview Questions and Answers - Part 5
By: Bijan Patel - In:: Selenium Java Interview Questions and Answers - Part 5
By: Bijan Patel|In: Automation
2) Can you arrange the below testng.xml tags from parent to child?
<test>
<suite>
<class>
<methods>
<classes>
<suite><test><classes><class><methods>
8) How to exclude a particular test method from a test case execution using TestNG?
<suite name="Sample Test Suite" verbose="1" >
<test name="Sample Tests" >
<classes>
<class name="com.test.sample">
<methods>
<exclude name="TestA" />
</methods>
</class>
</classes>
</test>
</suite>
9) How to exclude a particular group from a test case execution using TestNG?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Test Suite">
<groups>
<run>
<exclude name="integration"></exclude>
</run>
</groups>
<test name="Test">
<classes>
<class name="TestNGGroupsExample" />
</classes>
</test>
</suite>
12) What are the different ways to produce reports for TestNG results?
There are two ways to generate a report with TestNG −
Listeners − For implementing a listener class, the class has to implement the org.testng.ITestListener
interface. These classes are notified at runtime by TestNG when the test starts, finishes, fails, skips, or
passes.
Reporters − For implementing a reporting class, the class has to implement an org.testng.IReporter
interface. These classes are called when the whole suite run ends. The object containing the information
of the whole test run is passed to this class when called.
13) How to write regular expressions in testng.xml file to search @Test methods containing “smoke”
keyword?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="testSuite">
<test name="test"> <classes>
<class name="sample">
<methods>
<exclude name="smoke.*"/>
</methods>
</class>
</classes>
</test>
</suite>
14) What is the time unit we specify in test suites and test cases?
Time unit is Milliseconds
@Test(invocationCount = 10)
public void testCase(){
System.out.println("Invocation method");
}
Example: Start a thread pool, which contains 3 threads, and run the test method 3 times
@Test(invocationCount = 3, threadPoolSize = 3)
public void testThreadPools() {
System.out.printf("Thread Id : %s%n", Thread.currentThread().getId());
}
@Test(timeOut=5000)
public void executeTimeOut() throws InterruptedException{
Thread.sleep(3000);
}