TESTNG FAQ

  1. What are the annotations used in TestNG ?
  2. @Test, @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, @BeforeClass, @AfterClass, @BeforeMethod, @AfterMethod.
  3. What is the difference between @BeforeMethod and @BeforeClass ?
  4. @BeforeMethod- this will execute before every @Test method. @BeforeClass- this will execute before every class.
  5. What are the different attributes for @Test annotation?
  6. alwaysRun, dataProvider, dependsOnMethods, enabled, priority etc.
  7. What is return type of Data Provider?
  8. Object[][]
  9. What are advantages of TestNG over Junit?
  10. In Junit we have to declare @BeforeClass and @AfterClass which is a constraint where as in TestNG there is no constraint like this.
    Additional Levels of setUp/tearDown level are available in TestNG like @Before/AfterSuite,@Before/AfterTest and @Before/AfterGroup No Need to extend any class in TestNG.
    There is no method name constraint in TestNG as in Junit. You can give any name to the test methods in TestNG.
    In TestNG we can tell the test that one method is dependent on another method where as in Junit this is not possible. In Junit each test is independent of another test.
    Grouping of test cases is available in TestNGwhere as the same is not available in Junit.
    Execution can be done based on Groups.. Also using TestNG your selenium testcase execution can be done in parallel
  11. I'm running testng.xml with group name. Before/AfterClass is not running?
  12. When you specify a group to run, any method that is not part of this group will not be run. Since @BeforeClass/@AfterClass do not belong to that group, they are not being run. The way to fix this is to put these methods in that group or to use alwaysRun=true
  13. What is the difference between priority and dependsOnMethods?
  14. Priority is used set the sequence of execution of @Test mthods in a TestNg class dependsOnMethods is used to skip test methods whenever dependent method is failed/skipped.
  15. How to capture bitmaps in Selenium? | Selenium
  16. Bitmaps are captured using the Selenium set of commands. There are two modes of capturing the bitmaps
    1) Capture the bitmap for the entire page - it captures the browser main page area of AUT
    2) Capture the bitmap for the screen shots - it captures the entire screen shot like the print screen that you give from your keyboard Selenium doesn't support bitmap capturing for an element on AUT.
  17. When to use Accessors in Selenium? | Selenium
  18. Accessors are mostly used for storing the value in a variable. The variable can be used for following reasons:
    1) To get the value from an element and comparing with some dynamic value
    2) To take a logical decision to execute the test steps
    ex: if the value of the variable true execute step1 and step2 else step3 and step4
    3) To execute some statements in a loop based on the value returned by the element.
  19. When to use Assert, Verify and WaitFor in Selenium? | Selenium
  20. 1) assert - If the expected value is mandatory to continue with the next set of steps we will use Assert. As Assert aborts the test, if the expected value doesn't match. It is good to use for any mandatory checks.
    2) verify - If the expected value is optional to continue with the next set of steps we will use Verify. As Verify continues executing with the next set of steps, if the expected value doesn't match. It is good to use for any optional checks.
    3) waitFor - If your test needs to wait, if the expected value is not matching we use waitFor. We normally use waitFor for AJAX kind of controls loading within a page.
  21. What are the types of Assertions there in Selenium? | Selenium
  22. Selenium Assertions can be used in 3 modes:
    1) assert - When an "assert" fails, the test will be aborted. If you are executing test suite, the next state case will start
    2) verify - When a "verify" fails, the test will continue execution, logging the failure.
    3) waitFor - "waitFor" commands wait for some condition to become true (which can be useful for testing Ajax applications).
    They will succeed immediately if the condition is already true. However, they will fail and halt the test if the condition does not become true within the current timeout setting.
  23. What is Assertion in Selenium? | Selenium
  24. Assertion is nothing but a check or verification point.
    Assertion verifies the state of the application conforms to what is expected.
    Examples include "make sure the page title is X" and "verify that this checkbox is checked.