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

Commit

Permalink
Translation Memory functional tests
Browse files Browse the repository at this point in the history
Tests: create, delete, import, clear, cancel clear/delete/delete after clear.
Update to data sql script as some tables have changed.
  • Loading branch information
djansen-redhat committed Sep 26, 2013
1 parent 6f83d98 commit 23615eb
Show file tree
Hide file tree
Showing 10 changed files with 683 additions and 11 deletions.
21 changes: 17 additions & 4 deletions functional-test/src/main/java/org/zanata/page/AbstractPage.java
Expand Up @@ -24,10 +24,7 @@
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.*;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.openqa.selenium.support.ui.FluentWait;
Expand Down Expand Up @@ -143,6 +140,22 @@ public WebElement apply(WebDriver driver)
}
}

public Alert switchToAlert()
{
return waitForTenSec().until(new Function<WebDriver, Alert>() {
@Override
public Alert apply(WebDriver driver) {
try {
return getDriver().switchTo().alert();
}
catch (NoAlertPresentException noAlertPresent)
{
return null;
}
}
});
}

protected <P extends AbstractPage> P refreshPageUntil(P currentPage, Predicate<WebDriver> predicate)
{
waitForTenSec().until(predicate);
Expand Down
Expand Up @@ -30,6 +30,8 @@ public class AdministrationPage extends BasePage

private final By MANAGE_USER_LINK = By.id("Admin_Manage_users_home");

private final By MANAGE_TM_LINK = By.id("Translation_Memory_home");

public AdministrationPage(WebDriver driver)
{
super(driver);
Expand All @@ -46,4 +48,10 @@ public ManageUserPage goToManageUserPage()
clickLinkAfterAnimation(MANAGE_USER_LINK);
return new ManageUserPage(getDriver());
}

public TranslationMemoryPage goToTranslationMemoryPage()
{
clickLinkAfterAnimation(MANAGE_TM_LINK);
return new TranslationMemoryPage(getDriver());
}
}
@@ -0,0 +1,81 @@
/*
* 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.administration;

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

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

@FindBy(id = "tmForm:slugField:slug")
private WebElement idField;

@FindBy(id = "tmForm:descriptionField:description")
private WebElement descriptionField;

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

@FindBy(id = "tmForm:cancel")
private WebElement cancelButton;

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

public TranslationMemoryEditPage enterMemoryID(String id)
{
idField.sendKeys(id);
return new TranslationMemoryEditPage(getDriver());
}

public TranslationMemoryEditPage enterMemoryDescription(String description)
{
descriptionField.sendKeys(description);
return new TranslationMemoryEditPage(getDriver());
}

public TranslationMemoryPage saveTM()
{
saveButton.click();
return new TranslationMemoryPage(getDriver());
}

public TranslationMemoryEditPage clickSaveAndExpectFailure()
{
saveButton.click();
return new TranslationMemoryEditPage(getDriver());
}

public TranslationMemoryPage cancelTM()
{
cancelButton.click();
return new TranslationMemoryPage(getDriver());
}

}
@@ -0,0 +1,203 @@
/*
* 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.administration;

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.openqa.selenium.*;
import org.openqa.selenium.support.FindBy;
import org.zanata.page.BasePage;
import org.zanata.util.TableRow;
import org.zanata.util.WebElementUtil;

import java.util.List;

/**
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class TranslationMemoryPage extends BasePage
{
private static final int ID_COLUMN = 0;
private static final int DESCRIPTION_COLUMN = 1;
private static final int ENTRIES_COLUMN = 2;
private static final int IMPORT_COLUMN = 4;
private static final int EXPORT_COLUMN = 5;
private static final int ACTIONS_COLUMN = 6;

@FindBy(id = "createTmLink")
private WebElement createTmLink;

@FindBy(id = "main_content:form:tmTable")
private WebElement tmList;

private By tmListBy = By.id("main_content:form:tmTable");

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

public TranslationMemoryEditPage clickCreateNew()
{
createTmLink.click();
return new TranslationMemoryEditPage(getDriver());
}

public TranslationMemoryPage clickImport(String tmName)
{
WebElement importButton = findRowByTMName(tmName)
.getCells()
.get(IMPORT_COLUMN)
.findElement(By.tagName("a"));
importButton.click();
return new TranslationMemoryPage(getDriver());
}

public TranslationMemoryPage enterImportFileName(String importFileName)
{
getDriver().findElement(By.name("uploadedFile")).sendKeys(importFileName);
return new TranslationMemoryPage(getDriver());
}

public TranslationMemoryPage clickUploadButtonAndAcknowledge()
{
getDriver().findElement(By.name("uploadBtn")).click();
switchToAlert().accept();
return new TranslationMemoryPage(getDriver());
}

public Alert expectFailedUpload()
{
getDriver().findElement(By.name("uploadBtn")).click();
return switchToAlert();
}

public TranslationMemoryPage clickClearTMAndAccept(String tmName)
{
clickTMAction(tmName, 0).accept();
return new TranslationMemoryPage(getDriver());
}

public TranslationMemoryPage clickClearTMAndCancel(String tmName)
{
clickTMAction(tmName, 0).dismiss();
return new TranslationMemoryPage(getDriver());
}

public TranslationMemoryPage clickDeleteTmAndAccept(String tmName)
{
clickTMAction(tmName, 1).accept();
return new TranslationMemoryPage(getDriver());
}

public TranslationMemoryPage clickDeleteTmAndCancel(String tmName)
{
clickTMAction(tmName, 1).dismiss();
return new TranslationMemoryPage(getDriver());
}

public TranslationMemoryPage dismissError()
{
switchToAlert().accept();
return new TranslationMemoryPage(getDriver());
}

public List<String> getListedTranslationMemorys()
{
return WebElementUtil.getColumnContents(getDriver(), tmListBy, ID_COLUMN);
}

public String getDescription(String tmName)
{
return findRowByTMName(tmName)
.getCells()
.get(DESCRIPTION_COLUMN)
.getText();
}

public String getNumberOfEntries(String tmName)
{
return findRowByTMName(tmName)
.getCells()
.get(ENTRIES_COLUMN)
.getText();
}

public String waitForExpectedNumberOfEntries(final String tmName, final String expected)
{
return waitForTenSec().until(new Function<WebDriver, String>() {
@Override
public String apply(WebDriver driver) {
return expected.equals(getNumberOfEntries(tmName)) ? getNumberOfEntries(tmName) : null;
}
});
}

public boolean canDelete(String tmName)
{
return findRowByTMName(tmName)
.getCells()
.get(ACTIONS_COLUMN)
.findElements(By.tagName("input"))
.get(1)
.isEnabled();
}

/*
* Get a row from the TM table that corresponds with tmName
*/
private TableRow findRowByTMName(final String tmName)
{
TableRow matchedRow = waitForTenSec().until(new Function<WebDriver, TableRow>()
{
@Override
public TableRow apply(WebDriver driver)
{
List<TableRow> tableRows = WebElementUtil.getTableRows(getDriver(), tmList);
Optional<TableRow> matchedRow = Iterables.tryFind(tableRows, new Predicate<TableRow>() {
@Override
public boolean apply(TableRow input) {
List<String> cellContents = input.getCellContents();
String localeCell = cellContents.get(ID_COLUMN).trim();
return localeCell.equalsIgnoreCase(tmName);
}
});

// Keep looking for the TM entry until timeout
return matchedRow.isPresent() ? matchedRow.get() : null;
}
});
return matchedRow;
}

