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

Commit

Permalink
Merge remote branch 'origin/master' into rhbz1023247
Browse files Browse the repository at this point in the history
Conflicts:
	zanata-war/src/test/java/org/zanata/seam/SeamAutowire.java
  • Loading branch information
seanf committed Nov 14, 2013
2 parents 4780722 + eae31dd commit bff0b12
Show file tree
Hide file tree
Showing 136 changed files with 2,748 additions and 905 deletions.
Expand Up @@ -20,11 +20,15 @@
*/
package org.zanata.page.projects;

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 org.zanata.util.Constants;

import java.util.Map;

public class CreateProjectPage extends BasePage {
@FindBy(id = "projectForm:slugField:slug")
Expand All @@ -36,29 +40,55 @@ public class CreateProjectPage extends BasePage {
@FindBy(id = "projectForm:descriptionField:description")
private WebElement descriptionField;

@FindBy(id = "projectForm:homeContentField:homeContentTextArea")
private WebElement homeContentTextArea;

@FindBy(id = "projectForm:projectTypeField:selectField")
private WebElement projectTypeSelect;

@FindBy(id =
"projectForm:humanViewableSourceUrlField:humanViewableSourceUrl")
private WebElement viewSourceURLField;

@FindBy(id = "projectForm:"+
"machineReadableSourceUrlField:machineReadableSourceUrl")
private WebElement downloadSourceURLField;

@FindBy(id = "cke_projectForm:homeContentField:homeContent:inp")
private WebElement homeContentTextArea;

@FindBy(id = "projectForm:statusField:selectField")
private WebElement statusSelection;

@FindBy(id = "projectForm:save")
private WebElement saveButton;

private static final Map<String, String> projectTypeOptions =
Constants.projectTypeOptions();

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

public CreateProjectPage inputProjectId(String projectId) {
projectIdField.sendKeys(projectId);
return this;
defocus();
return new CreateProjectPage(getDriver());
}

public CreateProjectPage inputProjectName(final String projectName) {
getDriver().findElement(By.id("projectForm:nameField:name"))
.sendKeys(projectName);
defocus();
return new CreateProjectPage(getDriver());
}

public CreateProjectPage inputProjectName(String projectName) {
projectNameField.sendKeys(projectName);
public CreateProjectPage enterDescription(String projectDescription) {
descriptionField.sendKeys(projectDescription);
defocus();
return new CreateProjectPage(getDriver());
}

public CreateProjectPage selectProjectType(String projectType) {
new Select(projectTypeSelect)
.selectByVisibleText(projectTypeOptions.get(projectType));
return this;
}

Expand All @@ -67,6 +97,21 @@ public CreateProjectPage selectStatus(String status) {
return this;
}

public CreateProjectPage enterViewSourceURL(String url) {
viewSourceURLField.sendKeys(url);
return this;
}

public CreateProjectPage enterDownloadSourceURL(String url) {
downloadSourceURLField.sendKeys(url);
return this;
}

public CreateProjectPage enterHomepageContent(String content) {
homeContentTextArea.sendKeys(content);
return this;
}

public ProjectPage saveProject() {
clickAndCheckErrors(saveButton);
return new ProjectPage(getDriver());
Expand Down
Expand Up @@ -21,7 +21,6 @@
package org.zanata.page.projects;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -33,6 +32,7 @@
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;
import org.zanata.page.BasePage;
import org.zanata.util.Constants;

public class CreateVersionPage extends BasePage {

Expand All @@ -46,20 +46,7 @@ public class CreateVersionPage extends BasePage {
private WebElement saveButton;

private static final Map<String, String> projectTypeOptions =
new HashMap<String, String>();
static {
projectTypeOptions.put("File",
"File. For plain text, LibreOffice, InDesign.");
projectTypeOptions.put("Gettext",
"Gettext. For gettext software strings.");
projectTypeOptions.put("Podir", "Podir. For publican/docbook strings.");
projectTypeOptions.put("Properties",
"Properties. For Java properties files.");
projectTypeOptions.put("Utf8Properties",
"Utf8Properties. For UTF8-encoded Java properties.");
projectTypeOptions.put("Xliff", "Xliff. For supported XLIFF files.");
projectTypeOptions.put("Xml", "Xml. For XML from the Zanata REST API.");
}
Constants.projectTypeOptions();

public CreateVersionPage(final WebDriver driver) {
super(driver);
Expand Down
Expand Up @@ -20,6 +20,7 @@
*/
package org.zanata.page.projects;

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

Expand Down Expand Up @@ -107,4 +108,15 @@ public ProjectMaintainersPage clickManageMaintainers() {
getDriver().findElement(By.linkText("Manage Maintainers")).click();
return new ProjectMaintainersPage(getDriver());
}

public List<String> getContentAreaParagraphs() {
List<String> paragraphTexts = new ArrayList<String>();
List<WebElement> paragraphs = getDriver()
.findElement(By.className("content_box"))
.findElements(By.tagName("p"));
for (WebElement element : paragraphs) {
paragraphTexts.add(element.getText());
}
return paragraphTexts;
}
}
Expand Up @@ -21,6 +21,7 @@
package org.zanata.page.projects;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -80,4 +81,48 @@ public List<String> getProjectNamesOnCurrentPage() {
return WebElementUtil.getColumnContents(getDriver(), projectTableBy,
PROJECT_NAME_COLUMN);
}

/**
* Wait for a project name to be shown or hidden in the list.
* The list may take several seconds to reload.
* @param projectName name of the desired project
* @param visible is or is not visible
*/
public void waitForProjectVisibility(final String projectName,
final boolean visible) {
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return getProjectNamesOnCurrentPage()
.contains(projectName) == visible;
}
});
}

public ProjectsPage setActiveFilterEnabled(boolean enabled) {
WebElement activeCheckbox = getDriver()
.findElement(By.xpath("//*[@title='Filter active projects']"));
if (activeCheckbox.isSelected() != enabled) {
activeCheckbox.click();
}
return new ProjectsPage(getDriver());
}

public ProjectsPage setReadOnlyFilterEnabled(final boolean enabled) {
WebElement readOnlyCheckbox = getDriver().findElement(
By.xpath("//*[@title='Filter read-only projects']"));
if (readOnlyCheckbox.isSelected() != enabled) {
readOnlyCheckbox.click();
}
return new ProjectsPage(getDriver());
}

public ProjectsPage setObsoleteFilterEnabled(boolean enabled) {
WebElement readOnlyCheckbox = getDriver().findElement(
By.xpath("//*[@title='Filter obsolete projects']"));
if (readOnlyCheckbox.isSelected() != enabled) {
readOnlyCheckbox.click();
}
return new ProjectsPage(getDriver());
}
}
20 changes: 20 additions & 0 deletions functional-test/src/main/java/org/zanata/util/Constants.java
Expand Up @@ -22,6 +22,9 @@

import com.google.common.base.Objects;

import java.util.HashMap;
import java.util.Map;

public enum Constants {
// constants used by page and workflow objects
propFile("setup.properties"), zanataInstance("zanata.instance.url"),
Expand Down Expand Up @@ -50,4 +53,21 @@ public String toString() {
public String value() {
return value;
}

public static Map<String, String> projectTypeOptions() {
Map<String, String> projectTypeOptions = new HashMap<String, String>();
projectTypeOptions.put("None", "-- No selection --");
projectTypeOptions.put("File",
"File. For plain text, LibreOffice, InDesign.");
projectTypeOptions.put("Gettext",
"Gettext. For gettext software strings.");
projectTypeOptions.put("Podir", "Podir. For publican/docbook strings.");
projectTypeOptions.put("Properties",
"Properties. For Java properties files.");
projectTypeOptions.put("Utf8Properties",
"Utf8Properties. For UTF8-encoded Java properties.");
projectTypeOptions.put("Xliff", "Xliff. For supported XLIFF files.");
projectTypeOptions.put("Xml", "Xml. For XML from the Zanata REST API.");
return projectTypeOptions;
}
}
Expand Up @@ -20,6 +20,7 @@
*/
package org.zanata.workflow;

import java.util.HashMap;
import java.util.List;

import org.zanata.page.projects.CreateVersionPage;
Expand All @@ -30,14 +31,22 @@

@Slf4j
public class ProjectWorkFlow extends AbstractWebWorkFlow {
public ProjectPage createNewProject(String projectId, String projectName) {

/**
* Creates a new project using minimal input, all other items are default.
* This function is lenient, i.e. will not fail if the project exists.
* @param projectId Project identifier
* @param projectName Project short name
* @return new Project page for created project
*/
public ProjectPage createNewSimpleProject(String projectId,
String projectName) {
ProjectsPage projectsPage = goToHome().goToProjects();
List<String> projects = projectsPage.getProjectNamesOnCurrentPage();
log.info("current projects: {}", projects);

if (projects.contains(projectName)) {
log.warn(
"{} has already been created. Presumably you are running test manually and more than once.",
log.warn("{} already exists. This test environment is not clean.",
projectId);
// since we can't create same project multiple times,
// if we run this test more than once manually, we don't want it to
Expand All @@ -49,6 +58,42 @@ public ProjectPage createNewProject(String projectId, String projectName) {
.saveProject();
}

/**
* Create a project in full, using the details given in settings.<br/>
* All items must be defined.
* @param settings A HashMap of project identifiers and settings
* @return a new Project page for the created project
* @see {@link #projectDefaults()}
*/
public ProjectPage createNewProject(HashMap<String, String> settings) {
ProjectsPage projectsPage = goToHome().goToProjects();
List<String> projects = projectsPage.getProjectNamesOnCurrentPage();
log.info("current projects: {}", projects);
return projectsPage.clickOnCreateProjectLink()
.inputProjectId(settings.get("Project ID"))
.inputProjectName(settings.get("Name"))
.enterDescription(settings.get("Description"))
.selectProjectType(settings.get("Project Type"))
.enterHomepageContent(settings.get("Homepage Content"))
.enterViewSourceURL(settings.get("View source files"))
.enterDownloadSourceURL(settings.get("Source Download/Checkout"))
.selectStatus(settings.get("Status"))
.saveProject();
}

public static HashMap<String, String> projectDefaults() {
HashMap<String, String> defaults = new HashMap<String, String>();
defaults.put("Project ID", "");
defaults.put("Name", "");
defaults.put("Description", "");
defaults.put("Project Type", "None");
defaults.put("Homepage Content", "");
defaults.put("View source files", "");
defaults.put("Source Download/Checkout", "");
defaults.put("Status", "ACTIVE");
return defaults;
}

/**
* By default this will create a podir project version
*
Expand Down
Expand Up @@ -45,7 +45,7 @@ public void pushTransMemoryProject() {

ProjectWorkFlow projectWorkFlow = new ProjectWorkFlow();
ProjectPage projectPage =
projectWorkFlow.createNewProject("trans-memory",
projectWorkFlow.createNewSimpleProject("trans-memory",
"trans memory test");
projectWorkFlow.createNewProjectVersion("trans memory test", "master");

Expand All @@ -65,7 +65,7 @@ public void pushTransMemoryProjectWithDifferentProjectName() {

ProjectWorkFlow projectWorkFlow = new ProjectWorkFlow();
ProjectPage projectPage =
projectWorkFlow.createNewProject("trans-memory-v2",
projectWorkFlow.createNewSimpleProject("trans-memory-v2",
"trans memory test v2");
projectWorkFlow.createNewProjectVersion("trans memory test v2",
"master");
Expand Down

0 comments on commit bff0b12

Please sign in to comment.