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

Commit

Permalink
Fix functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Jun 28, 2015
1 parent 5c06532 commit a315251
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 36 deletions.
7 changes: 4 additions & 3 deletions functional-test/src/main/java/org/zanata/page/BasePage.java
Expand Up @@ -39,6 +39,7 @@
import org.zanata.page.languages.LanguagesPage;
import org.zanata.page.projects.ProjectVersionsPage;
import org.zanata.page.projects.ProjectsPage;
import org.zanata.page.search.SearchPage;
import org.zanata.page.utility.ContactAdminFormPage;
import org.zanata.page.utility.HomePage;
import org.zanata.util.WebElementUtil;
Expand Down Expand Up @@ -246,10 +247,10 @@ public BasePage enterSearch(String searchText) {
return new BasePage(getDriver());
}

public ProjectsPage submitSearch() {
log.info("Press Enter on Project search");
public SearchPage submitSearch() {
log.info("Press Enter on Zanata search");
existingElement(searchInput).sendKeys(Keys.ENTER);
return new ProjectsPage(getDriver());
return new SearchPage(getDriver());
}

public BasePage expectSearchListContains(final String expected) {
Expand Down
Expand Up @@ -40,14 +40,11 @@ public class ProjectsPage extends BasePage {
public static final int PROJECT_NAME_COLUMN = 0;

private By createProjectButton = By.id("createProjectLink");
private By searchProjectForm = By.id("search-project_form");
private By mainContentDiv = By.id("main_body_content");
private By projectTable = By.id("main_content:form:projectList");
private By activeCheckBox = By.xpath("//*[@data-original-title='Filter active projects']");
private By readOnlyCheckBox = By.xpath("//*[@data-original-title='Filter read-only projects']");

private By projectTabSearchPage = By.id("projects_tab");
private By userTabSearchPage = By.id("users_tab");

public ProjectsPage(final WebDriver driver) {
super(driver);
}
Expand Down Expand Up @@ -75,24 +72,15 @@ public ProjectVersionsPage apply(WebDriver input) {
}, "Find and go to project " + projectName);
}

public List<String> getProjectNamesOnSearchPage() {
public List<String> getProjectNamesOnCurrentPage() {
log.info("Query Projects list");
waitForPageSilence();
gotoProjectTabInSearchPage();

log.info("Query Group project versions");

List<String> names = new ArrayList<String>();
for (WebElement row : readyElement(searchProjectForm)
.findElements(By.xpath("//h3[@class='list__title']"))) {
names.add(row.getText());
if (readyElement(mainContentDiv)
.getText().contains("No project exists")) {
return Collections.emptyList();
}
return names;

}

public void gotoProjectTabInSearchPage() {
clickElement(projectTabSearchPage);
return WebElementUtil.getColumnContents(getDriver(), projectTable,
PROJECT_NAME_COLUMN);
}

/**
Expand All @@ -103,7 +91,7 @@ public void gotoProjectTabInSearchPage() {
public ProjectsPage expectProjectVisible(final String projectName) {
log.info("Wait for project {} visible", projectName);
waitForPageSilence();
assertThat(getProjectNamesOnSearchPage()).contains(projectName);
assertThat(getProjectNamesOnCurrentPage()).contains(projectName);
return new ProjectsPage(getDriver());
}

Expand All @@ -115,7 +103,7 @@ public ProjectsPage expectProjectVisible(final String projectName) {
public ProjectsPage expectProjectNotVisible(final String projectName) {
log.info("Wait for project {} not visible", projectName);
waitForPageSilence();
assertThat(getProjectNamesOnSearchPage()).doesNotContain(
assertThat(getProjectNamesOnCurrentPage()).doesNotContain(
projectName);
return new ProjectsPage(getDriver());
}
Expand Down
@@ -0,0 +1,77 @@
/*
* Copyright 2015, 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.search;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.ArrayList;
import java.util.Collections;
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.page.projects.CreateProjectPage;
import org.zanata.page.projects.ProjectVersionsPage;
import org.zanata.util.WebElementUtil;

import com.google.common.base.Function;

@Slf4j
public class SearchPage extends BasePage {

private By searchProjectForm = By.id("search-project_form");

private By projectTabSearchPage = By.id("projects_tab");
private By userTabSearchPage = By.id("users_tab");


public SearchPage(final WebDriver driver) {
super(driver);
}

public List<String> getProjectNamesOnSearchPage() {
log.info("Query Projects list");
waitForPageSilence();
gotoProjectTabInSearchPage();

log.info("Query project name");

List<String> names = new ArrayList<String>();
for (WebElement row : readyElement(searchProjectForm)
.findElements(By.xpath("//h3[@class='list__title']"))) {
names.add(row.getText());
}
return names;

}

public void gotoProjectTabInSearchPage() {
clickElement(projectTabSearchPage);
}

public void gotoUserTabInSearchPage() {
clickElement(userTabSearchPage);
}
}
Expand Up @@ -52,7 +52,7 @@ public class ProjectWorkFlow extends AbstractWebWorkFlow {
public ProjectVersionsPage createNewSimpleProject(String projectId,
String projectName) {
ProjectsPage projectsPage = goToHome().goToProjects();
List<String> projects = projectsPage.getProjectNamesOnSearchPage();
List<String> projects = projectsPage.getProjectNamesOnCurrentPage();
log.info("current projects: {}", projects);

if (projects.contains(projectName)) {
Expand All @@ -79,7 +79,7 @@ public ProjectVersionsPage createNewSimpleProject(String projectId,
*/
public ProjectVersionsPage createNewProject(HashMap<String, String> settings) {
ProjectsPage projectsPage = goToHome().goToProjects();
List<String> projects = projectsPage.getProjectNamesOnSearchPage();
List<String> projects = projectsPage.getProjectNamesOnCurrentPage();
log.info("current projects: {}", projects);
CreateProjectPage createProjectPage = projectsPage
.clickOnCreateProjectLink()
Expand Down Expand Up @@ -148,7 +148,7 @@ public VersionLanguagesPage createNewProjectVersion(String projectName,
public ProjectVersionsPage goToProjectByName(String projectName) {
ProjectsPage projects = goToHome().goToProjects();
log.info("go to project by name with current projects: {}, name: {}",
projects.getProjectNamesOnSearchPage(), projectName);
projects.getProjectNamesOnCurrentPage(), projectName);
return projects.goToProject(projectName);
}

Expand Down
Expand Up @@ -73,15 +73,15 @@ public void setAProjectToReadOnly() throws Exception {
.setReadOnlyFilterEnabled(false)
.expectProjectNotVisible("about fedora");

assertThat(projectsPage.getProjectNamesOnSearchPage())
assertThat(projectsPage.getProjectNamesOnCurrentPage())
.doesNotContain("about fedora")
.as("The project is not displayed");

projectsPage = projectsPage.setActiveFilterEnabled(false)
.setReadOnlyFilterEnabled(true)
.expectProjectVisible("about fedora");

assertThat(projectsPage.getProjectNamesOnSearchPage())
assertThat(projectsPage.getProjectNamesOnCurrentPage())
.contains("about fedora")
.as("The project is now displayed");
}
Expand All @@ -100,7 +100,7 @@ public void setAProjectToWritable() throws Exception {
.setActiveFilterEnabled(false)
.setReadOnlyFilterEnabled(true)
.expectProjectVisible("about fedora")
.getProjectNamesOnSearchPage())
.getProjectNamesOnCurrentPage())
.contains("about fedora")
.as("The project is locked");

Expand All @@ -116,7 +116,7 @@ public void setAProjectToWritable() throws Exception {
.setReadOnlyFilterEnabled(false)
.expectProjectVisible("about fedora");

assertThat(projectsPage.getProjectNamesOnSearchPage())
assertThat(projectsPage.getProjectNamesOnCurrentPage())
.contains("about fedora")
.as("The project is now displayed");
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ public void deleteAProject() throws Exception {
.confirmDeleteProject()
.goToProjects();

assertThat(projectsPage.getProjectNamesOnSearchPage())
assertThat(projectsPage.getProjectNamesOnCurrentPage())
.doesNotContain("about fedora")
.as("The project is not displayed");

Expand All @@ -47,7 +47,7 @@ public void deleteAProject() throws Exception {

projectsPage.expectProjectVisible("about fedora");

assertThat(projectsPage.getProjectNamesOnSearchPage())
assertThat(projectsPage.getProjectNamesOnCurrentPage())
.contains("about fedora")
.as("The project is now displayed");

Expand All @@ -56,7 +56,7 @@ public void deleteAProject() throws Exception {
assertThat(new LoginWorkFlow()
.signIn("translator", "translator")
.goToProjects()
.getProjectNamesOnSearchPage())
.getProjectNamesOnCurrentPage())
.doesNotContain("about fedora")
.as("User cannot navigate to the archived project");
}
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.zanata.page.BasePage;
import org.zanata.page.projects.ProjectBasePage;
import org.zanata.page.projects.ProjectsPage;
import org.zanata.page.search.SearchPage;
import org.zanata.util.SampleProjectRule;
import org.zanata.workflow.BasicWorkFlow;
import org.zanata.workflow.LoginWorkFlow;
Expand Down Expand Up @@ -72,13 +73,13 @@ public void successfulProjectSearchAndDisplay() throws Exception {
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void unsuccessfulProjectSearch() throws Exception {
ProjectsPage projectsPage = new BasicWorkFlow()
SearchPage searchPage = new BasicWorkFlow()
.goToHome()
.enterSearch("arodef")
.expectSearchListContains("Search Zanata for 'arodef'")
.submitSearch();

assertThat(projectsPage.getProjectNamesOnSearchPage().isEmpty())
assertThat(searchPage.getProjectNamesOnSearchPage().isEmpty())
.isTrue()
.as("No projects are displayed");
}
Expand Down

0 comments on commit a315251

Please sign in to comment.