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 #206 from zanata/fix-google-permissions
Browse files Browse the repository at this point in the history
Add stability to the Google OpenID test
  • Loading branch information
Patrick Huang committed Oct 2, 2013
2 parents c7e1a4c + 389b67e commit fc1d84f
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 91 deletions.
25 changes: 17 additions & 8 deletions functional-test/src/main/java/org/zanata/page/AbstractPage.java
Expand Up @@ -20,18 +20,25 @@
*/
package org.zanata.page;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import java.util.List;
import java.util.Set;

import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.*;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.NoAlertPresentException;
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 java.util.List;
import java.util.Set;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;

@Slf4j
public class AbstractPage {
Expand Down Expand Up @@ -62,6 +69,10 @@ public String getTitle() {
return driver.getTitle();
}

public String getUrl() {
return driver.getCurrentUrl();
}

public FluentWait<WebDriver> waitForTenSec() {
return ajaxWaitForTenSec;
}
Expand Down Expand Up @@ -92,7 +103,6 @@ public List<String> getErrors() {

/**
* Wait until expected number of errors presented on page or timeout.
*
* @param expectedNumber
* expected number of errors on page
* @return list of error message
Expand All @@ -109,7 +119,6 @@ public boolean apply(WebDriver input) {

/**
* Wait for all necessary elements to be available on page.
*
* @param elementBys
* selenium search criteria for locating elements
*/
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -21,11 +21,13 @@
package org.zanata.page.account;

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.zanata.page.BasePage;
import org.zanata.page.googleaccount.GoogleAccountPage;
import org.zanata.page.utility.DashboardPage;

@Slf4j
Expand Down
Expand Up @@ -18,7 +18,7 @@
* 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;
package org.zanata.page.googleaccount;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -53,15 +53,13 @@ public GoogleAccountPage enterGooglePassword(String password) {
return new GoogleAccountPage(getDriver());
}

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

// 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());
public GoogleManagePermissionsPage clickPermissionsSignIn() {
signInButton.click();
return new GoogleManagePermissionsPage(getDriver());
}
}
@@ -0,0 +1,56 @@
/*
* 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.googleaccount;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.zanata.page.AbstractPage;

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

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

public GoogleManagePermissionsPage removePermission(String permissionName) {
if (pageContainsPermission(permissionName)) {
getDriver().findElement(By.name(permissionName))
.findElement(By.cssSelector("input[type='submit']"))
.click();
}
return new GoogleManagePermissionsPage(getDriver());
}

public boolean pageContainsPermission(String permissionName) {
try {
return getDriver().findElement(By.name(permissionName))
.isDisplayed();
} catch (NoSuchElementException nsee) {
// Permission not listed
return false;
}
}
}
@@ -0,0 +1,50 @@
/*
* 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.googleaccount;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.zanata.page.AbstractPage;
import org.zanata.page.account.EditProfilePage;

import com.google.common.base.Function;

/**
* @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() {
waitForTenSec().until(new Function<WebDriver, Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
return getDriver().findElement(By.id("submit_approve_access"))
.isEnabled();
}
});
getDriver().findElement(By.id("submit_approve_access")).click();
return new EditProfilePage(getDriver());
}
}
Expand Up @@ -13,6 +13,11 @@ public <P extends AbstractPage> P goToPage(String url, Class<P> pageClass) {
return PageFactory.initElements(driver, pageClass);
}

public <P extends AbstractPage> P goToUrl(String url, Class<P> pageClass) {
driver.navigate().to(url);
return PageFactory.initElements(driver, pageClass);
}

private String toUrl(String relativeUrl) {
return hostUrl + removeLeadingSlash(relativeUrl);
}
Expand Down
@@ -0,0 +1,52 @@
/*
* 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.workflow;

import org.zanata.page.googleaccount.GoogleAccountPage;
import org.zanata.page.googleaccount.GoogleManagePermissionsPage;

/**
* @author Damian Jansen <a
* href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class GoogleWorkFlow extends AbstractWebWorkFlow {
private static String permissionsPageLink =
"https://accounts.google.com/b/0/IssuedAuthSubTokens?hl=en_GB";
private static String forceLogoutLink =
"https://accounts.google.com/Logout?service=lso";

public GoogleManagePermissionsPage resetGooglePermissions(
String googleUsername, String password) {
GoogleAccountPage googleAccountPage =
new BasicWorkFlow().goToUrl(permissionsPageLink,
GoogleAccountPage.class);

return googleAccountPage.enterGoogleEmail(googleUsername)
.enterGooglePassword(password).clickPermissionsSignIn()
.removePermission("localhost");
}

public GoogleAccountPage forceLogout() {
return new BasicWorkFlow().goToUrl(forceLogoutLink,
GoogleAccountPage.class);
}

}
Expand Up @@ -21,7 +21,7 @@
package org.zanata.workflow;

import org.zanata.page.account.EditProfilePage;
import org.zanata.page.account.GoogleAccountPage;
import org.zanata.page.googleaccount.GoogleAccountPage;
import org.zanata.page.utility.HomePage;

/**
Expand All @@ -35,9 +35,12 @@ public HomePage registerGoogleOpenID(String name, String username,
GoogleAccountPage googleAccountPage =
new BasicWorkFlow().goToHome().clickSignInLink()
.selectGoogleOpenID();

EditProfilePage editProfilePage =
googleAccountPage.enterGoogleEmail(email)
.enterGooglePassword(password).clickSignIn();
.enterGooglePassword(password).clickSignIn()
.acceptPermissions();

return editProfilePage.enterName(name).enterUserName(username)
.enterEmail(email).clickSave();
}
Expand Down
Expand Up @@ -22,6 +22,7 @@

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.zanata.feature.googleopenid.GoogleOpenIDTest;

/**
* @author Damian Jansen <a
Expand All @@ -30,6 +31,6 @@
@RunWith(Suite.class)
@Suite.SuiteClasses({ ChangePasswordTest.class, RegisterTest.class,
UsernameValidationTest.class, ValidEmailAddressTest.class,
InvalidEmailAddressTest.class, OpenIDTest.class })
InvalidEmailAddressTest.class, GoogleOpenIDTest.class })
public class AccountTestSuite {
}

0 comments on commit fc1d84f

Please sign in to comment.