Skip to content

Commit

Permalink
test(endToEnd): Add admin end to end test
Browse files Browse the repository at this point in the history
  • Loading branch information
djansen-redhat committed Feb 23, 2017
1 parent 8b6d7f4 commit 85577a2
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 12 deletions.
Expand Up @@ -82,6 +82,10 @@ public LanguagesPage goToLanguages() {
return new LanguagesPage(getDriver());
}

public boolean isAdministrator() {
return getDriver().findElements(BY_ADMINISTRATION_LINK).size() > 0;
}

public AdministrationPage goToAdministration() {
log.info("Click Administration menu link");
clickLinkAfterAnimation(BY_ADMINISTRATION_LINK);
Expand Down
@@ -0,0 +1,97 @@
/*
* Copyright 2017, 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.administration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.zanata.page.BasePage;

import java.util.HashMap;
import java.util.Map;

/**
* @author Damian Jansen
* <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
public class CreateUserAccountPage extends BasePage {
private static final org.slf4j.Logger log =
org.slf4j.LoggerFactory.getLogger(CreateUserAccountPage.class);
private By usernameField = By.id("newUserForm:username:input:username");
private By emailField = By.id("newUserForm:email:input:email");
private By saveButton = By.id("newUserForm:newUserSave");
private By cancelButton = By.linkText("Cancel");
private String roleIdPrefix = "newUserForm:roles:input:newUserRoles:";

private Map<String, String> roleMap;

public CreateUserAccountPage(WebDriver driver) {
super(driver);
roleMap = new HashMap<>();
roleMap.put("admin", "0");
roleMap.put("glossarist", "1");
roleMap.put("glossary-admin", "2");
roleMap.put("translator", "3");
roleMap.put("user", "4");
}

public CreateUserAccountPage enterUsername(String username) {
enterText(readyElement(usernameField), username);
return new CreateUserAccountPage(getDriver());
}

public CreateUserAccountPage enterEmail(String email) {
enterText(readyElement(emailField), email);
return new CreateUserAccountPage(getDriver());
}

public CreateUserAccountPage clickRole(String role) {
log.info("Click role {}", role);
clickElement(readyElement(By.id(roleIdPrefix.concat(roleMap.get(role)))));
return new CreateUserAccountPage(getDriver());
}

@SuppressWarnings("unused")
public boolean isRoleChecked(String role) {
log.info("Query is role {} checked", role);
return readyElement(By.id(roleIdPrefix.concat(roleMap.get(role))))
.isSelected();
}

public ManageUserPage saveUser() {
log.info("Click Save");
clickElement(saveButton);
return new ManageUserPage(getDriver());
}

@SuppressWarnings("unused")
public CreateUserAccountPage saveUserExpectFailure() {
log.info("Click Save");
clickElement(saveButton);
return new CreateUserAccountPage(getDriver());
}

@SuppressWarnings("unused")
public ManageUserPage cancelEditUser() {
log.info("Click Cancel");
clickElement(cancelButton);
return new ManageUserPage(getDriver());
}
}
Expand Up @@ -24,6 +24,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.zanata.page.BasePage;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -65,6 +66,12 @@ private WebElement findRowByUserName(final String username) {
return null;
}

public boolean isUserEnabled(String username) {
List<WebElement> locks = findRowByUserName(username)
.findElements(By.className("i--lock"));
return locks.isEmpty();
}

public List<WebElement> getRows() {
return readyElement(userTable)
.findElements(By.className("list__item--actionable"));
Expand All @@ -91,4 +98,10 @@ public List<String> getUserList() {
}
return names;
}

public CreateUserAccountPage selectCreateNewUser() {
clickElement(By.id("rolemanage-more-actions"));
clickLinkAfterAnimation(By.linkText("Create new user"));
return new CreateUserAccountPage(getDriver());
}
}
Expand Up @@ -48,6 +48,12 @@ public RoleAssignmentsPage clickMoreActions() {
return new RoleAssignmentsPage(getDriver());
}

public EditRoleAssignmentPage selectCreateNewRule() {
log.info("Click Create New in dropdown");
clickLinkAfterAnimation(By.linkText("New Rule"));
return new EditRoleAssignmentPage(getDriver());
}

public EditRoleAssignmentPage clickCreateNew() {
log.info("Click Create New");
clickElement(newRuleButton);
Expand Down
Expand Up @@ -51,7 +51,6 @@ public void setUp() {
@Feature(summary = "The user can change their password",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 86823)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
@Category(BasicAcceptanceTest.class)
@Ignore("Flaky test")
public void changePasswordSuccessful() throws Exception {
DashboardBasePage dashboard = new LoginWorkFlow()
Expand Down
Expand Up @@ -72,7 +72,6 @@ public void before() {
@Feature(summary = "The user can register an account with Zanata",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 86816)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
@Category(BasicAcceptanceTest.class)
public void registerSuccessful() throws Exception {
RegisterPage registerPage = homePage
.goToRegistration()
Expand Down
Expand Up @@ -69,7 +69,6 @@ public void setUp() {
@Feature(summary = "The user can traverse Dashboard activity lists",
tcmsTestPlanIds = 5316, tcmsTestCaseIds = 0)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
@Category(BasicAcceptanceTest.class)
public void dashboardBasicTests() throws Exception {
assertThat(dashboardPresentAfterLogin()).as("Dashboard is present")
.isTrue();
Expand Down
@@ -0,0 +1,171 @@
/*
* Copyright 2017, 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.feature.endtoend;

import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.subethamail.wiser.WiserMessage;
import org.zanata.feature.testharness.TestPlan;
import org.zanata.feature.testharness.ZanataTestCase;
import org.zanata.page.administration.AdministrationPage;
import org.zanata.page.administration.ManageUserPage;
import org.zanata.page.administration.RoleAssignmentsPage;
import org.zanata.page.dashboard.DashboardBasePage;
import org.zanata.page.more.MorePage;
import org.zanata.page.utility.HomePage;
import org.zanata.util.HasEmailRule;
import org.zanata.workflow.LoginWorkFlow;

import static org.assertj.core.api.Assertions.assertThat;

@Category(TestPlan.BasicAcceptanceTest.class)
public class AdminEndToEndTest extends ZanataTestCase {

private final String ADMINUSER = "admin";
private final String USERNAME = "aloy";
private final String EMAIL = "aloy@example.com";
private final String PASSWORD = "4me2test";
private final String USERROLEREGEX = ".+lo.+";
private final String ADMINEMAIL = "admin@test.com";

@Rule
public final HasEmailRule hasEmailRule = new HasEmailRule();

@Test
public void adminEndToEndTest() {

// Change admin contact address
AdministrationPage administrationPage = setUpAdminContactEmail();

// Add a new user to the system
ManageUserPage manageUserPage = addNewUser(administrationPage);

// Enable the user directly, set their password
manageUserPage = updateAndEnableUser(manageUserPage);

// Log out
manageUserPage.logout();

// New user is supposed to be an admin
newUserRequestsAdminAccess();

// Admin create a rule assignment for users to be made admin
RoleAssignmentsPage roleAssignmentsPage = adminCreatesRoleAssignmentRule();

// Log out
roleAssignmentsPage.logout();

// New user logs in as admin
// May require two logins
DashboardBasePage dashboardBasePage = userLogsInAndIsGrantedAdmin();

// New admin updates the home page
updateTheHomePage(dashboardBasePage);
}

private AdministrationPage setUpAdminContactEmail() {
return new LoginWorkFlow()
.signIn(ADMINUSER, ADMINUSER)
.goToAdministration()
.goToServerConfigPage()
.inputAdminEmail(ADMINEMAIL)
.save();
// Tested by user sending contact admin email
}

private ManageUserPage addNewUser(AdministrationPage administrationPage) {
ManageUserPage manageUserPage = administrationPage.goToManageUserPage()
.selectCreateNewUser()
.enterUsername(USERNAME)
.enterEmail(EMAIL)
.clickRole("user")
.saveUser();
assertThat(manageUserPage.getUserList()).contains(USERNAME);
WiserMessage email = hasEmailRule.getMessages().get(0);
assertThat(email.getEnvelopeReceiver()).contains(EMAIL);
return manageUserPage;
}

private ManageUserPage updateAndEnableUser(ManageUserPage manageUserPage) {
manageUserPage = manageUserPage.editUserAccount(USERNAME)
.enterPassword(PASSWORD)
.enterConfirmPassword(PASSWORD)
.clickEnabled()
.saveUser();
assertThat(manageUserPage.isUserEnabled(USERNAME)).isTrue();
return manageUserPage;
}

private HomePage newUserRequestsAdminAccess() {
final String inputMessage = "Can you please make me admin?";
HomePage homePage = new LoginWorkFlow().signIn(USERNAME, PASSWORD)
.gotoMorePage()
.clickContactAdmin()
.inputMessage(inputMessage)
.send(MorePage.class)
.logout();
WiserMessage email = hasEmailRule.getMessages().get(1);
assertThat(email.getEnvelopeReceiver()).contains(ADMINEMAIL);
assertThat(email.getData()).contains(inputMessage.getBytes());
return homePage;
}

private RoleAssignmentsPage adminCreatesRoleAssignmentRule() {
RoleAssignmentsPage roleAssignmentsPage = new LoginWorkFlow()
.signIn(ADMINUSER, ADMINUSER)
.goToAdministration()
.goToManageRoleAssignments()
.clickMoreActions()
.selectCreateNewRule()
.enterIdentityPattern(USERROLEREGEX)
.selectRole("admin")
.saveRoleAssignment();
assertThat(roleAssignmentsPage.getRulesByPattern()).contains(USERROLEREGEX);
return roleAssignmentsPage;
}

private DashboardBasePage userLogsInAndIsGrantedAdmin() {
// May require two logins
DashboardBasePage dashboardBasePage;
{
dashboardBasePage = new LoginWorkFlow()
.signIn(USERNAME, PASSWORD);
if (!dashboardBasePage.isAdministrator()) {
dashboardBasePage.logout();
dashboardBasePage = new LoginWorkFlow()
.signIn(USERNAME, PASSWORD);
}
}
assertThat(dashboardBasePage.isAdministrator()).isTrue();
return dashboardBasePage;
}

private HomePage updateTheHomePage(DashboardBasePage dashboardBasePage) {
HomePage homePage = dashboardBasePage
.goToHomePage()
.goToEditPageContent()
.enterText("This is some stuff right here")
.update();
assertThat(homePage.getMainBodyContent()).contains("This is some stuff right here");
return homePage;
}
}
@@ -0,0 +1,32 @@
/*
* Copyright 2017, 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.feature.endtoend;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({
AdminEndToEndTest.class,
UserEndToEndTest.class
})
public class EndToEndTestSuite {
}
Expand Up @@ -57,8 +57,8 @@
/**
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
@Category(TestPlan.DetailedTest.class)
public class EndToEndTest extends ZanataTestCase {
@Category(TestPlan.BasicAcceptanceTest.class)
public class UserEndToEndTest extends ZanataTestCase {

@Rule
public ExpectedException expectedException = ExpectedException.none();
Expand Down

0 comments on commit 85577a2

Please sign in to comment.