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

Commit

Permalink
Fix test element focus issues
Browse files Browse the repository at this point in the history
In some cases, element.blur works more reliably than a page click
  • Loading branch information
djansen-redhat committed Jan 20, 2015
1 parent 0e9518c commit acb8349
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 13 deletions.
9 changes: 9 additions & 0 deletions functional-test/src/main/java/org/zanata/page/CorePage.java
Expand Up @@ -193,6 +193,15 @@ public void defocus() {
}
}

/**
* Force the blur 'unfocus' process on a given element
*/
public void defocus(By elementBy) {
log.info("Force unfocus");
WebElement element = getDriver().findElement(elementBy);
((JavascriptExecutor) getDriver()).executeScript("arguments[0].blur()", element);
}

/* The system sometimes moves too fast for the Ajax pages, so provide a
* pause
*/
Expand Down
Expand Up @@ -47,7 +47,7 @@ public EditProfilePage enterName(String name) {
log.info("Enter name {}", name);
waitForWebElement(nameField).clear();
waitForWebElement(nameField).sendKeys(name);
defocus();
defocus(nameField);
return new EditProfilePage(getDriver());
}

Expand All @@ -62,7 +62,7 @@ public EditProfilePage enterEmail(String email) {
log.info("Enter email {}", email);
waitForWebElement(emailField).clear();
waitForWebElement(emailField).sendKeys(email);
defocus();
defocus(emailField);
return new EditProfilePage(getDriver());
}

Expand Down
Expand Up @@ -53,7 +53,7 @@ public class RegisterPage extends CorePage {

private By nameField = By.id("loginForm:name");
private By emailField = By.id("loginForm:emailField:email");
private By usernameField = By.id("loginForm:usernameField:username");
public By usernameField = By.id("loginForm:usernameField:username");
private By passwordField = By.id("loginForm:passwordField:password");
private By signUpButton = By.xpath("//input[@value='Sign Up']");
private By showHideToggleButton = By.className("js-form-password-toggle");
Expand Down
Expand Up @@ -73,7 +73,7 @@ public ProjectGeneralTab enterProjectName(final String projectName) {
log.info("Enter project name {}", projectName);
waitForWebElement(projectNameField).clear();
waitForWebElement(projectNameField).sendKeys(projectName);
defocus();
defocus(projectNameField);
return new ProjectGeneralTab(getDriver());
}

Expand All @@ -86,7 +86,7 @@ public ProjectGeneralTab enterDescription(String projectDescription) {
log.info("Enter project description {}", projectDescription);
waitForWebElement(descriptionField).clear();
waitForWebElement(descriptionField).sendKeys(projectDescription);
defocus();
defocus(descriptionField);
return new ProjectGeneralTab(getDriver());
}

Expand Down
Expand Up @@ -37,7 +37,7 @@ public class CreateVersionPage extends BasePage {
"must start and end with letter or number, and contain only " +
"letters, numbers, periods, underscores and hyphens.";

private By projectVersionID = By.id("create-version-form:slugField:slug");
public By projectVersionID = By.id("create-version-form:slugField:slug");
private By projectTypeSelection = By.id("create-version-form:project-type");
private By saveButton = By.id("create-version-form:button-create");
private By copyFromPreviousVersionChk = By.id("create-version-form:copy-from-version");
Expand Down
Expand Up @@ -130,7 +130,7 @@ public void usernamePreExisting() throws Exception {
RegisterPage registerPage = homePage
.goToRegistration()
.enterUserName("admin");
registerPage.defocus();
registerPage.defocus(registerPage.usernameField);

assertThat(registerPage.expectError(
RegisterPage.USERNAME_UNAVAILABLE_ERROR))
Expand Down
Expand Up @@ -48,7 +48,7 @@ public void usernameCharacterValidation() throws Exception {
.goToHome()
.goToRegistration()
.enterUserName("user|name");
registerPage.defocus();
registerPage.defocus(registerPage.usernameField);

assertThat(registerPage.expectError(
RegisterPage.USERNAME_VALIDATION_ERROR))
Expand Down
Expand Up @@ -85,7 +85,7 @@ public void idFieldMustNotBeEmpty() throws Exception {
.goToProjectByName("about fedora")
.clickCreateVersionLink()
.inputVersionId("");
createVersionPage.defocus();
createVersionPage.defocus(createVersionPage.projectVersionID);

assertThat(createVersionPage.getErrors())
.contains("value is required")
Expand All @@ -101,23 +101,23 @@ public void idStartsAndEndsWithAlphanumeric() throws Exception {
.goToProjectByName("about fedora")
.clickCreateVersionLink()
.inputVersionId("-A");
createVersionPage.defocus();
createVersionPage.defocus(createVersionPage.projectVersionID);

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

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

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

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

assertThat(createVersionPage.expectError(
Expand All @@ -126,7 +126,7 @@ public void idStartsAndEndsWithAlphanumeric() throws Exception {
.as("The input is rejected");

createVersionPage = createVersionPage.inputVersionId("A-B_C");
createVersionPage.defocus();
createVersionPage.defocus(createVersionPage.projectVersionID);
createVersionPage = createVersionPage.waitForNumErrors(0);

assertThat(createVersionPage.getErrors())
Expand Down

0 comments on commit acb8349

Please sign in to comment.