LogoLogo
  • 🏹Lời nói đầu
  • 1. Introduction
  • 💡1.1. Các hoạt động trong 1 vòng kiểm thử
  • 💡1.2. Các cách tiếp cận khi viết automation test
  • 🔮1.3. Con đường phát triển của một kỹ sư kiểm thử phần mềm
  • ✅1.4. Quy trình của một dự án kiểm thử tự động
  • 🤖1.5. Các Framework trong kiểm thử tự động
  • 💎1.6. Selenium Java Basic mindmap
  • 📜1.7. Test cases
  • 2. Setup new maven project
    • ☕2.1. Install Java JDK
    • ☕2.2. Setup Maven
    • ☕2.3 Add Maven Dependencies
    • ☕2.4. Java practices
      • ⌨️2.4. Java Coding Practice
      • 📔Java Stream
        • 🍀Java 8 Stream - Xử lý Array, List nhanh gọn
          • 🛵1. find person that has mass >100
            • 🚜2. total mass of characters
            • 🚍3. total height of characters
            • 🚲4. get list name of person
            • 🛴5. find max mass person
            • 🚒6. find smallest person
            • 🚂7. sort by name
            • 🏎️8. sort by mass
      • 📁Logging
        • 🍏Log4j 2
  • 3. browsers
    • 🚚3.1. What is WebDriver?
    • 3.2. Chrome Browser
      • 🕸️Open Chrome Browser
        • Capture Performance metrics in chrome with selenium 4.0
        • Open Chrome Browser in Mobile mode
        • How to set specified chrome version to start
        • Interception Network tab
        • Open Chrome Browser - Headless mode
      • Fake GeoLocation
    • 3.3. Open Firefox Browser
      • Open Firefox Browser - Headless mode
    • 3.4. Open Edge Browser (Chromium)
    • 3.5. Open Safari browser
  • 🌞4. Inspect locators
  • 4.1. Understand HTML structure
  • 4.2. Locator Table
  • 4.3. Standard Naming Convention for UI Elements to Use with Selenium Locators
  • 4.4. FindElement
  • 4.5. Locating elements with XPath axis
  • 🍏5. Test Cases
    • 5.1. Form Authentication
    • 5.2. Drop Down
    • 5.3. Checkboxes
    • 5.4. Hyperlink
    • 5.5. Web Table
    • 5.6. JavaScript Alert
    • 5.7. Nest Frames
    • 5.8. Context menu
    • 5.9. Hover
    • 5.10. Broken Link
    • 5.11. Click Element via JS
    • 5.12. Wait for loading
    • 5.13. Pass params though XPath string
    • 5.14. Date picker
    • 5.15. Capture Screenshot
  • 6. TestNG
    • Annotations
    • testng.xml
      • parameter
      • Filter by group
      • Listener
      • Parallel
  • Capture screenshot when test failed
  • 🍐7. Page Object Model
    • What is?
    • Approach 1: Using String for exposing elements
    • Approach 2: Using By for exposing elements
    • Approach 3: Using PageFactory for exposing elements
    • Todo MVC sample page
      • page
      • supports
      • testcases
  • 8. Circle CI - Github Actions
    • Integrate Circle CI
  • 🥞9. Owner methods
    • Selenium owner methods
  • Interview
    • How I interview tester
      • 35 Challenging Interview Questions for Testers
    • Git căn bản
    • VSCODE
Powered by GitBook

Copyright @testingvn.com

On this page

Was this helpful?

  1. 6. TestNG

Annotations

Here is a quick overview of the annotations available in TestNG along with their attributes.

Behaviour of annotation

@BeforeSuite

@BeforeSuite: The annotated method will be run before all tests in this suite have run.

@AfterSuite

@AfterSuite: The annotated method will be run after all tests in this suite have run.

@BeforeTest

@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run.

@AfterTest

@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run.

@BeforeGroups

@BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked.

@AfterGroups

@AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked.

@BeforeClass

@BeforeClass: The annotated method will be run before the first test method in the current class is invoked.

@AfterClass

@AfterClass: The annotated method will be run after all the test methods in the current class have been run

@BeforeMethod

@BeforeMethod: The annotated method will be run before each test method.

@AfterMethod

@AfterMethod: The annotated method will be run after each test method

alwaysRun

For before methods (beforeSuite, beforeTest, beforeTestClass and beforeTestMethod, but not beforeGroups): If set to true, this configuration method will be run regardless of what groups it belongs to. For after methods (afterSuite, afterClass, ...): If set to true, this configuration method will be run even if one or more methods invoked previously failed or was skipped.

dependsOnGroups

The list of groups this method depends on.

dependsOnMethods

The list of methods this method depends on.

enabled

Whether methods on this class/method are enabled.

groups

The list of groups this class/method belongs to.

inheritGroups

If true, this method will belong to groups specified in the @Test annotation at the class level.

onlyForGroups

Only for @BeforeMethod and @AfterMethod. If specified, then this setup/teardown method will only be invoked if the corresponding test method belongs to one of the listed groups.

@DataProvider

Marks a method as supplying data for a test method. The annotated method must return an Object[][] where each Object[] can be assigned the parameter list of the test method. The @Test method that wants to receive data from this DataProvider needs to use a dataProvider name equals to the name of this annotation.

name

The name of this data provider. If it's not supplied, the name of this data provider will automatically be set to the name of the method.

parallel

If set to true, tests generated using this data provider are run in parallel. Default value is false.

@Factory

Marks a method as a factory that returns objects that will be used by TestNG as Test classes. The method must return Object[].

@Listeners

Defines listeners on a test class.

value

An array of classes that extend org.testng.ITestNGListener.

@Parameters

Describes how to pass parameters to a @Test method.

value

The list of variables used to fill the parameters of this method.

@Test

Marks a class or a method as part of the test.

alwaysRun

If set to true, this test method will always be run even if it depends on a method that failed.

dataProvider

The name of the data provider for this test method.

dataProviderClass

The class where to look for the data provider. If not specified, the data provider will be looked on the class of the current test method or one of its base classes. If this attribute is specified, the data provider method needs to be static on the specified class.

dependsOnGroups

The list of groups this method depends on.

dependsOnMethods

The list of methods this method depends on.

description

The description for this method.

enabled

Whether methods on this class/method are enabled.

expectedExceptions

The list of exceptions that a test method is expected to throw. If no exception or a different than one on this list is thrown, this test will be marked a failure.

groups

The list of groups this class/method belongs to.

invocationCount

The number of times this method should be invoked.

invocationTimeOut

The maximum number of milliseconds this test should take for the cumulated time of all the invocationcounts. This attribute will be ignored if invocationCount is not specified.

priority

The priority for this test method. Lower priorities will be scheduled first.

successPercentage

The percentage of success expected from this method

singleThreaded

If set to true, all the methods on this test class are guaranteed to run in the same thread, even if the tests are currently being run with parallel="methods". This attribute can only be used at the class level and it will be ignored if used at the method level. Note: this attribute used to be called sequential (now deprecated).

timeOut

The maximum number of milliseconds this test should take.

threadPoolSize

The size of the thread pool for this method. The method will be invoked from multiple threads as specified by invocationCount. Note: this attribute is ignored if invocationCount is not specified

Previous5.15. Capture ScreenshotNexttestng.xml

Last updated 4 years ago

Was this helpful?