Q. What is TestNG and it’s benefits ?
TestNG stands for Testing Next Generation framework. It is unit test automation framework inspired from JUnit.
Benefite:
- It is open source
- It supports lots of annotations
- It allows to set the priority of test cases
- It allows to group the test cases
- We can set the dependency of on test case on another test case
- It has good reporting features
- It support parallel testing

Q. What is the default Test execution sequence if we do not specify the priority ? When you have more than one @Test.
In case of multiple @Test…By default @Test will be executed based on alphabetical order of method name if we have not set the priority.

Q. How to enable disable a Test ?
@Test(enabled=true) to enable and @Test(enabled=false), If we make a test as enabled=false then that test will not be executed

Q. How to set the priority ?
Syntax: @Test(priority=1)

Q.Which priority @Test gets executed 1st ?
Less priority gets executed first

Q. Can we give priority as minus value ?
Yes its allowed.
Example
@Test(priority=-5)
@Test(priority=-8)
so @Test(priority=-8) will be executed first

Q. What is the execution sequence of TestNG Annotations?
@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite

Q. Which annotation is called by default when @Test is called?
@BeforeMethod and @AfetrMethod (if available) is called by default with @Test

Q. TestNG default reports ?
1.emailable-report.html
2. Default test.html
3. index.html (contains: suite.xml, total time, number of total methods, pass/failed methods count, count of tests, count of groupes)

Q. What is Assert?
Assert is a class in TestNG which is used to validate some outcomes. We add the validation points using Assert in our automation script to make it more meaningful

Q. Difference between soft assertion and hard assertion ?
1. If soft assert fails then it doesn’t stop the execution of next statements. After executing all the remaining steps it makes the test case as failed but when a hard assert fails then it stops the execution of next statement and terminates the test and control goes to next @Test annotation
2. In case of soft assert we need to create the object of SoftAssert class where as in case of Hard assert we don’t need to create any object

Q. if Assertion fails then it throws exception or error ?
Java.lang.AssertionError

Q.How to verify error message ?
1) Using getText() method we can get text of element having error message on web page and store in a String variable as actual, we can give the expected in another String variable and we can use Assert.assertEqual to compare actual with expected.
2) Using getAttribute(innerHTML) method we can get the text of element having error message on web page and store in a String variable as actual, we can give the expected in another String variable and we can use Assert.assertEqual to compare actual with expected.