All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.onevizion.uitest.api.helper.grid.group.GridGroup Maven / Gradle / Ivy

package com.onevizion.uitest.api.helper.grid.group;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.testng.Assert;

import com.onevizion.uitest.api.AbstractSeleniumCore;
import com.onevizion.uitest.api.SeleniumSettings;
import com.onevizion.uitest.api.helper.Element;
import com.onevizion.uitest.api.helper.Js;
import com.onevizion.uitest.api.vo.ConfigFieldType;

@Component
public class GridGroup {

    public static final String EMPTY_GROUP_NAME = "Undefined";

    private static final String CLASS_GROUP = "group_row";

    @Autowired
    private SeleniumSettings seleniumSettings;

    @Autowired
    private Js js;

    @Autowired
    private GridGroupJs gridGroupJs;

    @Autowired
    private Element element;

    public void checkGridIsGrouped(Long gridIdx) {
        int count = getGroups(gridIdx).size();
        Assert.assertEquals(count > 0, true, "Grid is not grouped");
    }

    public void checkGridIsUngrouped(Long gridIdx) {
        int count = getGroups(gridIdx).size();
        Assert.assertEquals(count == 0, true, "Grid is grouped");
    }

    public void checkGroupsCount(Long gridIdx, int groupsCount) {
        int count = getGroups(gridIdx).size();
        Assert.assertEquals(count, groupsCount, "Wrong groups count");
    }

    public void checkGroupLabel(Long gridIdx, int position, String groupLabel) {
        String actualGroupLabel = getGroups(gridIdx).get(position - 1).getAttribute("innerText").trim();
        Assert.assertEquals(actualGroupLabel, groupLabel, "Wrong group label");
    }

    public void collapseOrExpandGroup(Long gridIdx, int position) {
        WebElement group = getGroups(gridIdx).get(position - 1);
        element.click(group);
    }

    private List getGroups(Long gridIdx) {
        seleniumSettings.getWebDriver().manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
        List groups = seleniumSettings.getWebDriver().findElements(By.xpath("//*[@id='" + AbstractSeleniumCore.GRID_ID_BASE + gridIdx + "']//*[contains(@class, '" + CLASS_GROUP + "')][label]"));
        seleniumSettings.getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        return groups;
    }

    public void checkRowsInGroup(Long gridIdx, ConfigFieldType configFieldType, String group, String columnLabel, List columnVals) {
        String groupId = getGroupId(gridIdx, configFieldType, group);
        int columnIndex = js.getColumnIndexByLabel(gridIdx, columnLabel);

        List actualColumnVals = gridGroupJs.getColumnValsInGroup(gridIdx, columnIndex, groupId);
        Assert.assertEquals(actualColumnVals, columnVals);
    }

    private String getGroupId(Long gridIdx, ConfigFieldType configFieldType, String group) {
        if (EMPTY_GROUP_NAME.equals(group)) {
            return " ";
        }

        if (ConfigFieldType.CHECKBOX.equals(configFieldType)) {
            if ("Yes".equals(group)) {
                return "1";
            } else {
                return "0";
            }
        } else if (ConfigFieldType.DROP_DOWN.equals(configFieldType)) {
            return gridGroupJs.getGroupId(gridIdx, group);
        } else {
            return group;
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy