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 #180 from zanata/openid-tests
Browse files Browse the repository at this point in the history
Clean up Page and Workflow concept for OpenID tests
  • Loading branch information
Patrick Huang committed Sep 18, 2013
2 parents 7a06c68 + 2dfbb77 commit 09deb76
Show file tree
Hide file tree
Showing 16 changed files with 562 additions and 93 deletions.
18 changes: 12 additions & 6 deletions functional-test/src/main/java/org/zanata/page/AbstractPage.java
Expand Up @@ -20,20 +20,21 @@
*/
package org.zanata.page;

import java.util.List;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
import org.openqa.selenium.support.ui.FluentWait;
import org.zanata.util.WebElementUtil;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;

import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.util.Set;

@Slf4j
public class AbstractPage
Expand All @@ -44,6 +45,11 @@ public class AbstractPage
public void deleteCookiesAndRefresh()
{
getDriver().manage().deleteAllCookies();
Set<Cookie> cookies = getDriver().manage().getCookies();
if (cookies.size() > 0)
{
log.warn("Failed to delete cookies: {}", cookies);
}
getDriver().navigate().refresh();
}

Expand Down
@@ -0,0 +1,78 @@
/*
* Copyright 2013, 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.account;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.zanata.page.BasePage;
import org.zanata.page.utility.HomePage;

/**
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class EditProfilePage extends BasePage
{
@FindBy(id = "editProfileForm:nameField:name")
private WebElement nameField;

@FindBy(id = "editProfileForm:usernameField:username")
private WebElement usernameField;

@FindBy(id = "editProfileForm:emailField:email")
private WebElement emailField;

@FindBy(id = "editProfileForm:saveButton")
private WebElement saveButton;

@FindBy(id = "editProfileForm:cancelButton")
private WebElement cancelButton;

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

public EditProfilePage enterName(String name)
{
nameField.sendKeys(name);
return new EditProfilePage(getDriver());
}

public EditProfilePage enterUserName(String userName)
{
usernameField.sendKeys(userName);
return new EditProfilePage(getDriver());
}

public EditProfilePage enterEmail(String email)
{
emailField.sendKeys(email);
return new EditProfilePage(getDriver());
}

public HomePage clickSave()
{
saveButton.click();
return new HomePage(getDriver());
}

}
@@ -0,0 +1,71 @@
/*
* Copyright 2013, 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.account;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.zanata.page.AbstractPage;

/**
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class GoogleAccountPage extends AbstractPage
{
@FindBy(id = "Email")
private WebElement emailField;

@FindBy(id = "Passwd")
private WebElement passwordField;

@FindBy(id = "signIn")
private WebElement signInButton;

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

public GoogleAccountPage enterGoogleEmail(String email)
{
emailField.sendKeys(email);
return new GoogleAccountPage(getDriver());
}

public GoogleAccountPage enterGooglePassword(String password)
{
passwordField.sendKeys(password);
return new GoogleAccountPage(getDriver());
}

public EditProfilePage clickSignIn()
{
signInButton.click();

// May return a Permissions request page, if this is the first run
if(!getDriver().getTitle().contains("Edit Profile"))
{
GooglePermissionsPage googlePermissionsPage = new GooglePermissionsPage(getDriver());
googlePermissionsPage.acceptPermissions();
}
return new EditProfilePage(getDriver());
}
}
@@ -0,0 +1,24 @@
package org.zanata.page.account;

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.AbstractPage;

/**
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class GooglePermissionsPage extends AbstractPage
{
public GooglePermissionsPage(WebDriver driver)
{
super(driver);
}

public EditProfilePage acceptPermissions()
{
getDriver().findElement(By.id("submit_approve_access")).click();
return new EditProfilePage(getDriver());
}
}
@@ -0,0 +1,37 @@
package org.zanata.page.account;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.zanata.page.BasePage;

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

@FindBy(id="Email")
private WebElement emailField;

@FindBy(id="signIn")
private WebElement signInButton;

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

public OpenIDPage enterEmail(String email)
{
emailField.sendKeys(email);
return new OpenIDPage(getDriver());
}

public GoogleAccountPage clickSignIn()
{
signInButton.click();
return new GoogleAccountPage(getDriver());
}

}
Expand Up @@ -20,18 +20,13 @@
*/
package org.zanata.page.account;

import com.google.common.base.Predicate;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.zanata.page.AbstractPage;
import org.zanata.page.BasePage;

import java.util.List;
import org.zanata.page.utility.DashboardPage;

@Slf4j
public class SignInPage extends BasePage
Expand All @@ -53,78 +48,35 @@ public SignInPage(final WebDriver driver)
super(driver);
}

public <P extends AbstractPage> P signInAndGoToPage(String username, String password, Class<P> pageClass)
public SignInPage enterUsername(String username)
{
try
{
doSignIn(username, password);
}
catch (IllegalAccessError iae)
{
SignInPage.log.warn("Login failed. May due to some weird issue. Will Try again.");
doSignIn(username, password);
}
catch (TimeoutException e)
{
SignInPage.log.error("timeout on login. If you are running tests manually with cargo.wait, you probably forget to create the user admin/admin. See ManualRunHelper.");
throw e;
}
return PageFactory.initElements(getDriver(), pageClass);
usernameField.sendKeys(username);
return new SignInPage(getDriver());
}

public SignInPage signInFailure(String username, String password)
public SignInPage enterPassword(String password)
{
SignInPage.log.info("log in as username: {}", username);
usernameField.clear();
usernameField.sendKeys(username);
passwordField.sendKeys(password);
signInButton.click();
waitForTenSec().until(new Predicate<WebDriver>()
{
@Override
public boolean apply(WebDriver driver)
{
List<WebElement> messages = driver.findElements(By.id("messages"));
return messages.size() > 0 && messages.get(0).getText().contains("Login failed");
}
});
return new SignInPage(getDriver());
}

public ResetPasswordPage gotToResetPassword()
public DashboardPage clickSignIn()
{
forgotPasswordLink.click();
return new ResetPasswordPage(getDriver());
signInButton.click();
return new DashboardPage(getDriver());
}

public String getNotificationMessage()
public GoogleAccountPage selectGoogleOpenID()
{
List<WebElement> messages = getDriver().findElements(By.id("messages"));
return messages.size() > 0 ? messages.get(0).getText() : "";
getDriver().findElement(By.linkText("Google")).click();
return new GoogleAccountPage(getDriver());
}

private void doSignIn(String username, String password)
public ResetPasswordPage goToResetPassword()
{
SignInPage.log.info("Internal log in as username: {}", username);
usernameField.clear();
passwordField.clear();
usernameField.sendKeys(username);
passwordField.sendKeys(password);
signInButton.click();
waitForTenSec().until(new Predicate<WebDriver>()
{
@Override
public boolean apply(WebDriver driver)
{
List<WebElement> messages = driver.findElements(By.id("messages"));
if (messages.size() > 0 && messages.get(0).getText().contains("Login failed"))
{
throw new IllegalAccessError("Login failed");
}
List<WebElement> signIn = driver.findElements(By.id("Sign_in"));
return signIn.size() == 0;
}
});
forgotPasswordLink.click();
return new ResetPasswordPage(getDriver());
}


}

0 comments on commit 09deb76

Please sign in to comment.