Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Change the way we wait for errors in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Feb 17, 2015
1 parent 95cff3e commit 2949c09
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 42 deletions.
22 changes: 11 additions & 11 deletions functional-test/src/main/java/org/zanata/page/CorePage.java
Expand Up @@ -120,21 +120,21 @@ public boolean apply(WebDriver input) {
}

/**
* Wait until an expected error is visible
* Wait until at least one error is visible
*
* @param expected The expected error string
* @return The full list of visible errors
*/
public List<String> expectError(final String expected) {
String msg = "expected error: " + expected;
public List<String> expectErrors() {
waitForPageSilence();
String msg = "an error message";
logWaiting(msg);
waitForAMoment().withMessage(msg).until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
List<String> errors = getErrors();
return errors.contains(expected);
}
});
// waitForAMoment().withMessage(msg).until(new Predicate<WebDriver>() {
// @Override
// public boolean apply(WebDriver input) {
// List<String> errors = getErrors();
// return !errors.isEmpty();
// }
// });
return getErrors();
}

Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.zanata.page.BasePage;
import org.zanata.page.utility.HomePage;

/**
* @author Damian Jansen <a
Expand Down Expand Up @@ -59,14 +60,18 @@ public ResetPasswordPage clearFields() {
return new ResetPasswordPage(getDriver());
}

public ResetPasswordPage resetPassword() {
public HomePage resetPassword() {
log.info("Click Submit");
defocus(usernameField);
defocus(emailField);
waitForWebElement(submitButton).click();
return new ResetPasswordPage(getDriver());
return new HomePage(getDriver());
}

public ResetPasswordPage resetFailure() {
log.info("Click Submit");
defocus(usernameField);
defocus(emailField);
waitForWebElement(submitButton).click();
return new ResetPasswordPage(getDriver());
}
Expand Down
Expand Up @@ -80,7 +80,7 @@ public void validEmailAcceptance() throws Exception {
public void invalidEmailRejection() throws Exception {
registerPage = registerPage.enterEmail("plaintext").registerFailure();

assertThat(registerPage.expectError(RegisterPage.MALFORMED_EMAIL_ERROR))
assertThat(registerPage.expectErrors())
.contains(RegisterPage.MALFORMED_EMAIL_ERROR)
.as("The email formation error is displayed");
}
Expand Down
Expand Up @@ -129,8 +129,7 @@ public void emailValidationIsUsedOnProfileEdit() throws Exception {
.typeNewAccountEmailAddress("admin@example.com")
.clickUpdateEmailButton();

assertThat(dashboardAccountTab.expectError(
DashboardAccountTab.EMAIL_TAKEN_ERROR))
assertThat(dashboardAccountTab.expectErrors())
.contains(DashboardAccountTab.EMAIL_TAKEN_ERROR)
.as("The email is rejected, being already taken");

Expand All @@ -141,8 +140,7 @@ public void emailValidationIsUsedOnProfileEdit() throws Exception {
.typeNewAccountEmailAddress("test @example.com")
.clickUpdateEmailButton();

assertThat(dashboardAccountTab.expectError(
RegisterPage.MALFORMED_EMAIL_ERROR))
assertThat(dashboardAccountTab.expectErrors())
.contains(RegisterPage.MALFORMED_EMAIL_ERROR)
.as("The email is rejected, being of invalid format");
}
Expand Down
Expand Up @@ -132,8 +132,7 @@ public void usernamePreExisting() throws Exception {
.enterUserName("admin");
registerPage.defocus(registerPage.usernameField);

assertThat(registerPage.expectError(
RegisterPage.USERNAME_UNAVAILABLE_ERROR))
assertThat(registerPage.expectErrors())
.contains(RegisterPage.USERNAME_UNAVAILABLE_ERROR)
.as("Username not available message is shown");
}
Expand Down
Expand Up @@ -50,8 +50,7 @@ public void usernameCharacterValidation() throws Exception {
.enterUserName("user|name");
registerPage.defocus(registerPage.usernameField);

assertThat(registerPage.expectError(
RegisterPage.USERNAME_VALIDATION_ERROR))
assertThat(registerPage.expectErrors())
.contains(RegisterPage.USERNAME_VALIDATION_ERROR)
.as("Username validation errors are shown");
}
Expand Down
Expand Up @@ -106,8 +106,7 @@ public void translationMemoryIdsAreUnique() throws Exception {
.enterMemoryDescription("Meh")
.clickSaveAndExpectFailure();

assertThat(translationMemoryEditPage.expectError(
TranslationMemoryPage.ID_UNAVAILABLE))
assertThat(translationMemoryEditPage.expectErrors())
.contains(TranslationMemoryPage.ID_UNAVAILABLE)
.as("The Id Is Not Available error is displayed");

Expand All @@ -117,8 +116,7 @@ public void translationMemoryIdsAreUnique() throws Exception {
// RHBZ-1010771
translationMemoryEditPage.assertNoCriticalErrors();

assertThat(translationMemoryEditPage.expectError(
TranslationMemoryPage.ID_UNAVAILABLE))
assertThat(translationMemoryEditPage.expectErrors())
.contains(TranslationMemoryPage.ID_UNAVAILABLE)
.as("The Id Is Not Available error is displayed");
}
Expand Down
Expand Up @@ -104,25 +104,22 @@ public void idStartsAndEndsWithAlphanumeric() throws Exception {
.inputVersionId("-A");
createVersionPage.defocus(createVersionPage.projectVersionID);

assertThat(createVersionPage.expectError(
CreateVersionPage.VALIDATION_ERROR))
assertThat(createVersionPage.expectErrors())
.contains(CreateVersionPage.VALIDATION_ERROR)
.as("The input is rejected");

createVersionPage = createVersionPage.inputVersionId("B-");
createVersionPage.defocus(createVersionPage.projectVersionID);

assertThat(createVersionPage.expectError(
CreateVersionPage.VALIDATION_ERROR))
assertThat(createVersionPage.expectErrors())
.contains(CreateVersionPage.VALIDATION_ERROR)
.as("The input is rejected");

createVersionPage = createVersionPage.inputVersionId("_C_");
createVersionPage.defocus(createVersionPage.projectVersionID);
createVersionPage = createVersionPage.waitForNumErrors(1);

assertThat(createVersionPage.expectError(
CreateVersionPage.VALIDATION_ERROR))
assertThat(createVersionPage.expectErrors())
.contains(CreateVersionPage.VALIDATION_ERROR)
.as("The input is rejected");

Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.zanata.feature.testharness.TestPlan.BasicAcceptanceTest;
import org.zanata.feature.testharness.TestPlan.DetailedTest;
import org.zanata.page.account.ResetPasswordPage;
import org.zanata.page.utility.HomePage;
import org.zanata.util.AddUsersRule;
import org.zanata.util.EnsureLogoutRule;
import org.zanata.util.HasEmailRule;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void signInSuccessful() {
public void signInFailure() {
assertThat(new LoginWorkFlow()
.signInFailure("nosuchuser", "password")
.expectError("Login failed"))
.expectErrors())
.contains("Login failed")
.as("Log in error message is shown");
}
Expand All @@ -87,10 +88,10 @@ public void resetPasswordSuccessful() {
.clickSignInLink()
.goToResetPassword()
.enterUserName("admin")
.enterEmail("admin@example.com")
.resetPassword();
.enterEmail("admin@example.com");
HomePage homePage = resetPasswordPage.resetPassword();

assertThat(resetPasswordPage.getNotificationMessage())
assertThat(homePage.getNotificationMessage())
.isEqualTo("You will soon receive an email with a link to " +
"reset your password.");

Expand Down Expand Up @@ -137,7 +138,7 @@ public void invalidResetPasswordFieldEntries() {
.enterEmail("b")
.resetFailure();

assertThat(resetPasswordPage.expectError("not a well-formed email address"))
assertThat(resetPasswordPage.expectErrors())
.contains("not a well-formed email address")
.as("Invalid email error is displayed");

Expand All @@ -161,7 +162,7 @@ public void emptyResetPasswordFieldEntries() {
.clearFields()
.resetFailure();

assertThat(resetPasswordPage.expectError("may not be empty"))
assertThat(resetPasswordPage.expectErrors())
.contains("may not be empty")
.as("Empty email error is displayed");

Expand Down
Expand Up @@ -26,12 +26,10 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openqa.selenium.By;
import org.zanata.feature.Feature;
import org.zanata.feature.testharness.ZanataTestCase;
import org.zanata.feature.testharness.TestPlan.BasicAcceptanceTest;
import org.zanata.feature.testharness.TestPlan.DetailedTest;
import org.zanata.page.dashboard.DashboardBasePage;
import org.zanata.page.groups.CreateVersionGroupPage;
import org.zanata.page.groups.VersionGroupPage;
import org.zanata.page.groups.VersionGroupsPage;
Expand Down Expand Up @@ -219,8 +217,7 @@ public void inputValidationForID() throws Exception {
groupPage.defocus(groupPage.groupNameField);
groupPage.saveGroupFailure();

assertThat(groupPage.expectError(
CreateVersionGroupPage.VALIDATION_ERROR))
assertThat(groupPage.expectErrors())
.contains(CreateVersionGroupPage.VALIDATION_ERROR)
.as("Validation error is displayed for " + inputText);
}
Expand Down

0 comments on commit 2949c09

Please sign in to comment.