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 #412 from zanata/fix-functional-tests-projectpage
Browse files Browse the repository at this point in the history
Fix functional test post projectpage merge
  • Loading branch information
djansen-redhat committed Apr 10, 2014
2 parents d33b4f1 + 92c0e99 commit 98b2bac
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 130 deletions.
23 changes: 18 additions & 5 deletions functional-test/src/main/java/org/zanata/page/BasePage.java
Expand Up @@ -22,11 +22,7 @@

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.*;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.zanata.page.account.MyAccountPage;
Expand Down Expand Up @@ -277,4 +273,21 @@ public String getHtmlSource(WebElement webElement) {
"return arguments[0].innerHTML;", webElement);
}

public void clickWhenTabEnabled(final WebElement tab) {
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
boolean clicked = false;
try {
if (tab.isDisplayed() && tab.isEnabled()) {
tab.click();
clicked = true;
}
} catch(WebDriverException wde) {
return clicked;
}
return clicked;
}
});
}
}
Expand Up @@ -71,7 +71,7 @@ public VersionGroupsPage saveGroup() {
}

public CreateVersionGroupPage saveGroupFailure() {
clickAndCheckErrors(saveButton);
saveButton.click();
return new CreateVersionGroupPage(getDriver());
}

Expand Down
Expand Up @@ -5,10 +5,7 @@

import lombok.extern.slf4j.Slf4j;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.zanata.page.BasePage;
Expand Down Expand Up @@ -147,22 +144,22 @@ public boolean apply(WebDriver driver) {
}

public VersionGroupPage clickLanguagesTab() {
getDriver().findElement(By.id("languages")).click();
clickWhenTabEnabled(getDriver().findElement(By.id("languages")));
return new VersionGroupPage(getDriver());
}

public VersionGroupPage clickProjectsTab() {
getDriver().findElement(By.id("projects")).click();
clickWhenTabEnabled(getDriver().findElement(By.id("projects")));
return new VersionGroupPage(getDriver());
}

public VersionGroupPage clickMaintainersTab() {
getDriver().findElement(By.id("maintainers")).click();
clickWhenTabEnabled(getDriver().findElement(By.id("maintainers")));
return new VersionGroupPage(getDriver());
}

public VersionGroupPage clickSettingsTab() {
getDriver().findElement(By.id("settings")).click();
clickWhenTabEnabled(getDriver().findElement(By.id("settings")));
return new VersionGroupPage(getDriver());
}

Expand Down Expand Up @@ -210,4 +207,5 @@ public VersionGroupPage confirmAddProject() {
new Actions(getDriver()).sendKeys(Keys.ENTER);
return new VersionGroupPage(getDriver());
}

}
Expand Up @@ -21,6 +21,7 @@

package org.zanata.page.projects;

import com.google.common.base.Function;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

Expand All @@ -34,6 +35,12 @@ public ProjectAboutPage(WebDriver driver) {
}

public String getAboutText() {
return getDriver().findElement(By.id("project-about")).getText();
return waitForTenSec().until(new Function<WebDriver, String>() {
@Override
public String apply(WebDriver driver) {
return getDriver()
.findElement(By.id("project-about")).getText();
}
});
}
}
Expand Up @@ -25,6 +25,7 @@

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.zanata.page.BasePage;
Expand Down Expand Up @@ -230,18 +231,4 @@ public String getGitUrl() {
return "";
}

private void clickWhenTabEnabled(final WebElement tab) {
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
boolean clicked = false;
if (tab.isDisplayed() && tab.isEnabled()) {
tab.click();
clicked = true;
}
return clicked;
}
});
}

}
Expand Up @@ -27,6 +27,7 @@
import com.google.common.collect.Iterables;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
Expand Down Expand Up @@ -101,7 +102,7 @@ public boolean apply(

public List<String> getVersions() {
return WebElementUtil.elementsToText(getDriver(),
By.className("list__title"));
By.xpath("//h3[@class='list__title']"));
}

public int getNumberOfDisplayedVersions() {
Expand All @@ -114,7 +115,8 @@ public ProjectVersionsPage waitForDisplayedVersions(final int expected) {
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return getNumberOfDisplayedVersions() == expected;
return getNumberOfDisplayedVersions() == expected &&
getVersions().size() == expected;
}
});
return new ProjectVersionsPage(getDriver());
Expand All @@ -129,7 +131,15 @@ public ProjectVersionsPage clickSearchIcon() {
}

