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

Commit

Permalink
Enforced validations webdriver tests
Browse files Browse the repository at this point in the history
Test that setting validations for a version are enforced in the editor.
  • Loading branch information
djansen-redhat committed Oct 10, 2013
1 parent a75f861 commit b2b2d67
Show file tree
Hide file tree
Showing 8 changed files with 560 additions and 6 deletions.
4 changes: 4 additions & 0 deletions functional-test/src/main/java/org/zanata/page/BasePage.java
Expand Up @@ -255,6 +255,10 @@ public void waitForSideMenuOpened() {
.className("off-canvas--right-under")));
}

public boolean expectNoCriticalErrors() {
return getDriver().findElements(By.id("errorMessage")).size() <= 0;
}

public void assertNoCriticalErrors() {
List<WebElement> errors =
getDriver().findElements(By.id("errorMessage"));
Expand Down
@@ -0,0 +1,132 @@
/*
* Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.page.projects;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.zanata.page.AbstractPage;
import org.zanata.util.TableRow;
import org.zanata.util.WebElementUtil;

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

/**
* @author Damian Jansen <a
* href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class EditVersionPage extends AbstractPage {

public enum ValidationLevel {
OFF, WARNING, ERROR
}

private static int NAME_COLUMN = 0;
private static int DESCRIPTION_COLUMN = 1;
private static int OPTION_COLUMN = 2;

@FindBy(id = "iterationForm:validationOptionsTable")
private WebElement validationOptionsTable;

public EditVersionPage(WebDriver driver) {
super(driver);
}

/**
* Set a level for a validation option
* @param optionName The option to set, e.g. HTML/XML tags
* @param level the level to set to, ie. Off, Warning or Error
* @return new EditVersionPage
*/
public EditVersionPage setValidationLevel(String optionName, String level) {
String cssPath = ".//input[@value='" + level + "']";
getValidationOption(optionName).getCells().get(OPTION_COLUMN)
.findElement(By.xpath(cssPath)).click();
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
//
}
return new EditVersionPage(getDriver());
}

/**
* Query a validation option, determine if is set to a level
* @param optionName The option to query, e.g. HTML/XML tags
* @param level the expected level setting, ie. Off, Warning or Error
* @return new EditVersionPage
*/
public boolean isValidationLevel(String optionName, String level) {
String cssPath = ".//*[@value='" + level + "']";
WebElement option =
getValidationOption(optionName).getCells().get(OPTION_COLUMN)
.findElement(By.xpath(cssPath));
return option.getAttribute("checked").equals("true");
}

/**
* Press the Update button
* @return new EditVersionPage
*/
public ProjectVersionPage clickUpdate() {
getDriver().findElement(By.id("iterationForm:update")).click();
return new ProjectVersionPage(getDriver());
}

private TableRow getValidationOption(final String optionName) {
TableRow matchedRow =
waitForTenSec().until(new Function<WebDriver, TableRow>() {
@Override
public TableRow apply(WebDriver driver) {
List<TableRow> tableRows = WebElementUtil.
getTableRows(getDriver(), driver.findElement(By
.id("iterationForm:validationOptionsTable")));
Optional<TableRow> matchedRow =
Iterables.tryFind(tableRows,
new Predicate<TableRow>() {
@Override
public boolean
apply(TableRow input) {
List<String> cellContents =
input.getCellContents();
String nameCell =
cellContents.get(
NAME_COLUMN)
.trim();
return nameCell
.equalsIgnoreCase(
optionName);
}
});

// we keep looking for the option until timeout
return matchedRow.isPresent() ? matchedRow.get() : null;
}
});
return matchedRow;
}
}
Expand Up @@ -43,6 +43,9 @@ public class ProjectVersionPage extends BasePage {
@FindBy(linkText = "Source Documents")
private WebElement sourceDocumentsButton;

@FindBy(linkText = "Edit Version")
private WebElement editVersionButton;

public ProjectVersionPage(final WebDriver driver) {
super(driver);
}
Expand Down Expand Up @@ -113,4 +116,9 @@ public ProjectSourceDocumentsPage goToSourceDocuments() {
sourceDocumentsButton.click();
return new ProjectSourceDocumentsPage(getDriver());
}

public EditVersionPage editVersion() {
editVersionButton.click();
return new EditVersionPage(getDriver());
}
}
Expand Up @@ -26,4 +26,9 @@ public List<List<String>> getDocumentListTableContent() {
By.id("gwt-debug-documentListTable"));
}

public EditorPage selectDocument(String documentName) {
getDriver().findElement(By.id("gwt-debug-docLabel-"+documentName)).click();
return new EditorPage(getDriver());
}

}

0 comments on commit b2b2d67

Please sign in to comment.