Skip to content

Tags are shown in random order on dashboard #438

Open

Description

@pratik2rock

The order of Tags shown on dashboard is not same as order in which tests are run and tags are assigned.

e.g. I have 4 test classes as Class1,Class2,Class3,Class4

Categories assigned in each class are
Class1 - Category1
Class2 - Category2
Class3 - Category3
Class4 - Category4

When these categories are shown on dashboard under section Tags, they are not shown in same order as tests run i.e. from Class1 to Class4, instead the categories are shown in random order on dashboard.

Activity

  1. ptvelikov commented on Mar 18, 2025

    @ptvelikov

    Is there any progress, analysis or updates on this issue? Is there a workaround? The problem is not only in the Tags section in the Dashboard, but in the Category view, also. There is no logic in the ordering of the Tags/Categories, each time they are ordered randomly. Is there a way to force them to order by name or by time?

    Image

    Image

    I have tried making a custom method for reordering the categories just before the flush.

    public static void sortCategoriesInReport() {
            if (extent == null) {
                logger.warn("ExtentReports instance is null. Skipping category sorting.");
                return;
            }
    
            Set<NamedAttributeContext<Category>> categorySet = extent.getReport().getCategoryCtx().getSet();
    
            // Convert to sorted list
            List<NamedAttributeContext<Category>> sortedCategories = categorySet.stream()
                    .sorted(Comparator.comparing(c -> c.getAttr().getName(), String.CASE_INSENSITIVE_ORDER))
                    .toList(); 
    
            // Clear and re-add sorted categories in bulk
            categorySet.clear();
            categorySet.addAll(sortedCategories); // Bulk add instead of iteration
    
            // Print sorted categories
            String sortedCategoryNames = sortedCategories.stream()
                    .map(c -> c.getAttr().getName())
                    .collect(Collectors.joining(", "));
    
            logger.info("Categories sorted successfully: {}", sortedCategoryNames);
        }
    

    calling it in another class like this:

    // Finalize and flush the ExtentReports
            ExtentReportManager.sortCategoriesInReport();
            extent.flush();
            logger.info("Test execution completed. Report generated.");
    

    the result of the method is:

    2025-03-18 15:40:02 INFO t.reports.ExtentReportManager - Categories sorted successfully: 001-LoginPageSuite, 002-MaintenanceSuite, 003-ConfigurationSuite, 004-DealerAdminSuite, 005-UserManagementSuite 2025-03-18 15:40:02 INFO executors.BaseTestExecutor - Test execution completed. Report generated.

    which means that the ordering works, but i was not able to find proper set method to write the ordered values to the report back.

    Additionally, most probably the flush itself refreshes the ordering in the "Report" class and specifically in the "public final void refresh()" method - https://github.com/extent-framework/extentreports-java/blob/master/src/main/java/com/aventstack/extentreports/model/Report.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions