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 on dashboard and homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Aug 12, 2013
1 parent eefd6fd commit 5eeb1fa
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 178 deletions.
31 changes: 19 additions & 12 deletions functional-test/src/main/java/org/zanata/page/BasePage.java
Expand Up @@ -20,13 +20,9 @@
*/
package org.zanata.page;

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

Expand All @@ -46,11 +42,13 @@
import org.zanata.page.utility.HomePage;
import org.zanata.util.WebElementUtil;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import javax.annotation.Nullable;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;

/**
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
Expand All @@ -77,6 +75,9 @@ public class BasePage extends AbstractPage

@FindBy(id = "user_avatar")
private WebElement userAvatar;

@FindBy(id = "home")
private WebElement homeLink;

private static final By BY_SIGN_IN = By.id("signin_link");
private static final By BY_SIGN_OUT = By.id("right_menu_sign_out_link");
Expand All @@ -98,6 +99,12 @@ public MyAccountPage goToMyProfile()

return new MyAccountPage(getDriver());
}

public HomePage goToHomePage()
{
homeLink.click();
return new HomePage(getDriver());
}

public ProjectsPage goToProjects()
{
Expand Down
@@ -0,0 +1,94 @@
/*
* Copyright 2010, 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.utility;

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

public class DashboardPage extends BasePage
{

@FindBy(id = "main_body_content")
private WebElement mainBodyContent;

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

public boolean containActivityListSection()
{
return getDriver().findElement(By.id("activityList")) != null;
}

public boolean containMyMaintainedProjectsSection()
{
return getDriver().findElement(By.id("maintainedProject")) != null;
}

public List<WebElement> getMyActivityList()
{
WebElement listWrapper = getDriver().findElement(By.id("activityList")).findElement(By.tagName("ul"));

if (listWrapper != null)
{
return listWrapper.findElements(By.xpath("./li"));
}
return new ArrayList<WebElement>();
}

public List<WebElement> getMyMaintainedProject()
{
WebElement listWrapper = getDriver().findElement(By.id("maintainedProject")).findElement(By.tagName("ul"));

if (listWrapper != null)
{
return listWrapper.findElements(By.xpath("./li"));
}
return new ArrayList<WebElement>();
}

public void clickMoreActivity()
{
WebElement moreActivity = getMoreActivityElement();
if (moreActivity != null)
{
moreActivity.click();
WebElementUtil.waitForTenSeconds(getDriver()).until(
ExpectedConditions.invisibilityOfElementLocated(By.className("loader__spinner")));
}
}

public WebElement getMoreActivityElement()
{
return getDriver().findElement(By.id("moreActivity"));
}
}
Expand Up @@ -20,22 +20,14 @@
*/
package org.zanata.page.utility;

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

@Slf4j
public class HomePage extends BasePage
{

Expand All @@ -47,74 +39,20 @@ public HomePage(final WebDriver driver)
super(driver);
}

@Deprecated
// home page replace by dashboard
public EditHomeContentPage goToEditPageContent()
{
getDriver().findElement(By.linkText("Edit Page Content")).click();
return new EditHomeContentPage(getDriver());
}

@Deprecated
// home page replace by dashboard
public EditHomeCodePage goToEditPageCode()
{
getDriver().findElement(By.linkText("Edit Page Code")).click();
return new EditHomeCodePage(getDriver());
}

@Deprecated
// home page replace by dashboard
public String getMainBodyContent()
{
return mainBodyContent.getText();
}

public boolean containActivityListSection()
{
return getDriver().findElement(By.id("activityList")) != null;
}

public boolean containMyMaintainedProjectsSection()
{
return getDriver().findElement(By.id("maintainedProject")) != null;
}

public List<WebElement> getMyActivityList()
{
WebElement listWrapper = getDriver().findElement(By.id("activityList")).findElement(By.tagName("ul"));

if (listWrapper != null)
{
return listWrapper.findElements(By.xpath("./li"));
}
return new ArrayList<WebElement>();
}

public List<WebElement> getMyMaintainedProject()
{
WebElement listWrapper = getDriver().findElement(By.id("maintainedProject")).findElement(By.tagName("ul"));

if (listWrapper != null)
{
return listWrapper.findElements(By.xpath("./li"));
}
return new ArrayList<WebElement>();
}

public void clickMoreActivity()
{
WebElement moreActivity = getMoreActivityElement();
if (moreActivity != null)
{
moreActivity.click();
WebElementUtil.waitForTenSeconds(getDriver()).until(
ExpectedConditions.invisibilityOfElementLocated(By.className("loader__spinner")));
}
}

public WebElement getMoreActivityElement()
{
return getDriver().findElement(By.id("moreActivity"));
}
}
Expand Up @@ -20,33 +20,32 @@
*/
package org.zanata.workflow;

import org.zanata.page.utility.HomePage;
import org.zanata.page.account.SignInPage;

import lombok.extern.slf4j.Slf4j;

import org.zanata.page.account.SignInPage;
import org.zanata.page.utility.DashboardPage;