private Alert clickTMAction(String tmName, int position)
{
findRowByTMName(tmName)
.getCells()
.get(ACTIONS_COLUMN)
.findElements(By.tagName("input"))
.get(position)
.click();
return switchToAlert();
}
}
15 changes: 12 additions & 3 deletions functional-test/src/main/java/org/zanata/util/WebElementUtil.java
Expand Up @@ -20,8 +20,7 @@
*/
package org.zanata.util;

import java.util.Collection;
import java.util.List;
import java.util.*;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
Expand Down Expand Up @@ -81,7 +80,6 @@ public static List<TableRow> getTableRows(WebDriver driver, final WebElement tab
@Override
public List<TableRow> apply(WebDriver webDriver)
{

List<WebElement> rows = table.findElements(By.xpath(".//tbody[1]/tr"));
return ImmutableList.copyOf(Lists.transform(rows, WebElementTableRowFunction.FUNCTION));
}
Expand Down Expand Up @@ -112,6 +110,16 @@ public static FluentWait<WebDriver> waitForTenSeconds(WebDriver webDriver)

public static List<String> getColumnContents(WebDriver driver, final By by, final int columnIndex)
{
try
{
driver.findElement(by);
}
catch(NoSuchElementException noElement)
{
// Some pages don't show a table, if there's no items to show
return Collections.emptyList();
}

return waitForTenSeconds(driver).until(new Function<WebDriver, List<String>>()
{
@Override
Expand All @@ -132,6 +140,7 @@ public String apply(TableRow from)
}));
}
});

}

public static List<List<String>> getTwoDimensionList(WebDriver driver, final By by)
Expand Down

0 comments on commit 23615eb

Please sign in to comment.