About Me

Page views

Powered by Blogger.

Followers

Saturday 9 May 2015



TestNG is the framework which is very useful to use with selenium WebDriver.
The main reason behind TestNG's popularity is we can create and configure test case and test suite very easily using many different annotations of TestNG.

Annotations are those things in TestNG which guides it for what to do next or which method should be executed next. TestNG has also facility to pass parameters with annotations. Let we look at TestNG annotations list with its functional description.

@Test
@Test annotation describes method as a test method or part of your test.

@BeforeMethod
Any method which is marked with @BeforeMethod annotation will be executed before each and every @test annotated method.

@AfterMethod
Same as @BeforeMethod, If any method is annotated with @AfterMethod annotation then it will be executed after execution of each and every @test annotated method.


@BeforeClass
Method annotated using @BeforeClass will be executed before first @Test method execution. @BeforeClass annotated method will be executed once only per class so don't be confused. VIEWPRACTICALEXAMPLEOF@BeforeClass ANNOTATION

@AfterClass
Same as @BeforeClass, Method annotated with @AfterClass annotation will be executed once only per class after execution of all @Test annotated methods of that class. VIEWPRACTICALEXAMPLEOF@AfterClass ANNOTATION

@BeforeTest
@BeforeTest annotated method will be executed before the any @Test annotated method of those classes which are inside <test> tag in testng.xml file. VIEW PRACTICAL EXAMPLE

@AfterTest
@AfterTest annotated method will be executed when all @Test annotated methods completes its execution of those classes which are inside <test> tag in testng.xml file. VIEW PRACTICAL EXAMPLE

@BeforeSuite
Method marked with @BeforeSuite annotation will run before the all suites from test.

@AfterSuite
@AfterSuite annotated method will start running when execution of all tests executed from current test suite.

@DataProvider
When you use @DataProvider annotation for any method that means you are using that method as a data supplier. Configuration of @DataProvider annotated method must be like it always return Object[][] which we can use in @Test annotated method.
@BeforeGroups
@BeforeGroups annotated method will run before the first test run of that specific group.

@AfterGroups
@AfterGroups annotated method will run after all test methods of that group completes its execution.

@Parameters
When you wants to pass parameters in your test methods, you need to use @Parameters annotation. VIEWPRACTICALEXAMPLEOF@Parameters ANNOTATION

@Factory
When you wants to execute specific group of test cases with different values, you need to use @Factory annotation. An array of class objects is returned by @Factory annotated method and those TestNG will those objects as test classes.

@Listeners
@Listeners are used to with test class. It is helpful for logging purpose.

0 comments:

Post a Comment

Popular Posts

Copyright © Learn Selenium Yourself | Powered by Blogger
Design by Duan Zhiyan | Blogger Theme by NewBloggerThemes.com