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

Commit

Permalink
Merge branch 'integration/master' into rhbz1092193
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Oct 22, 2014
2 parents 122c7d8 + d2d8e22 commit af0b471
Show file tree
Hide file tree
Showing 180 changed files with 5,417 additions and 2,210 deletions.
18 changes: 13 additions & 5 deletions .gitignore
@@ -1,8 +1,3 @@
# NB be careful ignoring anything under src/ (especially directories or .jar files)
# because ignoring files under these directories can make it
# difficult to debug build problems. At the very least, we should ensure
# 'mvn clean' will clean such directories.


*~
*.patch
Expand Down Expand Up @@ -36,6 +31,7 @@ bin/
# eclipse scrapbook page:
*.jpage

*.pdf

# idea
*.idea/
Expand All @@ -53,6 +49,18 @@ bin/
# vim
*.swp


# binary files
*.class
*.cli
*.exe
*.jar
*.war
*.zip

# temp files
*.log
*.temp
*.tmp
/tmp*
*.bak
2 changes: 2 additions & 0 deletions functional-test/pom.xml
Expand Up @@ -54,6 +54,7 @@
<webdriver.display>:0</webdriver.display>
<webdriver.log>${project.build.directory}/webdriver.log</webdriver.log>
<webdriver.screenshot.dir>${project.build.directory}/screenshots</webdriver.screenshot.dir>
<webdriver.wait>10</webdriver.wait>
<googleopenid.credentials>zanata.user.1:</googleopenid.credentials>
<!-- on jenkins, this needs to be set to empty - so that cargo can shutdown. see http://stackoverflow.com/questions/1096642/tomcat-failed-to-shutdown -->
<cargo.debug.jvm.args>
Expand Down Expand Up @@ -695,6 +696,7 @@
<echo>-Dwebdriver.display=display to run test browser in, for Xnest or otherwise. Default is :0.</echo>
<echo>-Dwebdriver.chrome.bin=full path to chrome binary.</echo>
<echo>-Dwebdriver.chrome.driver=full path to chromedriver binary.</echo>
<echo>-Dwebdriver.wait=global wait time in seconds for element searches. Default is 10.</echo>
<echo>==========================================================</echo>
<echo>to ask cargo to start up then wait so that tests can be run manually: mvn clean package cargo:run -Dfunctional-test -Dmysql.port=13306</echo>
</target>
Expand Down
58 changes: 39 additions & 19 deletions functional-test/src/main/java/org/zanata/page/AbstractPage.java
Expand Up @@ -35,7 +35,6 @@
import org.zanata.util.WebElementUtil;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;

