Search in sources :

Example 1 with UIUtils.getTextFromElement

use of org.keycloak.testsuite.util.UIUtils.getTextFromElement in project keycloak by keycloak.

the class GroupPolicyForm method populate.

public void populate(GroupPolicyRepresentation expected, boolean save) {
    UIUtils.setTextInputValue(name, expected.getName());
    UIUtils.setTextInputValue(description, expected.getDescription());
    UIUtils.setTextInputValue(groupsClaim, expected.getGroupsClaim());
    logic.selectByValue(expected.getLogic().name());
    for (GroupPolicyRepresentation.GroupDefinition definition : toRepresentation().getGroups()) {
        boolean isExpected = false;
        for (GroupPolicyRepresentation.GroupDefinition expectedDef : expected.getGroups()) {
            if (definition.getPath().equals(expectedDef.getPath())) {
                isExpected = true;
                break;
            }
        }
        if (!isExpected) {
            unselect(definition.getPath());
        }
    }
    for (GroupPolicyRepresentation.GroupDefinition definition : expected.getGroups()) {
        String path = definition.getPath();
        String groupName = path.substring(path.lastIndexOf('/') + 1);
        WebElement element = driver.findElement(By.xpath("//span[text()='" + groupName + "']"));
        element.click();
        waitUntilElement(selectGroupButton).is().enabled();
        selectGroupButton.click();
        driver.findElements(By.xpath("(//table[@id='selected-groups'])/tbody/tr")).stream().filter(webElement -> webElement.findElements(tagName("td")).size() > 1).map(webElement -> webElement.findElements(tagName("td"))).filter(tds -> UIUtils.getTextFromElement(tds.get(0)).equals(definition.getPath())).forEach(tds -> {
            if (!tds.get(1).findElement(By.tagName("input")).isSelected()) {
                if (definition.isExtendChildren()) {
                    tds.get(1).findElement(By.tagName("input")).click();
                }
            } else {
                if (!definition.isExtendChildren() && tds.get(1).findElement(By.tagName("input")).isSelected()) {
                    tds.get(1).findElement(By.tagName("input")).click();
                }
            }
        });
    }
    if (save) {
        save();
    }
}
Also used : WaitUtils.waitUntilElement(org.keycloak.testsuite.util.WaitUtils.waitUntilElement) Form(org.keycloak.testsuite.page.Form) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) By(org.openqa.selenium.By) WebDriver(org.openqa.selenium.WebDriver) UIUtils(org.keycloak.testsuite.util.UIUtils) WebElement(org.openqa.selenium.WebElement) Page(org.jboss.arquillian.graphene.page.Page) HashSet(java.util.HashSet) List(java.util.List) ModalDialog(org.keycloak.testsuite.console.page.fragment.ModalDialog) Drone(org.jboss.arquillian.drone.api.annotation.Drone) Logic(org.keycloak.representations.idm.authorization.Logic) Select(org.openqa.selenium.support.ui.Select) UIUtils.getTextFromElement(org.keycloak.testsuite.util.UIUtils.getTextFromElement) By.tagName(org.openqa.selenium.By.tagName) FindBy(org.openqa.selenium.support.FindBy) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) WebElement(org.openqa.selenium.WebElement)

Example 2 with UIUtils.getTextFromElement

use of org.keycloak.testsuite.util.UIUtils.getTextFromElement in project keycloak by keycloak.

the class GroupPolicyForm method toRepresentation.

public GroupPolicyRepresentation toRepresentation() {
    GroupPolicyRepresentation representation = new GroupPolicyRepresentation();
    representation.setName(UIUtils.getTextInputValue(name));
    representation.setDescription(UIUtils.getTextInputValue(description));
    String groupsClaimValue = UIUtils.getTextInputValue(groupsClaim);
    representation.setGroupsClaim(groupsClaim == null || "".equals(groupsClaimValue.trim()) ? null : groupsClaimValue);
    representation.setLogic(Logic.valueOf(UIUtils.getTextFromElement(logic.getFirstSelectedOption()).toUpperCase()));
    representation.setGroups(new HashSet<>());
    driver.findElements(By.xpath("(//table[@id='selected-groups'])/tbody/tr")).stream().filter(webElement -> webElement.findElements(tagName("td")).size() > 1).forEach(webElement -> {
        List<WebElement> tds = webElement.findElements(tagName("td"));
        representation.addGroupPath(getTextFromElement(tds.get(0)), tds.get(1).findElement(tagName("input")).isSelected());
    });
    return representation;
}
Also used : WaitUtils.waitUntilElement(org.keycloak.testsuite.util.WaitUtils.waitUntilElement) Form(org.keycloak.testsuite.page.Form) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) By(org.openqa.selenium.By) WebDriver(org.openqa.selenium.WebDriver) UIUtils(org.keycloak.testsuite.util.UIUtils) WebElement(org.openqa.selenium.WebElement) Page(org.jboss.arquillian.graphene.page.Page) HashSet(java.util.HashSet) List(java.util.List) ModalDialog(org.keycloak.testsuite.console.page.fragment.ModalDialog) Drone(org.jboss.arquillian.drone.api.annotation.Drone) Logic(org.keycloak.representations.idm.authorization.Logic) Select(org.openqa.selenium.support.ui.Select) UIUtils.getTextFromElement(org.keycloak.testsuite.util.UIUtils.getTextFromElement) By.tagName(org.openqa.selenium.By.tagName) FindBy(org.openqa.selenium.support.FindBy) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) WebElement(org.openqa.selenium.WebElement)

Aggregations

HashSet (java.util.HashSet)2 List (java.util.List)2 Drone (org.jboss.arquillian.drone.api.annotation.Drone)2 Page (org.jboss.arquillian.graphene.page.Page)2 GroupPolicyRepresentation (org.keycloak.representations.idm.authorization.GroupPolicyRepresentation)2 Logic (org.keycloak.representations.idm.authorization.Logic)2 ModalDialog (org.keycloak.testsuite.console.page.fragment.ModalDialog)2 Form (org.keycloak.testsuite.page.Form)2 UIUtils (org.keycloak.testsuite.util.UIUtils)2 UIUtils.getTextFromElement (org.keycloak.testsuite.util.UIUtils.getTextFromElement)2 WaitUtils.waitUntilElement (org.keycloak.testsuite.util.WaitUtils.waitUntilElement)2 By (org.openqa.selenium.By)2 By.tagName (org.openqa.selenium.By.tagName)2 WebDriver (org.openqa.selenium.WebDriver)2 WebElement (org.openqa.selenium.WebElement)2 FindBy (org.openqa.selenium.support.FindBy)2 Select (org.openqa.selenium.support.ui.Select)2