TestNG Qns
TestNG Qns
Answer: TestNG is the framework created for executing unit tests in java program by
the developers.
TestNG is also used by the software testers to efficiently run the automated test scripts
created in Selenium Webdriver. Its full form is the “Testing New Generation” framework.
It is inspired by “JUnit” which is another framework for unit testing Java programs. In
addition to all the features in JUnit, TestNG has its new features which make it more
powerful.
OR
Directly click on the Run button on the toolbar of the Eclipse.
(ii) Test annotation: This is the annotation which is only mentioned before the test case
(Before the method written to execute the test case)
@Test is the test annotation
(iii) Postcondition annotation: These are the annotations that are executed after the
test case. (After the method is written to execute the test case)
@AfterSuite, @AfterClass, @AfterTest, @AfterMethod are the postcondition annotations
@BeforeTest
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@AfterClass
@Aftertest
@AfterSuite
And, getText() will get executed after clickelement() as its priority is set to 2.
This is the file that gets generated on your machine automatically after the execution of
the class using TestNG.
In the above example, the print() method will get executed 8 times.
In this case, the method will get terminated in 5000 ms (5 seconds) and the test case is
marked as “Failed”.
@Test(expectedException=numberFormatException.class)
If the hard assert fails, then none of the code gets executed after the assert statement.
So now if the test case fails, the execution is not terminated when we use soft assert.
Q #17) How to pass parameter in the test case through the testng.xml file?
Answer: If we have a class in which a login method is defined, then we can pass the
login parameters to this login method from the testing.xml file
We will have to use the “@parameters” annotation as follows:
@Parameters({"user_name","password"})
@Test
We have a blank XML file. Here, we have to mention the project name and the classes
to be executed along with the package name as shown below.