/**
Expand All @@ -45,13 +44,13 @@
@Slf4j
public class AbstractPage {
private final WebDriver driver;
private final FluentWait<WebDriver> ajaxWaitForTenSec;
private final FluentWait<WebDriver> ajaxWaitForSec;

public AbstractPage(final WebDriver driver) {
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10),
this);
this.driver = driver;
ajaxWaitForTenSec = WebElementUtil.waitForTenSeconds(driver);
ajaxWaitForSec = WebElementUtil.waitForAMoment(driver);
waitForPageSilence();
}

Expand All @@ -78,8 +77,8 @@ public String getUrl() {
return driver.getCurrentUrl();
}

public FluentWait<WebDriver> waitForTenSec() {
return ajaxWaitForTenSec;
public FluentWait<WebDriver> waitForAMoment() {
return ajaxWaitForSec;
}

/**
Expand All @@ -89,7 +88,7 @@ public FluentWait<WebDriver> waitForTenSec() {
*/
public void waitForPage(List<By> elementBys) {
for (final By by : elementBys) {
waitForTenSec().until(new Function<WebDriver, WebElement>() {
waitForAMoment().until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
return getDriver().findElement(by);
Expand All @@ -99,12 +98,13 @@ public WebElement apply(WebDriver driver) {
}

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

protected <P extends AbstractPage> P refreshPageUntil(P currentPage,
Predicate<WebDriver> predicate) {
waitForTenSec().until(predicate);
waitForAMoment().until(predicate);
PageFactory.initElements(driver, currentPage);
return currentPage;
}

protected <P extends AbstractPage, T> T refreshPageUntil(P currentPage,
Function<WebDriver, T> function) {
T done = waitForTenSec().until(function);
T done = waitForAMoment().until(function);
PageFactory.initElements(driver, currentPage);
return done;
}
Expand All @@ -136,7 +136,7 @@ protected <P extends AbstractPage, T> T refreshPageUntil(P currentPage,
*/
public <T> void
waitFor(final Callable<T> callable, final Matcher<T> matcher) {
waitForTenSec().until(new Predicate<WebDriver>() {
waitForAMoment().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
try {
Expand All @@ -146,7 +146,8 @@ public boolean apply(WebDriver input) {
new Description.NullDescription());
}
return matcher.matches(result);
} catch (Exception e) {
}
catch (Exception e) {
log.warn("exception", e);
return false;
}
Expand All @@ -160,30 +161,49 @@ public boolean apply(WebDriver input) {
*/
public void waitForPageSilence() {
// Wait for jQuery calls to be 0
waitForTenSec().until(new Predicate<WebDriver>() {
waitForAMoment().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
int ajaxCalls;
int jQueryCalls;
try {
jQueryCalls = Integer.parseInt(
((JavascriptExecutor) getDriver())
.executeScript("return jQuery.active")
.toString());
} catch (WebDriverException jCall) {
.executeScript("return jQuery.active")
.toString()
);
}
catch (WebDriverException jCall) {
jQueryCalls = 0;
}

try {
ajaxCalls = Integer.parseInt(
((JavascriptExecutor) getDriver())
.executeScript("return Ajax.activeRequestCount")
.toString());
} catch (WebDriverException jCall) {
.executeScript(
"return Ajax.activeRequestCount")
.toString()
);
}
catch (WebDriverException jCall) {
ajaxCalls = 0;
}
return ajaxCalls + jQueryCalls == 0;
}
});
}

/**
* Wait for an element to be visible, and return it
* @param elementBy WebDriver By locator
* @return target WebElement
*/
public WebElement waitForWebElement(final By elementBy) {
return waitForAMoment().until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver input) {
return getDriver().findElement(elementBy);
}
});
}
}
17 changes: 12 additions & 5 deletions functional-test/src/main/java/org/zanata/page/BasePage.java
Expand Up @@ -37,6 +37,7 @@
import org.zanata.page.dashboard.DashboardBasePage;
import org.zanata.page.glossary.GlossaryPage;
import org.zanata.page.groups.VersionGroupsPage;
import org.zanata.page.languages.LanguagesPage;
import org.zanata.page.projects.ProjectVersionsPage;
import org.zanata.page.projects.ProjectsPage;
import org.zanata.page.utility.HelpPage;
Expand Down Expand Up @@ -103,14 +104,14 @@ private void clickNavMenuItem(final WebElement menuItem) {
getDriver().findElement(By.id("nav-main"))
.findElement(By.tagName("a")).click();
}
waitForTenSec().until(new Predicate<WebDriver>() {
waitForAMoment().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return menuItem.isDisplayed();
}
});
// The notifications can sometimes get in the way
waitForTenSec().until(ExpectedConditions.elementToBeClickable(menuItem));
waitForAMoment().until(ExpectedConditions.elementToBeClickable(menuItem));
menuItem.click();
}

Expand All @@ -120,6 +121,12 @@ public VersionGroupsPage goToGroups() {
return new VersionGroupsPage(getDriver());
}

public LanguagesPage goToLanguages() {
log.info("Click Languages");
clickNavMenuItem(getDriver().findElement(By.id("languages_link")));
return new LanguagesPage(getDriver());
}

