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

Commit

Permalink
Fix and add functional tests missing from the suite
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit d14e54a22451a8766ee539908ba5e5d68210d5d7
Author: Damian Jansen <djansen@redhat.com>
Date:   Thu Nov 6 23:30:28 2014 +1000

    Fix and simplify the version languages page

commit 463cb59c61c3c2e9caea180f99bc7d47812ca1f2
Author: Damian Jansen <djansen@redhat.com>
Date:   Fri Oct 24 13:06:03 2014 +1000

    Add a wait for the list of project type options

commit 741fbea9ac38a9f9e9ec08940f832a3f0a6dc03f
Author: Patrick Huang <pahuang@redhat.com>
Date:   Fri Oct 24 11:16:22 2014 +1000

    add special classname to source panel for webdriver finder

commit 6a1d4f59abe90c2529ba09b40ded71ad4f2659bf
Author: Damian Jansen <djansen@redhat.com>
Date:   Tue Oct 21 12:47:25 2014 +1000

    Fix and add tests missing from the test plan

    Some tests have not been run, as they were missing from the plan.
    Adds them and fixes the ones that broke during.
    Add category to some tests.
    Remove unused imports.
    Add license headers.
  • Loading branch information
djansen-redhat committed Nov 7, 2014
1 parent 0e095d2 commit 749d496
Show file tree
Hide file tree
Showing 48 changed files with 652 additions and 137 deletions.
Expand Up @@ -20,12 +20,14 @@
*/
package org.zanata.page.glossary;

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.zanata.page.BasePage;
import org.zanata.util.WebElementUtil;

Expand All @@ -36,26 +38,41 @@
@Slf4j
public class GlossaryPage extends BasePage {

private By glossaryTable = By.id("glossary_form:data_table");
private By glossaryMain = By.id("glossary_form");
private By entryCount = By.className("stats__figure");
private By listItem = By.className("list__item--actionable");
private By entryName = By.className("list__title");

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

public List<String> getAvailableGlossaryLanguages() {
log.info("Query available glossary languages");
return WebElementUtil.getColumnContents(getDriver(), glossaryTable, 0);
List<String> availableLanguages = new ArrayList<>();
for (WebElement element : getListItems()) {
availableLanguages.add(element.findElement(entryName)
.getText().trim());
}
return availableLanguages;

}

public int getGlossaryEntryCount(String lang) {
log.info("Query number of glossary entries for {}", lang);
List<String> langs = getAvailableGlossaryLanguages();
int row = langs.indexOf(lang);
List<WebElement> langs = getListItems();
int row = getAvailableGlossaryLanguages().indexOf(lang);
if (row >= 0) {
return Integer
.parseInt(WebElementUtil.getColumnContents(getDriver(),
glossaryTable, 2).get(row));
return Integer.parseInt(langs.get(row)
.findElement(entryCount).getText());
}
return -1;
}

private List<WebElement> getListItems() {
return waitForElementExists(
waitForElementExists(glossaryMain),
By.className("list--stats"))
.findElements(listItem);
}
}
Expand Up @@ -20,17 +20,15 @@
*/
package org.zanata.page.projectversion;

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.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.zanata.page.BasePage;
import org.zanata.util.Constants;

import java.util.List;
import java.util.Map;

