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

Commit

Permalink
WIP: functional test for group page
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Nov 21, 2013
1 parent 860821e commit d9adad2
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 188 deletions.
@@ -1,16 +1,16 @@
package org.zanata.page.groups;

import java.util.ArrayList;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;
import org.zanata.page.BasePage;

import java.util.List;

import com.google.common.collect.ImmutableList;

/**
Expand All @@ -19,32 +19,26 @@
*/
@Slf4j
public class CreateVersionGroupPage extends BasePage {
@FindBy(id = "projectForm:slugField:slug")
@FindBy(id = "group-form:slugField:slug")
private WebElement groupSlugField;

@FindBy(id = "projectForm:nameField:name")
@FindBy(id = "group-form:nameField:name")
private WebElement groupNameField;

@FindBy(id = "projectForm:descriptionField:description")
@FindBy(id = "group-form:descriptionField:description")
private WebElement groupDescriptionField;

@FindBy(tagName = "Select")
private WebElement groupStatusSelection;

@FindBy(id = "projectForm:save")
@FindBy(id = "group-form:group-create-new")
private WebElement saveButton;

@FindBy(className = "errors")
private WebElement groupSlugFieldError;

public CreateVersionGroupPage(WebDriver driver) {
super(driver);
List<By> elementBys =
ImmutableList.<By> builder()
.add(By.id("projectForm:slugField:slug"))
.add(By.id("projectForm:nameField:name"))
.add(By.id("projectForm:descriptionField:description"))
.add(By.id("projectForm:save")).build();
.add(By.id("group-form:slugField:slug"))
.add(By.id("group-form:nameField:name"))
.add(By.id("group-form:descriptionField:description"))
.add(By.id("group-form:group-create-new")).build();
waitForPage(elementBys);
}

Expand All @@ -63,18 +57,13 @@ public CreateVersionGroupPage inputGroupDescription(String desc) {
return this;
}

public CreateVersionGroupPage selectStatus(String status) {
new Select(groupStatusSelection).selectByVisibleText(status);
return this;
}

public VersionGroupsPage saveGroup() {
clickAndCheckErrors(saveButton);
return new VersionGroupsPage(getDriver());
}

public CreateVersionGroupPage saveGroupFailure() {
clickAndExpectErrors(saveButton);
clickAndCheckErrors(saveButton);
return new CreateVersionGroupPage(getDriver());
}

Expand All @@ -84,4 +73,14 @@ public CreateVersionGroupPage clearFields() {
groupDescriptionField.clear();
return new CreateVersionGroupPage(getDriver());
}

public List<String> getFieldValidationErrors() {
List<WebElement> elements =
getDriver().findElements(By.className("message--danger"));
List<String> errors = new ArrayList<String>();
for (WebElement element : elements) {
errors.add(element.getText());
}
return errors;
}
}
@@ -1,7 +1,7 @@
package org.zanata.page.groups;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import java.util.ArrayList;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

Expand All @@ -15,61 +15,35 @@
import org.zanata.util.TableRow;
import org.zanata.util.WebElementUtil;

import java.util.List;
import com.google.common.base.Function;

