diff --git a/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/GlobalRightsAdministrationSectionPage.java b/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/GlobalRightsAdministrationSectionPage.java index b91c1547a4fe..e6031e828560 100644 --- a/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/GlobalRightsAdministrationSectionPage.java +++ b/xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-test/xwiki-platform-administration-test-pageobjects/src/main/java/org/xwiki/administration/test/po/GlobalRightsAdministrationSectionPage.java @@ -24,6 +24,9 @@ import org.openqa.selenium.support.FindBy; import org.xwiki.test.ui.po.EditRightsPane; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * Represents the actions possible on the Global Rights Administration Page. * @@ -68,9 +71,9 @@ public void unforceAuthenticatedView() private void setAuthenticatedView(boolean enabled) { - String desiredAltValue = enabled ? "yes" : "no"; - - if (!this.forceAuthenticatedViewLink.getAttribute("alt").equals(desiredAltValue)) { + String desiredCheckedValue = enabled ? "checked" : null; + String initialCheckedValue = this.forceAuthenticatedViewLink.getAttribute("checked"); + if (initialCheckedValue == null || !initialCheckedValue.equals(desiredCheckedValue)) { this.forceAuthenticatedViewLink.click(); // Wait for the setting to apply. Wait longer than usual in this case in an attempt to avoid some false @@ -78,8 +81,13 @@ private void setAuthenticatedView(boolean enabled) int defaultTimeout = getDriver().getTimeout(); try { getDriver().setTimeout(defaultTimeout * 2); - getDriver().waitUntilElementHasAttributeValue( - By.id(this.forceAuthenticatedViewLink.getAttribute("id")), "alt", desiredAltValue); + if (enabled) { + getDriver().waitUntilElementHasAttributeValue( + By.id(this.forceAuthenticatedViewLink.getAttribute("id")), "checked", "true"); + } else { + getDriver().waitUntilCondition(driver -> + this.forceAuthenticatedViewLink.getAttribute("checked") == null); + } } finally { // Restore the utils timeout for other tests. getDriver().setTimeout(defaultTimeout); diff --git a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/EditRightsPane.java b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/EditRightsPane.java index e12f06920978..7a99db3bdae6 100644 --- a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/EditRightsPane.java +++ b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-ui/src/main/java/org/xwiki/test/ui/po/EditRightsPane.java @@ -56,15 +56,15 @@ public String toString() /** The possible states of an access right box. */ public enum State { - NONE("/xwiki/resources/js/xwiki/usersandgroups/img/none.png"), - ALLOW("/xwiki/resources/js/xwiki/usersandgroups/img/allow.png"), - DENY("/xwiki/resources/js/xwiki/usersandgroups/img/deny1.png"); + NONE("none"), + ALLOW("yes"), + DENY("no"); - String imageURL; + String buttonClass; - State(String imageURL) + State(String buttonClass) { - this.imageURL = imageURL; + this.buttonClass = buttonClass; } State getNextState() @@ -72,12 +72,12 @@ State getNextState() return values()[(ordinal() + 1) % values().length]; } - static State getButtonImageState(WebElement button) + static State getButtonState(WebElement button) { for (State s : values()) { // The URL may contain query string parameters (e.g. starting with 11.1RC1 the resource URLs can now // contain a query parameter to avoid cache issue) and we don't care about that to identify the state. - if ((button.getAttribute("src").contains(s.imageURL))) { + if ((button.getAttribute("class").contains(s.buttonClass))) { return s; } } @@ -119,9 +119,9 @@ public State getGuestRight(Right right) */ public State getGuestRight(String rightName) { - final By iconLocator = By.xpath(String.format("//tr[@id='unregistered']/td[@data-title='%s']/button/img", rightName)); - final WebElement icon = getDriver().findElement(iconLocator); - return State.getButtonImageState(icon); + final By buttonLocator = By.xpath(String.format("//tr[@id='unregistered']/td[@data-title='%s']/button", rightName)); + final WebElement button = getDriver().findElement(buttonLocator); + return State.getButtonState(button); } public State getRight(String entityName, Right right) @@ -139,13 +139,13 @@ public State getRight(String entityName, Right right) */ public State getRight(String entityName, String rightName) { - final By iconLocator = + final By buttonLocator = By.xpath(String.format( "//*[@id='usersandgroupstable-display']//tr[./td[@class='username']//a[contains(@href, '%s')]]" - + "/td[@data-title='%s']/button/img", + + "/td[@data-title='%s']/button", entityName, rightName)); - final WebElement icon = getDriver().findElement(iconLocator); - return State.getButtonImageState(icon); + final WebElement button = getDriver().findElement(buttonLocator); + return State.getButtonState(button); } public boolean hasEntity(String entityName) @@ -172,15 +172,15 @@ public void clickGuestRight(String rightName) getDriver().executeJavascript( "window.__oldConfirm = window.confirm; window.confirm = function() { return true; };"); final By buttonLocator = By.xpath( - String.format("*//tr[@id='unregistered']/td[@data-title='%s']/button/img", rightName)); + String.format("*//tr[@id='unregistered']/td[@data-title='%s']/button", rightName)); final WebElement button = getDriver().findElement(buttonLocator); - State currentState = State.getButtonImageState(button); + State currentState = State.getButtonState(button); button.click(); // Note: Selenium 2.0a4 returns a relative URL when calling getAttribute("src") but since we moved to // Selenium 2.0a7 it returns a *full* URL even though the DOM has a relative URL as in: // - getDriver().waitUntilElementContainsAttributeValue(buttonLocator, "src", - currentState.getNextState().imageURL); + getDriver().waitUntilElementContainsAttributeValue(buttonLocator, "class", + currentState.getNextState().buttonClass); } finally { getDriver().executeJavascript("window.confirm = window.__oldConfirm;"); } @@ -212,14 +212,14 @@ public void clickRight(String entityName, String rightName) final By buttonLocator = By.xpath( String.format("//*[@id='usersandgroupstable-display']//tr[./td[@class='username']" - + "//a[contains(@href, '%s')]]/td[@data-title='%s']/button/img", entityName, rightName)); + + "//a[contains(@href, '%s')]]/td[@data-title='%s']/button", entityName, rightName)); final WebElement button = getDriver().findElement(buttonLocator); - State currentState = State.getButtonImageState(button).getNextState(); + State currentState = State.getButtonState(button).getNextState(); button.click(); // Note: Selenium 2.0a4 returns a relative URL when calling getAttribute("src") but since we moved to // Selenium 2.0a7 it returns a *full* URL even though the DOM has a relative URL as in: // - getDriver().waitUntilElementContainsAttributeValue(buttonLocator, "src", currentState.imageURL); + getDriver().waitUntilElementContainsAttributeValue(buttonLocator, "class", currentState.buttonClass); } finally { getDriver().executeJavascript("window.confirm = window.__oldConfirm;"); }