public ProjectVersionsPage clearVersionSearch() {
getDriver().findElement(By.id("versionSearch__input")).clear();
int maxKeys = 500;
while (!getDriver().findElement(By.id("versionSearch__input"))
.getAttribute("value").isEmpty() && maxKeys > 0) {
getDriver().findElement(By.id("versionSearch__input"))
.sendKeys(Keys.BACK_SPACE);
}
if (maxKeys == 0) {
log.warn("Exceeded max keypresses for clearing search bar");
}
return new ProjectVersionsPage(getDriver());
}

Expand Down
Expand Up @@ -20,11 +20,7 @@
*/
package org.zanata.page.projectversion;

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.openqa.selenium.*;
import org.openqa.selenium.support.FindBy;
import org.zanata.page.BasePage;
import com.google.common.base.Predicate;
Expand Down Expand Up @@ -90,23 +86,27 @@ public boolean apply(WebDriver input) {
});
}

public VersionLanguagesPage gotoDocumentTab() {
public VersionDocumentsPage gotoDocumentTab() {
clickWhenTabEnabled(getDriver().findElement(By.id("documents")));
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return documentsTab.isDisplayed();
return getDriver()
.findElement(By.id("documents_content"))
.isDisplayed();
}
});
return new VersionLanguagesPage(getDriver());
return new VersionDocumentsPage(getDriver());
}

public VersionLanguagesPage gotoLanguageTab() {
clickWhenTabEnabled(getDriver().findElement(By.id("languages")));
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return languageTab.isDisplayed();
return getDriver()
.findElement(By.id("languages_content"))
.isDisplayed();
}
});
return new VersionLanguagesPage(getDriver());
Expand Down Expand Up @@ -170,24 +170,12 @@ public VersionTranslationTab gotoSettingsTranslationTab() {
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return settingsTranslationTab.isDisplayed();
return getDriver()
.findElement(By.id("settings-translation-review-form"))
.isDisplayed();
}
});
return new VersionTranslationTab(getDriver());
}

private void clickWhenTabEnabled(final WebElement tab) {
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
boolean clicked = false;
if (tab.isDisplayed() && tab.isEnabled()) {
tab.click();
clicked = true;
}
return clicked;
}
});
}

}
@@ -1,15 +1,77 @@
/*
* 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.projectversion;

import com.google.common.base.Predicate;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.List;

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

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

public VersionDocumentsPage waitForSourceDocsContains(final String document) {
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return sourceDocumentsContains(document);
}
});
return new VersionDocumentsPage(getDriver());
}

public boolean sourceDocumentsContains(String document) {
List<WebElement> documentList = getLanguageTabDocumentList();
for (final WebElement tableRow : documentList) {
if (tableRow.findElement(By.className("list__title")).getText()
.contains(document)) {
return true;
}
}
return false;
}

private List<WebElement> getLanguageTabDocumentList() {
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return getDriver()
.findElement(By.id("documents-document_list"))
.isDisplayed();
}
});

List<WebElement> rows =
getDriver().findElement(By.id("documents-document_list"))
.findElements(By.xpath("./li"));
return rows;
}

}
Expand Up @@ -100,35 +100,6 @@ public EditorPage apply(WebDriver driver) {
});
}

public boolean sourceDocumentsContains(String document) {
gotoDocumentTab();
List<WebElement> documentList = getLanguageTabDocumentList();
for (final WebElement tableRow : documentList) {
if (tableRow.findElement(By.className("list__title")).getText()
.contains(document)) {
return true;
}
}
return false;
}

private List<WebElement> getLanguageTabDocumentList() {

waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return getDriver()
.findElement(By.id("documents-document_list"))
.isDisplayed();
}
});

List<WebElement> rows =
getDriver().findElement(By.id("documents-document_list"))
.findElements(By.xpath("./li"));
return rows;
}

private List<WebElement> getVersionTabDocumentList() {
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.DetailedTest;
import org.zanata.page.projectversion.VersionDocumentsPage;
import org.zanata.page.projectversion.VersionLanguagesPage;
import org.zanata.page.webtrans.EditorPage;
import org.zanata.util.CleanDocumentStorageRule;
Expand Down Expand Up @@ -85,8 +86,12 @@ public void uploadHTMLFile() {
assertThat("Document uploaded notification shows",
projectVersionPage.getNotificationMessage(),
Matchers.equalTo(successfullyUploaded));
assertThat("Document shows in table",
projectVersionPage.sourceDocumentsContains(htmlfile.getName()));

VersionDocumentsPage versionDocumentsPage =
projectVersionPage.gotoDocumentTab();

assertThat("Document shows in table", versionDocumentsPage
.sourceDocumentsContains(htmlfile.getName()));

EditorPage editorPage =
projectVersionPage.goToProjects().goToProject("about fedora")
Expand Down

0 comments on commit 98b2bac

Please sign in to comment.