/**
* @author Patrick Huang <a
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Slf4j
public class VersionGroupPage extends BasePage {
@FindBy(linkText = "Add Project Versions")
private WebElement addProjectVersionsLink;

@FindBy(id = "versionAddPanel_container")
private WebElement addProjectVersionPanel;

@FindBy(id = "iterationGroupForm:iterationsDataTable")
private WebElement groupDataTable;

private By versionsInGroupTableBy = By
.id("iterationGroupForm:iterationsDataTable");
private By versionsInGroupTableBy = By.id("projects-project_list");

public VersionGroupPage(final WebDriver driver) {
super(driver);
}

public VersionGroupPage addProjectVersion() {
addProjectVersionsLink.click();
waitForTenSec().until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
return addProjectVersionPanel.findElement(By
.id("projectVersionSearch:searchForm:searchField"));
}
});
return new VersionGroupPage(getDriver());
}

public List<List<String>> searchProject(final String projectName,
final int expectedResultNum) {
WebElement searchField =
addProjectVersionPanel.findElement(By
.id("projectVersionSearch:searchForm:searchField"));
searchField.sendKeys(projectName);
@FindBy(id = "settings-projects-form:newVersionField:newVersionInput")
private WebElement projectSearchField;

WebElement searchButton =
addProjectVersionPanel.findElement(By
.id("projectVersionSearch:searchForm:searchBtn"));
searchButton.click();
private final By newVersionListBy = By
.id("settings-projects-form:newVersionField:newVersionItems");

final By tableBy =
By.id("projectVersionSearch:searchResults:resultTable");
public List<WebElement> searchProject(final String projectName,
final int expectedResultNum) {
projectSearchField.sendKeys(projectName);

return refreshPageUntil(this,
new Function<WebDriver, List<List<String>>>() {
new Function<WebDriver, List<WebElement>>() {
@Override
public List<List<String>> apply(WebDriver driver) {
public List<WebElement> apply(WebDriver driver) {
// we want to wait until search result comes back. There
// is no way we can tell whether search result has come
// back and table refreshed.
Expand All @@ -78,67 +52,45 @@ public List<List<String>> apply(WebDriver driver) {
// (http://seleniumhq.org/exceptions/stale_element_reference.html),
// we have to set expected result num

List<List<String>> tableContents =
WebElementUtil.getTwoDimensionList(getDriver(),
tableBy);
List<WebElement> listItems =
WebElementUtil.getListItems(getDriver(),
newVersionListBy);

if (tableContents.size() != expectedResultNum) {
if (listItems.size() != expectedResultNum) {
log.debug("waiting for search result refresh...");
return null;
}
return tableContents;
return listItems;
}
});
}

public VersionGroupPage addToGroup(int rowIndex) {
WebElement table =
addProjectVersionPanel.findElement(By
.id("projectVersionSearch:searchResults:resultTable"));

List<WebElement> cells =
WebElementUtil.getTableRows(getDriver(), table).get(rowIndex)
.getCells();
WebElement actionCell = cells.get(cells.size() - 1);
if (!actionCell.getText().contains("Already in Group")) {
WebElement selectCheckBox =
actionCell.findElement(By
.xpath(".//input[@type='checkbox']"));
if (!selectCheckBox.isSelected()) {
selectCheckBox.click();
}
}

WebElement addSelected =
addProjectVersionPanel
.findElement(By
.id("projectVersionSearch:searchResults:addSelectedBtn"));
addSelected.click();
return this;
}
List<WebElement> listItems =
WebElementUtil.getListItems(getDriver(), newVersionListBy);

listItems.get(rowIndex).click();

public VersionGroupPage closeSearchResult(final int expectedRow) {
WebElement closeButton =
addProjectVersionPanel.findElement(By
.id("projectVersionSearch:searchForm:closeBtn"));
closeButton.click();
return refreshPageUntil(this, new Predicate<WebDriver>() {
@Override
public boolean apply(@javax.annotation.Nullable WebDriver input) {
List<TableRow> tableRows =
WebElementUtil.getTableRows(input,
versionsInGroupTableBy);
int size = tableRows.size();
log.info("table rows: {}", tableRows);
return size == expectedRow;
}
});
WebElement addButton =
getDriver().findElement(By.id("group-add-new-project-button"));
addButton.click();
return this;
}

@SuppressWarnings("unused")
public List<List<String>> getProjectVersionsInGroup() {
return WebElementUtil.getTwoDimensionList(getDriver(),
versionsInGroupTableBy);
public List<String> getProjectVersionsInGroup() {

List<WebElement> elements =
WebElementUtil
.getListItems(getDriver(), versionsInGroupTableBy);

List<String> result = new ArrayList<String>();

for (WebElement element : elements) {
result.add(element.getText());
}
return result;
}

public String getProjectName(int row) {
Expand Down Expand Up @@ -182,4 +134,9 @@ public ProjectVersionPage clickOnProjectVersionLinkOnRow(int row) {
versionLink.click();
return new ProjectVersionPage(getDriver());
}

public void clickOnTab(String tabId) {
WebElement tab = getDriver().findElement(By.id(tabId));
tab.click();
}
}
Expand Up @@ -40,7 +40,7 @@ public List<String> getGroupNames() {

public CreateVersionGroupPage createNewGroup() {
WebElement createLink =
getDriver().findElement(By.linkText("Create New Group"));
getDriver().findElement(By.id("group-create"));
createLink.click();
return new CreateVersionGroupPage(getDriver());
}
Expand Down
19 changes: 16 additions & 3 deletions functional-test/src/main/java/org/zanata/util/WebElementUtil.java
Expand Up @@ -20,7 +20,11 @@
*/
package org.zanata.util;

import java.util.*;
import static java.util.concurrent.TimeUnit.SECONDS;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
Expand All @@ -36,8 +40,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import static java.util.concurrent.TimeUnit.*;

public class WebElementUtil {
private WebElementUtil() {
}
Expand Down Expand Up @@ -167,6 +169,17 @@ public List<List<String>> apply(WebDriver input) {
});
}

public static List<WebElement> getListItems(WebDriver driver, final By by) {
return waitForTenSeconds(driver).until(
new Function<WebDriver, List<WebElement>>() {
@Override
public List<WebElement> apply(WebDriver input) {
final WebElement list = input.findElement(by);
return list.findElements(By.xpath(".//li"));
}
});
}

private static class WebElementToInnerHTMLFunction implements
Function<WebElement, String> {
private final WebDriver driver;
Expand Down

0 comments on commit d9adad2

Please sign in to comment.