@Slf4j
public class CreateVersionPage extends BasePage {
Expand All @@ -39,14 +37,13 @@ public class CreateVersionPage extends BasePage {
"must start and end with letter or number, and contain only " +
"letters, numbers, periods, underscores and hyphens.";

private By projectVersionID = By.id("create-version-form:slugField:slug");
private By projectTypeSelection = By.id("create-version-form:project-type");
private By statusSelection = By.id("create-version-form:statusField:status");
private By saveButton = By.id("create-version-form:button-create");
private By copyFromPreviousVersionChk = By.id("create-version-form:copy-from-version");
private By projectTypesList = By.id("create-version-form:project-type-list");

private static final Map<String, String> projectTypeOptions =
Constants.projectTypeOptions();
private By projectTypesList = By.id("create-version-form:project-type-list");
private By previousVersionsList = By.id("create-version-form:project-version");

public CreateVersionPage(final WebDriver driver) {
super(driver);
Expand All @@ -73,29 +70,78 @@ public boolean apply(WebDriver input) {
return new CreateVersionPage(getDriver());
}

public CreateVersionPage clickCopyFromVersion() {
log.info("Click Copy From Previous checkbox");
waitForWebElement(copyFromPreviousVersionChk).click();
private boolean isCopyFromVersionAvailable() {
return getDriver()
.findElements(copyFromPreviousVersionChk)
.size() > 0;
}

private void clickCopyFromCheckbox() {
((JavascriptExecutor) getDriver())
.executeScript("arguments[0].click();",
waitForWebElement(copyFromPreviousVersionChk)
.findElement(By.tagName("span")));

}

public CreateVersionPage enableCopyFromVersion() {
log.info("Set Copy From Previous checkbox");
if (!isCopyFromVersionAvailable()) {
log.warn("Copy Version not available!");
return this;
}
if (copyFromVersionIsChecked()) {
log.warn("Checkbox already enabled!");
} else {
clickCopyFromCheckbox();
}
waitForWebElement(previousVersionsList);
return this;
}

public CreateVersionPage disableCopyFromVersion() {
log.info("Unset Copy From Previous checkbox");
if (!isCopyFromVersionAvailable()) {
log.warn("Copy Version not available!");
return this;
}
if (!copyFromVersionIsChecked()) {
log.warn("Checkbox already disabled!");
} else {
clickCopyFromCheckbox();
}
waitForWebElement(projectTypesList);
return new CreateVersionPage(getDriver());
return this;
}

public boolean copyFromVersionIsChecked() {
log.info("Query is Copy from Version checkbox checked");
return waitForWebElement(copyFromPreviousVersionChk)
.findElement(By.tagName("input")).isSelected();
}

private WebElement getVersionIdField() {
log.info("Query Version ID");
return waitForWebElement(By.id("create-version-form:slugField:slug"));
return waitForWebElement(projectVersionID);
}

public CreateVersionPage selectProjectType(String projectType) {
public CreateVersionPage selectProjectType(final String projectType) {
log.info("Click project type {}", projectType);
List<WebElement> projectTypes = waitForWebElement(projectTypeSelection)
.findElements(By.tagName("li"));
for (WebElement projectTypeLi : projectTypes) {
if (projectTypeLi.findElement(By.xpath(".//div/label")).getText()
.startsWith(projectType)) {
projectTypeLi.findElement(By.xpath(".//div")).click();
break;
WebElement projectTypeCheck = waitForAMoment()
.until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver input) {
for (WebElement item : waitForWebElement(projectTypeSelection)
.findElements(By.tagName("li"))) {
if (item.findElement(By.tagName("label")).getText()
.startsWith(projectType)) {
return item;
}
}
return null;
}
}
});
projectTypeCheck.click();
return new CreateVersionPage(getDriver());
}

Expand Down
Expand Up @@ -28,7 +28,6 @@
import org.zanata.page.webtrans.EditorPage;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;

import lombok.extern.slf4j.Slf4j;

Expand All @@ -44,61 +43,71 @@ public VersionLanguagesPage(final WebDriver driver) {
super(driver);
}

private By languageList = By.id("languages-language_list");
private By languageItemTitle = By.className("list__item__meta");
private By languageItemStats = By.className("stats__figure");
private By languageDocumentList = By.id("languages-document_list");
private By documentListItem = By.className("list__item--actionable");
private By documentListItemTitle = By.className("list__title");

private List<WebElement> getLanguageTabLocaleList() {
return waitForWebElement(By.id("languages-language_list"))
.findElements(By.tagName("li"));
return waitForWebElement(languageList).findElements(By.tagName("li"));
}

public EditorPage translate(final String locale, final String docName) {
log.info("Click on {} : {} to begin translation", locale, docName);
gotoLanguageTab();
return refreshPageUntil(this, new Function<WebDriver, EditorPage>() {
@Override
public EditorPage apply(WebDriver driver) {
List<WebElement> localeList = getLanguageTabLocaleList();
for (WebElement localeRow : localeList) {
WebElement link = localeRow.findElement(By.xpath(".//a"));
if (link.findElement(By.className("list__item"))
.findElement(By.className("list__item__info"))
.findElement(By.className("list__item__meta"))
.getText().equals(locale)) {
clickLinkAfterAnimation(link);

List<WebElement> documentList =
getVersionTabDocumentList();
for (int i = 0; i < documentList.size(); i++) {
WebElement document = documentList.get(i);
if (document
.findElement(
By.xpath(".//a/div/div/h3[@class='list__title']"))
.getText().equals(docName)) {

clickLinkAfterAnimation(document.findElement(By
.id(i + ":" + "link-translate-options")));
private List<WebElement> getLanguageTabDocumentList() {
log.info("Query documents list");
return waitForWebElement(languageDocumentList)
.findElement(By.className("list--stats"))
.findElements(documentListItem);
}

clickLinkAfterAnimation(document
.findElement(
By.id(i
+ ":"
+ "link-translate-online"))
.findElement(By.tagName("a")));
public VersionLanguagesPage clickLocale(final String locale) {
log.info("Click locale {}", locale);
WebElement listItem = waitForAMoment()
.until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver input) {
for (WebElement localeRow : getLanguageTabLocaleList()) {
WebElement link = localeRow
.findElement(By.xpath(".//a")); // Top <a>
if (link.findElement(languageItemTitle)
.getText().equals(locale)) {
return link;
}
}
return null;
}
});
clickLinkAfterAnimation(listItem);
return new VersionLanguagesPage(getDriver());
}

return new EditorPage(getDriver());
public EditorPage clickDocument(final String docName) {
log.info("Click document {}", docName);
WebElement document = waitForAMoment()
.until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver input) {
for (WebElement document : getLanguageTabDocumentList()) {
if (waitForElementExists(document,
documentListItemTitle)
.getText().equals(docName)) {
return document
.findElement(documentListItemTitle);
}
}
return null;
}
}
throw new IllegalArgumentException("can not translate locale: "
+ locale);
}
});
});
clickLinkAfterAnimation(document);
return new EditorPage(getDriver());
}

private List<WebElement> getVersionTabDocumentList() {
log.info("Query documents list");
return waitForWebElement(
By.xpath("//form[@id='languages-document_list']/ul[@class='list--stats']"))
.findElements(By.tagName("li"));
public EditorPage translate(final String locale, final String docName) {
log.info("Click on {} : {} to begin translation", locale, docName);
return gotoLanguageTab()
.clickLocale(locale)
.clickDocument(docName);
}

public String getStatisticsForLocale(final String localeId) {
Expand All @@ -112,12 +121,10 @@ public String apply(WebDriver webDriver) {

List<WebElement> localeList = getLanguageTabLocaleList();
for (WebElement locale : localeList) {
if (locale.findElement(
By.xpath(".//a/div/div/span[@class='list__item__meta']"))
if (locale.findElement(languageItemTitle)
.getText()
.equals(localeId)) {
figure = locale.findElement(
By.xpath(".//a/div/div[2]/span/span[@class='stats__figure']"))
figure = locale.findElement(languageItemStats)
.getText();
break;
}
Expand Down
Expand Up @@ -138,7 +138,7 @@ public VersionLanguagesPage createNewProjectVersion(String projectName,
if (driver.findElements(By.id("create-version-form:copy-from-version"))
.size() > 0) {
createVersionPage = createVersionPage
.clickCopyFromVersion()
.disableCopyFromVersion()
.selectProjectType(versionType);
}
return createVersionPage.inputVersionId(versionID).saveVersion();
Expand Down
20 changes: 20 additions & 0 deletions functional-test/src/test/java/org/zanata/feature/Feature.java
@@ -1,3 +1,23 @@
/*
* Copyright 2014, 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.feature;

import java.lang.annotation.ElementType;
Expand Down
Expand Up @@ -22,7 +22,6 @@


import lombok.extern.slf4j.Slf4j;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.experimental.categories.Category;
Expand All @@ -35,7 +34,6 @@
import org.zanata.feature.testharness.ZanataTestCase;
import org.zanata.feature.testharness.TestPlan.DetailedTest;
import org.zanata.page.account.RegisterPage;
import org.zanata.page.utility.HomePage;
import org.zanata.util.EnsureLogoutRule;
import org.zanata.util.rfc2822.InvalidEmailAddressRFC2822;
import org.zanata.workflow.BasicWorkFlow;
Expand Down

0 comments on commit 749d496

Please sign in to comment.