public GlossaryPage goToGlossary() {
log.info("Click Glossary");
// Dynamically find the link, as it is not present for every user
Expand Down Expand Up @@ -257,7 +264,7 @@ public ProjectsPage submitSearch() {

public BasePage waitForSearchListContains(final String expected) {
log.info("Wait for Project search list contains {}", expected);
waitForTenSec().until(new Predicate<WebDriver>() {
waitForAMoment().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return getProjectSearchAutocompleteItems().contains(expected);
Expand All @@ -275,7 +282,7 @@ public List<String> getProjectSearchAutocompleteItems() {
public ProjectVersionsPage clickSearchEntry(final String searchEntry) {
log.info("Click Projects search result {}", searchEntry);
WebElement searchItem =
waitForTenSec().until(new Function<WebDriver, WebElement>() {
waitForAMoment().until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
List<WebElement> items =
Expand All @@ -296,7 +303,7 @@ public WebElement apply(WebDriver driver) {
}

public void clickWhenTabEnabled(final WebElement tab) {
waitForTenSec().until(new Predicate<WebDriver>() {
waitForAMoment().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
waitForPageSilence();
Expand Down
70 changes: 24 additions & 46 deletions functional-test/src/main/java/org/zanata/page/CorePage.java
Expand Up @@ -95,9 +95,14 @@ public List<String> getErrors() {
WebElementUtil.elementsToText(getDriver(),
By.xpath("//div[@class='message--danger']"));

List<String> topError =
WebElementUtil.elementsToText(getDriver(),
By.className("message--danger"));

List<String> allErrors = Lists.newArrayList();
allErrors.addAll(oldError);
allErrors.addAll(newError);
allErrors.addAll(topError);

return allErrors;
}
Expand All @@ -120,6 +125,23 @@ public boolean apply(WebDriver input) {
return getErrors();
}

/**
* Wait until an expected error is visible
*
* @param expected The expected error string
* @return The full list of visible errors
*/
public List<String> expectError(final String expected) {
log.info("Expect error {}", expected);
waitForAMoment().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return getErrors().contains(expected);
}
});
return getErrors();
}

public String getNotificationMessage() {
log.info("Query notification message");
List<WebElement> messages =
Expand All @@ -130,43 +152,21 @@ public String getNotificationMessage() {

public boolean expectNotification(final String notification) {
log.info("Wait for notification {}", notification);
return waitForTenSec().until(new Function<WebDriver, Boolean>() {
return waitForAMoment().until(new Function<WebDriver, Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
List<WebElement> messages = getDriver()
.findElement(By.id("messages"))
.findElements(By.tagName("li"));
List<String> notifications = new ArrayList<String>();
for( WebElement message : messages ) {
for (WebElement message : messages) {
notifications.add(message.getText().trim());
}
return notifications.contains(notification);
}
});
}

public List<String> expectFieldError(final String expected) {
waitForTenSec().until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
return waitForFieldErrors().contains(expected);
}
});
return getFieldErrors();
}

public List<String> waitForErrors() {
log.info("Query page errors list");
waitForTenSec().until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
return getDriver().findElement(
By.xpath("//span[@class='errors']"));
}
});
return getErrors();
}

public void assertNoCriticalErrors() {
log.info("Query critical errors");
List<WebElement> errors =
Expand Down Expand Up @@ -200,28 +200,6 @@ public void defocus() {
}
}

public List<String> waitForFieldErrors() {
log.info("Query field errors");
waitForTenSec().until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
return getDriver().findElement(By.className("message--danger"));
}
});
return getFieldErrors();
}

public List<String> getFieldErrors() {
log.info("Query field errors");
List<String> errorList = new ArrayList<String>();
List<WebElement> errorObjects =
getDriver().findElements(By.className("message--danger"));
for (WebElement element : errorObjects) {
errorList.add(element.getText().trim());
}
return errorList;
}

/* The system sometimes moves too fast for the Ajax pages, so provide a
* pause
*/
Expand Down

0 comments on commit af0b471

Please sign in to comment.