This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforced validations webdriver tests
Test that setting validations for a version are enforced in the editor.
- Loading branch information
1 parent
a75f861
commit b2b2d67
Showing
8 changed files
with
560 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
functional-test/src/main/java/org/zanata/page/projects/EditVersionPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.