fixed verifyEmail test

This commit is contained in:
vramik 2015-10-09 13:43:16 +02:00
parent e5d404fdb3
commit 1b41832946
5 changed files with 61 additions and 17 deletions

View file

@ -44,14 +44,6 @@ public class LoginActions extends AuthRealm {
@FindBy(css = "span.kc-feedback-text")
private WebElement feedbackText;
@FindBy(xpath = "//div[@id='kc-error-message']/p")
private WebElement error;
public String getErrorMessage() {
waitGuiForElementPresent(error, "Error message should be visible");
return error.getText();
}
public String getFeedbackText() {
waitGuiForElementPresent(feedbackText, "Feedback message should be visible");
return feedbackText.getText();

View file

@ -1,9 +1,41 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, 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.keycloak.testsuite.auth.page.login;
import static org.keycloak.testsuite.util.WaitUtils.waitGuiForElement;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
/**
*
* @author vramik
* @author <a href="mailto:vramik@redhat.com">Vlastislav Ramik</a>
*/
public class VerifyEmail extends Authenticate {
@FindBy(xpath = "//div[@id='kc-form-wrapper']/p")
private WebElement instruction;
public String getInstructionMessage() {
waitGuiForElement(instruction);
return instruction.getText();
}
}

View file

@ -1,5 +1,6 @@
package org.keycloak.testsuite.console.page.realm;
import java.util.Map;
import org.jboss.arquillian.graphene.findby.FindByJQuery;
import org.jboss.arquillian.graphene.page.Page;
import org.keycloak.testsuite.console.page.fragment.OnOffSwitch;
@ -66,5 +67,13 @@ public class EmailSettings extends RealmSettings {
public void setFromInput(String value) {
setInputValue(fromInput, value);
}
public void setSmtpServer(Map<String, String> smtpServer) {
setFromInput(smtpServer.get("from"));
setHostInput(smtpServer.get("host"));
setPortInput(smtpServer.get("port"));
save();
}
}
}

View file

@ -49,7 +49,7 @@ public class VerifyEmailTest extends AbstractAccountManagementTest {
@Before
public void beforeVerifyEmail() {
// enable verify email and configure smpt server in test realm
log.info("enable verify email and configure smpt server in test realm");
RealmRepresentation testRealmRep = testRealmResource().toRepresentation();
testRealmRep.setSmtpServer(suiteContext.getSmtpServer());
testRealmRep.setVerifyEmail(true);
@ -75,11 +75,11 @@ public class VerifyEmailTest extends AbstractAccountManagementTest {
assertEquals("You need to verify your email address to activate your account.",
testRealmVerifyEmailPage.getFeedbackText());
String url = assertEmailAndGetUrl(MailServerConfiguration.FROM, testUser.getEmail(),
String verifyEmailUrl = assertEmailAndGetUrl(MailServerConfiguration.FROM, testUser.getEmail(),
"Someone has created a Test account with this email address.");
log.info("navigating to " + url);
driver.navigate().to(url);
log.info("navigating to url from email: " + verifyEmailUrl);
driver.navigate().to(verifyEmailUrl);
assertCurrentUrlStartsWith(testRealmAccountManagementPage);
testRealmAccountManagementPage.signOut();
testRealmLoginPage.form().login(testUser);

View file

@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import static org.keycloak.representations.idm.CredentialRepresentation.PASSWORD;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
import static org.keycloak.testsuite.admin.ApiUtil.createUserAndResetPasswordWithAdminClient;
import static org.keycloak.testsuite.admin.Users.setPasswordFor;
@ -36,6 +37,7 @@ import org.keycloak.testsuite.auth.page.login.Registration;
import org.keycloak.testsuite.auth.page.login.ResetCredentials;
import org.keycloak.testsuite.auth.page.login.VerifyEmail;
import org.keycloak.testsuite.console.page.realm.LoginSettings.RequireSSLOption;
import org.keycloak.testsuite.util.MailServer;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith;
import org.openqa.selenium.Cookie;
@ -43,7 +45,6 @@ import org.openqa.selenium.Cookie;
/**
*
* @author tkyjovsk
* @author vramik
*/
public class LoginSettingsTest extends AbstractRealmTest {
@ -210,15 +211,23 @@ public class LoginSettingsTest extends AbstractRealmTest {
@Test
public void verifyEmail() {
log.info("enabling verify email");
MailServer.start();
MailServer.createEmailAccount(testUser.getEmail(), "password");
log.info("enabling verify email in login settings");
loginSettingsPage.form().setVerifyEmailAllowed(true);
loginSettingsPage.form().save();
log.debug("enabled");
log.info("configure smpt server in test realm");
RealmRepresentation testRealmRep = testRealmResource().toRepresentation();
testRealmRep.setSmtpServer(suiteContext.getSmtpServer());
testRealmResource().update(testRealmRep);
testAccountPage.navigateTo();
testRealmLoginPage.form().login(testUser);
Assert.assertEquals("Failed to send email, please try again later.",
testRealmVerifyEmailPage.getErrorMessage());
Assert.assertEquals("An email with instructions to verify your email address has been sent to you.",
testRealmVerifyEmailPage.getInstructionMessage());
log.info("verified verify email is enabled");
@ -241,6 +250,8 @@ public class LoginSettingsTest extends AbstractRealmTest {
testAccountPage.waitForAccountLinkPresent();
log.info("verified verify email is disabled");
MailServer.stop();
}
@Test