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

Commit

Permalink
Merge pull request #355 from zanata/glossary-admin-test
Browse files Browse the repository at this point in the history
Add automated test for glossary page.
  • Loading branch information
Patrick Huang committed Feb 5, 2014
2 parents daa321c + 3c1c75e commit d5f089d
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 2 deletions.
7 changes: 7 additions & 0 deletions functional-test/src/main/java/org/zanata/page/BasePage.java
Expand Up @@ -33,6 +33,7 @@
import org.zanata.page.account.RegisterPage;
import org.zanata.page.account.SignInPage;
import org.zanata.page.administration.AdministrationPage;
import org.zanata.page.glossary.GlossaryPage;
import org.zanata.page.groups.VersionGroupsPage;
import org.zanata.page.projects.ProjectsPage;
import org.zanata.page.utility.HomePage;
Expand Down Expand Up @@ -92,6 +93,12 @@ public VersionGroupsPage goToGroups() {
return new VersionGroupsPage(getDriver());
}

public GlossaryPage goToGlossary() {
// Dynamically find the link, as it is not present for every user
getDriver().findElement(By.id("glossary_link")).click();
return new GlossaryPage(getDriver());
}

public AdministrationPage goToAdministration() {
userAvatar.click();

Expand Down
@@ -0,0 +1,63 @@
/*
* 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.page.glossary;

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

/**
* @author Carlos Munoz <a
* href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
@Slf4j
public class GlossaryPage extends BasePage {

@FindBy(id = "glossary_form:data_table")
private WebElement glossaryTable;

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

public List<String> getAvailableGlossaryLanguages() {
return WebElementUtil.getColumnContents(getDriver(),
By.id("glossary_form:data_table"), 0);
}

public int getGlossaryEntryCount(String lang) {
List<String> langs = getAvailableGlossaryLanguages();
int row = langs.indexOf(lang);
if (row >= 0) {
return Integer
.parseInt(WebElementUtil.getColumnContents(getDriver(),
By.id("glossary_form:data_table"), 2).get(row));
}
return -1;
}
}
@@ -0,0 +1,94 @@
/*
* 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.glossary;

import lombok.extern.slf4j.Slf4j;

import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestRule;
import org.zanata.feature.DetailedTest;
import org.zanata.page.glossary.GlossaryPage;
import org.zanata.util.SampleProjectRule;
import org.zanata.workflow.ClientPushWorkFlow;
import org.zanata.workflow.LoginWorkFlow;

import java.io.File;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.greaterThan;

/**
* @author Carlos Munoz <a
* href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
@Category(DetailedTest.class)
@Slf4j
public class GlossaryAdminTest {

@Rule
public TestRule sampleProjectRule = new SampleProjectRule();

private ClientPushWorkFlow clientPushWorkFlow = new ClientPushWorkFlow();

/**
* Validates that a pushed glossary appears in the Glossary table.
* After pushing, a table with Glossary statistics should be shown.
* Validate that the the number of glossary entries per language matches
* the number of entries pushed from each of the test cases metnioned in the
* Setup.
* @see TCMS Test Case 181711
*/
@Test
public void testGlossaryView() {
// Push a glossary
File projectRootPath =
clientPushWorkFlow.getProjectRootPath("glossary");
String userConfigPath =
ClientPushWorkFlow.getUserConfigPath("glossaryadmin");

List<String> result =
clientPushWorkFlow
.callWithTimeout(
projectRootPath,
"mvn --batch-mode zanata:glossary-push -Dglossary.lang=hi -Dzanata.glossaryFile=compendium.csv -Dzanata.userConfig="
+ userConfigPath);

assertThat(clientPushWorkFlow.isPushSuccessful(result),
Matchers.is(true));

// Make sure glossary shows up on the page
GlossaryPage glossaryPage =
new LoginWorkFlow().signIn("admin", "admin").goToGlossary();
List<String> langs = glossaryPage.getAvailableGlossaryLanguages();

assertThat(langs.size(), greaterThan(0));
assertThat(langs, containsInAnyOrder("pl", "hi", "en-US"));
assertThat(glossaryPage.getGlossaryEntryCount("pl"), greaterThan(1));
assertThat(glossaryPage.getGlossaryEntryCount("hi"), greaterThan(1));
assertThat(glossaryPage.getGlossaryEntryCount("en-US"), greaterThan(1));
}
}
Expand Up @@ -15,7 +15,8 @@
GlossaryPushCSVTest.class,
UnauthorizedGlossaryDeleteTest.class,
UnauthorizedGlossaryPushTest.class,
GlossaryDeleteTest.class
GlossaryDeleteTest.class,
GlossaryAdminTest.class
})
// @formatter:on
public class GlossaryTestSuite {
Expand Down
2 changes: 1 addition & 1 deletion zanata-war/src/main/webapp/glossary/view.xhtml
Expand Up @@ -99,7 +99,7 @@

<ui:define name="page_title">#{messages['jsf.Glossary']}</ui:define>
<ui:define name="center_content">
<h:form>
<h:form id="glossary_form">
<s:token allowMultiplePosts="true"/>
<rich:dataTable id="data_table" width="100%"
value="#{glossaryAction.getStats()}" var="language"
Expand Down

0 comments on commit d5f089d

Please sign in to comment.