TestNG With Selenium WebDriver Interview Questions And Answers

Part 15

68 : What Is the usage of testng.xml file?

Answer : In selenium WebDriver software testing tool, We are using testng.xml file to configure our whole test suite In single file. Few of the tasks which we can specify In testng.xml file are as bellow.

  • We can define software testing test suite using set of test cases to run them from single place.
  • Can Include or exclude test methods from software web application's test execution.
  • Can specify a group to Include or exclude.
  • Can pass parameter to use In test case of software web application.
  • Can specify group dependencies.
  • Can configure parallel test execution for software web application.
  • Can define listeners.
69 : How to pass parameter with testng.xml file to use It In test case?

Answer : We can define parameter In testng.xml file using syntax like bellow.
<parameter name="browser" value="FFX" />

Here, name attribute defines parameter name and value defines value of that parameter. Then we can use that parameter In selenium webdriver software automation test case using bellow given syntax.
@Parameters ({"browser"})

VIEW FULL EXAMPLE on how to define and use parameter from testng.xml file.

70 : I have a test case with two @Test methods. I wants to exclude one @Test method from execution. Can I do It? How?

Answer : Yes you need to specify @Test method exclusion In testng.xml file as bellow.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Test Exclusion Suite">
  <test name="Exclusion Test" >
    <classes>
      <class name="Your Test Class Name">
       <methods>
       <exclude name="Your Test Method Name To Exclude"/>
      </methods>
      </class>      
    </classes>
  </test>
</suite>

You need to provide @Test method name In exclude tag to exclude It from execution.

You can VIEW DETAILED EXAMPLE on how to exclude specific @Test method from execution.


71 : Tell me syntax to skip @Test method from execution.

Answer : You can use bellow given syntax Inside @Test method to skip It from test execution.
throw new SkipException("Test Check_Checkbox Is Skipped");

It will throw skip exception and @Test method will be sipped Immediately from execution. You can VIEW FULL EXAMPLE on how to skip @Test method from execution.

72 : Arrange bellow give testng.xml tags from parent to child.

<test>
<suite>
<class>
</methods>
</classes>

Answer : Parent to child arrangement for above testng tags Is as bellow.

<suite>
<test>
</classes>
<class>
</methods>

1 comment:

  1. Thank you for the questions, these are really very helpful!!

    ReplyDelete