Code cleanup and refactoring : Check alert is displayed

application-manager-new
Menaka Madushanka 9 years ago
parent b930301819
commit 6858fb8a85

@ -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;
@ -59,50 +60,81 @@ public class RegistrationFormValidationTest extends IOTIntegrationUIBaseTestCase
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)

Loading…
Cancel
Save