@Slf4j
public class LoginWorkFlow extends AbstractWebWorkFlow
{
public HomePage signIn(String username, String password)
public DashboardPage signIn(String username, String password)
{
// System.getProperties().put("webdriver.firefox.useExisting", "true");
log.info("accessing zanata at: {}", hostUrl);

HomePage homePage = new HomePage(driver);
if (homePage.hasLoggedIn())
DashboardPage dashboardPage = new DashboardPage(driver);
if (dashboardPage.hasLoggedIn())
{
log.info("already logged in as {}", username);
if (homePage.loggedInAs().equals(username))
if (dashboardPage.loggedInAs().equals(username))
{
return homePage;
return dashboardPage;
}
log.info("sign out first then sign back in as {}", username);
homePage = homePage.logout();
dashboardPage.logout();
}

SignInPage signInPage = homePage.clickSignInLink();
return signInPage.signInAndGoToPage(username, password, HomePage.class);
SignInPage signInPage = dashboardPage.clickSignInLink();
return signInPage.signInAndGoToPage(username, password, DashboardPage.class);
}

}
Expand Up @@ -20,6 +20,8 @@
*/
package org.zanata.feature.account;

import static org.hamcrest.MatcherAssert.assertThat;

import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -29,13 +31,12 @@
import org.zanata.feature.DetailedTest;
import org.zanata.page.account.ChangePasswordPage;
import org.zanata.page.account.MyAccountPage;
import org.zanata.page.utility.DashboardPage;
import org.zanata.page.utility.HomePage;
import org.zanata.util.ResetDatabaseRule;
import org.zanata.workflow.BasicWorkFlow;
import org.zanata.workflow.LoginWorkFlow;

import static org.hamcrest.MatcherAssert.assertThat;

/**
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
Expand Down Expand Up @@ -68,8 +69,8 @@ public void changePasswordSuccessful()

HomePage homePage = myAccountPage.logout();
assertThat("User is logged out", !homePage.hasLoggedIn());
homePage = new LoginWorkFlow().signIn("translator", "newpassword");
assertThat("User has logged in with the new password", homePage.hasLoggedIn());
DashboardPage dashboardPage = new LoginWorkFlow().signIn("translator", "newpassword");
assertThat("User has logged in with the new password", dashboardPage.hasLoggedIn());
}

@Test
Expand Down Expand Up @@ -117,8 +118,8 @@ public void changePasswordCancel()

HomePage homePage = myAccountPage.logout();
assertThat("User is logged out", !homePage.hasLoggedIn());
homePage = new LoginWorkFlow().signIn("translator", "translator");
assertThat("User has logged in with the original password", homePage.hasLoggedIn());
DashboardPage dashboardPage = new LoginWorkFlow().signIn("translator", "translator");
assertThat("User has logged in with the original password", dashboardPage.hasLoggedIn());
}

@Test
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.DetailedTest;
import org.zanata.page.utility.DashboardPage;
import org.zanata.page.utility.HomePage;
import org.zanata.page.administration.EditHomeCodePage;
import org.zanata.page.administration.EditHomeContentPage;
Expand All @@ -38,7 +39,6 @@
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
@Category(DetailedTest.class)
@Ignore //Home page replaced by dashboard. No longer have edit page
public class EditHomePageTest
{
@ClassRule
Expand All @@ -48,21 +48,23 @@ public class EditHomePageTest
@Ignore("Cannot access the editor via WebDriver")
public void goToEditPageContent()
{
EditHomeContentPage editHomeContentPage = new LoginWorkFlow().signIn("admin", "admin").goToEditPageContent();
DashboardPage dashboard = new LoginWorkFlow().signIn("admin", "admin");
EditHomeContentPage editHomeContentPage = dashboard.goToHomePage().goToEditPageContent();

assertThat("Correct page", editHomeContentPage.getTitle(), Matchers.equalTo("Zanata: Edit Home Page"));
editHomeContentPage = editHomeContentPage.enterText("Test");
HomePage homePage = editHomeContentPage.update();
editHomeContentPage = homePage.goToEditPageContent();
editHomeContentPage.cancelUpdate();
}

@Test(expected = AssertionError.class) // RHBZ-988162 - not updating immediately

public void goToEditPageCode()
{
EditHomeCodePage editHomeCodePage = new LoginWorkFlow().signIn("admin", "admin").goToEditPageCode();
DashboardPage dashboard = new LoginWorkFlow().signIn("admin", "admin");
EditHomeCodePage editHomeCodePage = dashboard.goToHomePage().goToEditPageCode();

assertThat("Correct page", editHomeCodePage.getTitle(), Matchers.equalTo("Zanata: Edit Page Code"));
HomePage homePage = editHomeCodePage.enterText("Test").update();
HomePage homePage = editHomeCodePage.enterText("Test").update();
assertThat("Message displayed", homePage.getNotificationMessage(),
Matchers.equalTo("Home content was successfully updated."));
editHomeCodePage = homePage.goToEditPageCode();
Expand Down

0 comments on commit 5eeb1fa

Please sign in to comment.