Search code examples
seleniumselenium-webdriverreportingalluretestng-dataprovider

How to use @Description (in allure reporting) dynamically for each test case that executes same test method


I am using Allure reporting for my java-selenium testing framework . My Data provider is a HashMap in form of below

public static HashMap<String, String>[][] getDataTable(String fileName, String sheetName)

where fileName is the excel workBook name as saved in the location and sheet name is the one of the worksheet of workBook.

If I use @Description above the test method then same description will be shown for each test cases.

I have different test cases and their respective description for same test methods (Lets say method is Login and TestCase1: Login without password,TestCase2:Login without userName)

So for both test case i need different description using @Description in the allure reporting.

Should i modify the data provider for it? If so how?


Solution

  • For this I'm using something like this:

        @Test(dataProvider = "getListOfCredentials", dataProviderClass = AuthenticationDataProvider.class)
        public void loginUser(AuthenticationData authenticationData) {
                AllureLifecycle lifecycle = Allure.getLifecycle();
                lifecycle.updateTestCase(testResult -> testResult.setName("Test wrong login with username: "+authenticationData.getUsername()));
                lifecycle.updateTestCase(testResult -> testResult.setDescription("Test wrong login with password: "+authenticationData.getPassword()));
    }
    

    So, I have the Allure description and test title dynamic based on what credentials my data provider method will return each time the test will run using the object authenticationData.