How to write automation to verify a list of users that have the same role

24 Views Asked by At

I wanted to verify these lists of users or sample of data have the same role. For instances:

field: Users, field: Roles

Users:

A-tester

B-tester

C-tester

D-tester

E-tester

F-tester

G-tester

I wanted to verify field users has the same role from field Roles

Users(A/B/C/D/E/F/G) have the same tester role

This is my codes I've written so far: @Test(priority = 1, description = "AM-2641 Bulk Actions - Select All to Set Roles") @Severity(SeverityLevel.MINOR) @Description("Test Description: To verify user is able Select All Datasets to Set Roles.") public void AM_2641() {

    Response allDatasets = APIHelper.getRequest(DATASETS, ADMIN, new HashMap<>(), new HashMap<>());
    List<String> datasets = allDatasets.jsonPath().getList("name");
    String role = "tester";

    user.dataSetManagementPage()
            .verifyCheckboxesArePresent("name", datasets)
            .clickButtonInTopPanel(BULK_ACTIONS)
            .clickOnButtonWithTitleInBulkActions("bulk-select-all", "bulk-select-all")
            .verifyCheckboxesAreSelected("name", datasets, true)
            .clickButtonInTopPanel(BULK_ACTIONS)
            .clickOnButtonWithTitleInBulkActions("bulk-set-roles", "bulk-set-roles")
            .selectRoleInSetRoles(role, true)
            .clickButtonInDialog(OK)
            .verifyCheckboxesAreSelected("name", datasets, true)
            .verifyValueAtRowAndColumnEqualToExpectationInDatasetsList("Roles", datasets.toString(), role);
}

However the ".verifyValueAtRowAndColumnEqualToExpectationInDatasetsList("Roles", datasets.toString(), role);" could not verify the list has the expected role of a tester. It could only verify one user has the tester role.

This is the method:

@Step
protected void verifyValueAtRowAndColumnEqualToExpectation(String columnName, String rowName, String expectation) {
    List<WebElement> tableColumns = waitUntilElementsAreVisible(By.cssSelector(columnHeaderXpath));
    List<WebElement> tableRows = waitUntilElementsAreVisible(By.cssSelector(allFirstCells));
    int columnIndex = 0;
    int rowIndex = 0;
    for (int i = 0; i < tableColumns.size(); i++) {
        if (tableColumns.get(i).getText().equals(columnName)) {
            //get the index of the desired column
            columnIndex = i + 1;
            break;
        }
    }
    Assert.assertNotEquals(columnIndex, 0, String.format("Did not find any column with name '%s'\n", columnName));
    //option by default = 0 for most of the tables. only some special tables required optional in the child method
    if (optional != 0) {
        columnIndex = columnIndex + optional;
    }
    log.info("Found the column '" + columnName + "' at index " + columnIndex);
    boolean rowIsFound = false;
    for (int i = 0; i < tableRows.size(); i++) {
        if (tableRows.get(i).getText().equals(rowName)) {
            //exclude the first row
            //rowIndex by default = 2 to exclude the first row for common table.
            rowIndex += this.rowIndex + i;
            log.info("Found the row '" + rowName + "' at index :" + rowIndex);
            rowIsFound = true;
            break;
        }
    }
    Assert.assertTrue(rowIsFound, "Did not find any row '" + rowName + "'.");
    String cellToVerify = String.format(verifyXpath, rowIndex, columnIndex);
    log.info("The selector to verify is: " + cellToVerify);
    String actualValue = driver.findElement(By.cssSelector(cellToVerify)).getText();
    log.info("Actual value is: " + actualValue);
    log.info("Expectation value is: " + expectation);
    Assert.assertEquals(actualValue, expectation);
}

I expected a verification on a list of users/sample datas have the same role.

What can I do? Please help

0

There are 0 best solutions below