From 6858fb8a85b3f49f7cd1e619f53d7106c350fb0b Mon Sep 17 00:00:00 2001 From: Menaka Madushanka Date: Thu, 10 Mar 2016 16:31:43 +0530 Subject: [PATCH] Code cleanup and refactoring : Check alert is displayed --- .../user/RegistrationFormValidationTest.java | 88 +++++++++++++------ 1 file changed, 60 insertions(+), 28 deletions(-) diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTest.java index 79d87d94..b32ccaa9 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTest.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTest.java @@ -19,6 +19,7 @@ package org.wso2.carbon.iot.integration.web.ui.test.user; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -52,57 +53,88 @@ public class RegistrationFormValidationTest extends IOTIntegrationUIBaseTestCase driver.get(getWebAppURL() + Constants.IOT_USER_REGISTER_URL); registerPage = new NewUserRegisterPage(driver); uiElementMapper = UIElementMapper.getInstance(); -} + } @Test(description = "Test for submitting an empty registration form") public void emptyFormTest() throws IOException { registerPage.clearForm(); registerPage.validateForm("", "", "", "", "", ""); - Assert.assertEquals(driver.findElement(By.id( - uiElementMapper.getElement("iot.user.register.firstname.error"))).getText(), - "Firstname is a required field. This cannot be empty."); - Assert.assertEquals(driver.findElement(By.id( - uiElementMapper.getElement("iot.user.register.lastname.error"))).getText(), - "Lastname is a required field. This cannot be empty."); - Assert.assertEquals(driver.findElement(By.id( - uiElementMapper.getElement("iot.user.register.email.error"))).getText(), - "Email is a required field. This cannot be empty."); - Assert.assertEquals(driver.findElement(By.id( - uiElementMapper.getElement("iot.user.register.username.error"))).getText(), - "Username is a required field. This cannot be empty."); - Assert.assertEquals(driver.findElement(By.id( - uiElementMapper.getElement("iot.user.register.password.error"))).getText(), - "Please enter a user login password"); - Assert.assertEquals(driver.findElement(By.id( - uiElementMapper.getElement("iot.user.register.confirmPassword.error"))).getText(), - "Please enter a user login password"); + WebElement alertFirstName = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.firstname.error"))); + WebElement alertLastName = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.lastname.error"))); + WebElement alertEmail = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.email.error"))); + WebElement alertUserName = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.username.error"))); + WebElement alertPassword = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.password.error"))); + WebElement alertConfPassword = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.confirmPassword.error"))); + + if (!alertFirstName.isDisplayed()) { + Assert.assertTrue(false, "Alert for first name is not displayed"); + } + if (!alertLastName.isDisplayed()) { + Assert.assertTrue(false, "Alert for last name is not displayed"); + } + if (!alertEmail.isDisplayed()) { + Assert.assertTrue(false, "Alert for email is not displayed"); + } + if (!alertUserName.isDisplayed()) { + Assert.assertTrue(false, "Alert for user name is not displayed"); + } + if (!alertPassword.isDisplayed()) { + Assert.assertTrue(false, "Alert for password is not displayed"); + } + if (!alertConfPassword.isDisplayed()) { + Assert.assertTrue(false, "Alert for confirm password is not displayed"); + } + + Assert.assertEquals(alertFirstName.getText(), "Firstname is a required field. This cannot be empty."); + Assert.assertEquals(alertLastName.getText(), "Lastname is a required field. This cannot be empty."); + Assert.assertEquals(alertEmail.getText(), "Email is a required field. This cannot be empty."); + Assert.assertEquals(alertUserName.getText(), "Username is a required field. This cannot be empty."); + Assert.assertEquals(alertPassword.getText(), "Please enter a user login password"); + Assert.assertEquals(alertConfPassword.getText(), "Please enter a user login password"); } @Test(description = "Test for non matching passwords") public void nonMatchingPasswordTest() { registerPage.validateForm("user", "user", "user@wso2.com", "user1", "password", "Password"); + WebElement alertConfPassword = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.confirmPassword.error"))); + + if (!alertConfPassword.isDisplayed()) { + Assert.assertTrue(false, "Alert for confirm password is not displayed"); + } - Assert.assertEquals(driver.findElement(By.id( - uiElementMapper.getElement("iot.user.register.confirmPassword.error"))).getText(), - "Please enter the same password as above"); + Assert.assertEquals(alertConfPassword.getText(), "Please enter the same password as above"); } @Test(description = "Test for email") public void incorrectEmailTest() { registerPage.validateForm("user", "user", "user123", "user1", "password", "password"); + WebElement alertEmail = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.email.error"))); + if (!alertEmail.isDisplayed()) { + Assert.assertTrue(false, "Alert for email is not displayed"); + } - Assert.assertEquals(driver.findElement(By.id( - uiElementMapper.getElement("iot.user.register.email.error"))).getText(), - "Email is not valid. Please enter a correct email address."); + Assert.assertEquals(alertEmail.getText(), "Email is not valid. Please enter a correct email address."); } @Test(description = "Test for password length") public void passwordLengthTest() { registerPage.validateForm("user", "user", "user@wso2.com", "user1", "pass", "pass"); - Assert.assertEquals(driver.findElement(By.id( - uiElementMapper.getElement("iot.user.register.password.error"))).getText(), - "Password should be between 5 and 30 characters."); + WebElement alertPassword = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.password.error"))); + if (!alertPassword.isDisplayed()) { + Assert.assertTrue(false, "Alert for password is not displayed"); + } + + Assert.assertEquals(alertPassword.getText(), "Password should be between 5 and 30 characters."); } @AfterClass(alwaysRun = true)