[KEYCLOAK-2697] Fix some UI tests stability

This commit is contained in:
Vaclav Muzikar 2016-03-22 13:57:23 +01:00
parent 705a598ce6
commit 25363a91f9
6 changed files with 32 additions and 25 deletions

View file

@ -1,6 +1,7 @@
package org.keycloak.testsuite.console.page.authentication;
import org.jboss.arquillian.graphene.findby.ByJQuery;
import org.keycloak.testsuite.page.Form;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -14,6 +15,7 @@ import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
* @author Petr Mensik
* @author tkyjovsk
* @author mhajas
* @author Vaclav Muzikar <vmuzikar@redhat.com>
*/
public class PasswordPolicy extends Authentication {
@ -28,10 +30,10 @@ public class PasswordPolicy extends Authentication {
@FindBy(tagName = "select")
private WebElement addPolicySelectElement;
@FindBy(css = "tr.ng-scope")
private List<WebElement> allRows;
@FindBy(tagName = "table")
private WebElement table;
public void addPolicy(PasswordPolicy.Type policy, String value) {
public void addPolicy(Type policy, String value) {
waitUntilElement(addPolicySelectElement).is().present();
addPolicySelect.selectByVisibleText(policy.getName());
setPolicyValue(policy, value);
@ -39,45 +41,36 @@ public class PasswordPolicy extends Authentication {
}
public void addPolicy(PasswordPolicy.Type policy, int value) {
public void addPolicy(Type policy, int value) {
addPolicy(policy, String.valueOf(value));
}
public void addPolicy(PasswordPolicy.Type policy) {
public void addPolicy(Type policy) {
addPolicySelect.selectByVisibleText(policy.getName());
primaryButton.click();
}
public void removePolicy(PasswordPolicy.Type policy) {
int policyInputLocation = findPolicy(policy);
allRows.get(policyInputLocation).findElements(By.tagName("button")).get(0).click();
public void removePolicy(Type policy) {
getPolicyRow(policy).findElement(By.cssSelector("td.kc-action-cell")).click();
primaryButton.click();
}
public void editPolicy(PasswordPolicy.Type policy, int value) {
public void editPolicy(Type policy, int value) {
editPolicy(policy, String.valueOf(value));
}
public void editPolicy(PasswordPolicy.Type policy, String value) {
public void editPolicy(Type policy, String value) {
setPolicyValue(policy, value);
primaryButton.click();
}
private void setPolicyValue(PasswordPolicy.Type policy, String value) {
int policyInputLocation = findPolicy(policy);
WebElement input = allRows.get(policyInputLocation).findElement(By.tagName("input"));
input.clear();
input.sendKeys(value);
private void setPolicyValue(Type policy, String value) {
WebElement input = getPolicyRow(policy).findElement(By.tagName("input"));
Form.setInputValue(input, value);
}
private int findPolicy(PasswordPolicy.Type policy) {
for (int i = 0; i < allRows.size(); i++) {
String policyName = allRows.get(i).findElement(ByJQuery.selector("td:eq(0)")).getText();
if (policyName.equals(policy.getName())) {
return i;
}
}
return 0;
private WebElement getPolicyRow(Type policy) {
return table.findElement(By.xpath("//tr[td[text()='" + policy.getName() + "']]"));
}
public enum Type {

View file

@ -1,5 +1,6 @@
package org.keycloak.testsuite.console.page.authentication;
import org.keycloak.testsuite.util.WaitUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -28,6 +29,8 @@ public class RequiredActions extends Authentication {
}
private void setRequiredActionValue(String id, boolean value) {
WaitUtils.waitUntilElement(requiredActionTable).is().present();
WebElement checkbox = requiredActionTable.findElement(By.id(id));
if (checkbox.isSelected() != value) {

View file

@ -191,6 +191,10 @@ public class LdapUserProviderForm extends Form {
vendorSelect.selectByVisibleText(vendor);
}
public void selectVendor(int index) {
vendorSelect.selectByIndex(index);
}
public List<String> getVendors() {
waitUntilElement(By.id("vendor")).is().present();

View file

@ -1,6 +1,8 @@
package org.keycloak.testsuite.console.page.realm;
import org.keycloak.testsuite.console.page.AdminConsoleRealm;
import org.keycloak.testsuite.util.WaitUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
@ -11,11 +13,14 @@ import static org.keycloak.testsuite.util.WaitUtils.*;
* @author tkyjovsk
*/
public class RealmSettings extends AdminConsoleRealm {
private static final String navTabsClassName = "nav-tabs";
@FindBy(className = "nav-tabs")
@FindBy(className = navTabsClassName)
private RealmTabs realmTabs;
public RealmTabs tabs() {
waitUntilElement(By.className(navTabsClassName)).is().present();
return realmTabs;
}

View file

@ -32,6 +32,7 @@ import org.keycloak.testsuite.console.page.authentication.otppolicy.OTPPolicy;
import org.keycloak.testsuite.console.page.authentication.otppolicy.OTPPolicyForm.Digits;
import org.keycloak.testsuite.console.page.authentication.otppolicy.OTPPolicyForm.OTPHashAlg;
import org.keycloak.testsuite.console.page.authentication.otppolicy.OTPPolicyForm.OTPType;
import org.keycloak.testsuite.util.WaitUtils;
/**
*
@ -45,6 +46,7 @@ public class OTPPolicyTest extends AbstractConsoleTest {
@Before
public void beforeOTPPolicyTest() {
otpPolicyPage.navigateTo();
WaitUtils.pause(1000); // wait for the form to fully render
}
@Test

View file

@ -133,7 +133,7 @@ public class LdapUserFederationTest extends AbstractConsoleTest {
@Test
public void testConnection() throws Exception {
createLdapUserProvider.navigateTo();
createLdapUserProvider.form().selectVendor("Other");
createLdapUserProvider.form().selectVendor(1);
createLdapUserProvider.form().setConsoleDisplayNameInput("ldap");
createLdapUserProvider.form().selectEditMode(WRITABLE);
createLdapUserProvider.form().setLdapConnectionUrlInput("ldap://localhost:10389");