Code formatting

application-manager-new
Menaka Madushanka 9 years ago
parent 7cf8fcf4ac
commit 67cb3df652

@ -0,0 +1,5 @@
package org.wso2.iot.integration.ui.pages;
public class UIConstants {
public static long webDriverTimeOut = 10;
}

@ -17,9 +17,6 @@
*/
package org.wso2.iot.integration.ui.pages;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
@ -29,8 +26,7 @@ import java.util.Properties;
*/
public class UIElementMapper {
public static final Properties uiPropertiies = new Properties();
private static final Log log = LogFactory.getLog(UIElementMapper.class);
public static final Properties uiProperties = new Properties();
private static UIElementMapper instance;
private UIElementMapper(){
@ -50,16 +46,16 @@ public class UIElementMapper {
InputStream inputStream = UIElementMapper.class.getResourceAsStream("/mapper.properties");
if (inputStream.available() > 0) {
uiPropertiies.load(inputStream);
uiProperties.load(inputStream);
inputStream.close();
return uiPropertiies;
return uiProperties;
}
return null;
}
public String getElement (String key) {
if (uiPropertiies != null) {
return uiPropertiies.getProperty(key);
if (!uiProperties.isEmpty()) {
return uiProperties.getProperty(key);
}
return null;
}

@ -32,7 +32,7 @@ public class EnrollDevicePage {
private WebDriver driver;
private UIElementMapper uiElementMapper;
public EnrollDevicePage(WebDriver driver) throws IOException{
public EnrollDevicePage(WebDriver driver) throws IOException {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
}

@ -17,12 +17,9 @@
*/
package org.wso2.iot.integration.ui.pages.groups;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
import java.io.IOException;
@ -34,17 +31,15 @@ import java.io.IOException;
*/
public class DeviceAddGroupPage {
private static final Log log = LogFactory.getLog(DeviceAddGroupPage.class);
private WebDriver driver;
private UIElementMapper uiElementMapper;
public DeviceAddGroupPage(WebDriver driver) throws IOException {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
WebDriverWait webDriverWait = new WebDriverWait(driver, 10);
if (!driver.findElement(By.xpath
(uiElementMapper.getElement("iot.device.group.addNewGroup.xpath"))).getText().contains("ADD NEW GROUP")){
(uiElementMapper.getElement("iot.device.group.addNewGroup.xpath"))).getText().contains("ADD NEW GROUP")) {
throw new IllegalStateException("This is not the Add Group page");
}
}
@ -54,9 +49,8 @@ public class DeviceAddGroupPage {
* @param name The group name that is need to be created.
* @param description the description for the group
* @return The resultant page.
* @throws Exception
*/
public DeviceGroupsPage addNewGroup (String name, String description) throws Exception{
public DeviceGroupsPage addNewGroup(String name, String description) throws IOException {
WebElement nameField = driver.findElement(By.id(
uiElementMapper.getElement("iot.device.group.addGroupForm.name.id")));

@ -17,13 +17,12 @@
*/
package org.wso2.iot.integration.ui.pages.groups;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIConstants;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
import java.io.IOException;
@ -31,14 +30,13 @@ import java.util.ArrayList;
import java.util.List;
public class DeviceGroupsPage {
private static final Log log = LogFactory.getLog(DeviceGroupsPage.class);
private WebDriver driver;
private UIElementMapper uiElementMapper;
public DeviceGroupsPage(WebDriver driver) throws IOException {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
WebDriverWait webDriverWait = new WebDriverWait(driver, 10);
WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut);
if (!webDriverWait.until(ExpectedConditions.textToBePresentInElement(driver.findElement(By.xpath(
uiElementMapper.getElement("iot.device.groups.view.header.xpath"))), "GROUPS"))) {
@ -46,14 +44,14 @@ public class DeviceGroupsPage {
}
}
public DeviceAddGroupPage addNewGroup() throws Exception {
public DeviceAddGroupPage addNewGroup() throws IOException {
WebElement addNewGroupBtn = driver.findElement(By.xpath(
uiElementMapper.getElement("iot.device.viewGroup.empty.addGroup.xpath")));
addNewGroupBtn.click();
return new DeviceAddGroupPage(driver);
}
public boolean isGroupCreated (String groupName) {
public boolean isGroupCreated(String groupName) {
WebElement table = driver.findElement(By.id(uiElementMapper.getElement("iot.device.table.id")));
List<WebElement> allGroupNames = table.findElements(By.tagName("h4"));
List<String> groupsList = new ArrayList<>();
@ -67,5 +65,4 @@ public class DeviceGroupsPage {
}
}

@ -73,22 +73,22 @@ public class IOTAdminDashboard {
return new LoginPage(driver);
}
public DeviceAddGroupPage addGroup() throws Exception {
public DeviceAddGroupPage addGroup() throws IOException {
driver.findElement(By.xpath(uiElementMapper.getElement("iot.device.group.addButton.xpath"))).click();
return new DeviceAddGroupPage(driver);
}
public DeviceGroupsPage viewGroups() throws Exception {
public DeviceGroupsPage viewGroups() throws IOException {
driver.findElement(By.xpath(uiElementMapper.getElement("iot.device.group.viewButton.xpath"))).click();
return new DeviceGroupsPage(driver);
}
public AddUserPage addUser() throws Exception {
public AddUserPage addUser() throws IOException {
driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.user.addButton.xpath"))).click();
return new AddUserPage(driver);
}
public UserListingPage viewUser() throws Exception {
public UserListingPage viewUser() throws IOException {
driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.user.viewButton.xpath"))).click();
return new UserListingPage(driver);
}

@ -17,13 +17,12 @@
*/
package org.wso2.iot.integration.ui.pages.home;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIConstants;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
import org.wso2.iot.integration.ui.pages.enroll.EnrollDevicePage;
import org.wso2.iot.integration.ui.pages.groups.DeviceAddGroupPage;
@ -36,7 +35,6 @@ import java.io.IOException;
* For admin this is the dashboard.
*/
public class IOTHomePage {
private static final Log log = LogFactory.getLog(IOTHomePage.class);
private WebDriver driver;
private UIElementMapper uiElementMapper;
@ -44,19 +42,19 @@ public class IOTHomePage {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
// Check that we're on the right page.
WebDriverWait wait = new WebDriverWait(driver, 10);
WebDriverWait wait = new WebDriverWait(driver, UIConstants.webDriverTimeOut);
if (!wait.until(ExpectedConditions.titleIs("Device Management | IoT Server"))) {
throw new IllegalStateException("This is not the home page");
}
}
public boolean checkUserName() throws Exception{
public boolean checkUserName() {
String name = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.registered.name"))).getText();
return name.contains(uiElementMapper.getElement("iot.user.login.username"));
}
//To logout
public LoginPage logout() throws Exception {
public LoginPage logout() throws IOException {
driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.registered.name"))).click();
WebElement logout = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.logout.link.xpath")));
logout.click();
@ -64,7 +62,7 @@ public class IOTHomePage {
}
//To enroll devices as user
public EnrollDevicePage enrollNewDevice() throws Exception{
public EnrollDevicePage enrollNewDevice() throws IOException {
driver.findElement(By.xpath("iot.home.page.uuf-menu.xpath")).click();
driver.findElement(By.xpath("iot.home.page.uuf-menu.devicemgt.xpath")).click();
driver.findElement(By.xpath("iot.home.enrollDevice.xpath")).click();
@ -72,12 +70,12 @@ public class IOTHomePage {
}
//To add new Device groups as user
public void goToGroupMgt() throws Exception {
public void goToGroupMgt() {
driver.findElement(By.xpath("iot.home.page.uuf-menu.xpath")).click();
driver.findElement(By.xpath("iot.home.page.uuf-menu.groupmgt.xpath")).click();
}
public DeviceAddGroupPage addNewGroup() throws Exception {
public DeviceAddGroupPage addNewGroup() throws IOException {
driver.findElement(By.xpath("iot.device.viewGroup.empty.addGroup.xpath")).click();
return new DeviceAddGroupPage(driver);
}

@ -24,6 +24,7 @@ import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIConstants;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard;
import org.wso2.iot.integration.ui.pages.home.IOTHomePage;
@ -43,7 +44,7 @@ public class LoginPage {
public LoginPage(WebDriver driver) throws IOException {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
WebDriverWait webDriverWait = new WebDriverWait(driver, 10);
WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut);
if (!webDriverWait.until(ExpectedConditions.titleContains("Login | IoT Server"))) {
throw new IllegalStateException("This is not the Login page");

@ -1,43 +1,44 @@
package org.wso2.iot.integration.ui.pages.uesr;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIConstants;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
import java.io.IOException;
/**
* This class represents the add user page of the IOT server.
*/
public class AddUserPage {
private static final Log log = LogFactory.getLog(AddUserPage.class);
private WebDriver driver;
private UIElementMapper uiElementMapper;
public AddUserPage(WebDriver driver) throws Exception {
public AddUserPage(WebDriver driver) throws IOException {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
WebDriverWait webDriverWait = new WebDriverWait(driver, 10);
if (!webDriverWait.until(ExpectedConditions.titleContains("User Management | IoT Server"))){
WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut);
if (!webDriverWait.until(ExpectedConditions.titleContains("User Management | IoT Server"))) {
throw new IllegalStateException("This is not the Add User page");
}
}
/**
* Method to create a new user.
*
* @param userName The username for the user.
* @param firstName The user's first name.
* @param lastName The user's last name.
* @param email Email address of the user.
* @return The user added confirmation page.
* @throws Exception
*/
public UserAddedConfirmationPage createNewUser(String userName, String firstName, String lastName, String email) throws Exception {
public UserAddedConfirmationPage createNewUser(String userName, String firstName, String lastName, String email)
throws IOException {
WebElement userNameField = driver.findElement(By.id(
uiElementMapper.getElement("iot.admin.addUser.username.id")));
@ -53,7 +54,7 @@ public class AddUserPage {
lastNameField.sendKeys(lastName);
emailField.sendKeys(email);
WebDriverWait wait = new WebDriverWait(driver, 10);
WebDriverWait wait = new WebDriverWait(driver, UIConstants.webDriverTimeOut);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
uiElementMapper.getElement("iot.admin.addUser.add.btn.xpath"))));

@ -6,6 +6,7 @@ import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIConstants;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
/**
@ -20,7 +21,7 @@ public class EditUserPage {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
WebDriverWait webDriverWait = new WebDriverWait(driver, 10);
WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut);
if (!webDriverWait.until(ExpectedConditions.titleContains("User Management | IoT Server"))){
throw new IllegalStateException("This is not the Edit User page");
}

@ -1,12 +1,11 @@
package org.wso2.iot.integration.ui.pages.uesr;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIConstants;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
import org.wso2.iot.integration.ui.pages.login.LoginPage;
@ -16,7 +15,6 @@ import java.io.IOException;
* This class represents the new user registration page.
*/
public class NewUserRegisterPage {
private static final Log log = LogFactory.getLog(NewUserRegisterPage.class);
private WebDriver driver;
private UIElementMapper uiElementMapper;
@ -24,14 +22,15 @@ public class NewUserRegisterPage {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
// Check that we're on the right page.
WebDriverWait webDriverWait = new WebDriverWait(driver, 10);
if (!webDriverWait.until(ExpectedConditions.titleContains("Register | IoT Server"))){
WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut);
if (!webDriverWait.until(ExpectedConditions.titleContains("Register | IoT Server"))) {
throw new IllegalStateException("This is not the Register page");
}
}
/**
* The method to register a new user.
*
* @param firstName First name of the user.
* @param lastName Last name of the user.
* @param email Email address of the user.

@ -6,6 +6,8 @@ import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
import java.io.IOException;
/**
* This class represents the confirmation page for adding a new user.
*/
@ -14,7 +16,7 @@ public class UserAddedConfirmationPage {
private WebDriver driver;
private UIElementMapper uiElementMapper;
public UserAddedConfirmationPage(WebDriver driver) throws Exception {
public UserAddedConfirmationPage(WebDriver driver) throws IOException {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
@ -23,5 +25,4 @@ public class UserAddedConfirmationPage {
}
}

@ -17,39 +17,33 @@
*/
package org.wso2.iot.integration.ui.pages.uesr;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
import java.io.IOException;
/**
* Class to represent the user listing page.
*/
public class UserListingPage {
private static final Log log = LogFactory.getLog(UserListingPage.class);
private WebDriver driver;
private UIElementMapper uiElementMapper;
public UserListingPage(WebDriver driver) throws Exception {
public UserListingPage(WebDriver driver) throws IOException {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
if (!driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.user.listing.page.subtitle.xpath")))
.getText().contains("USERS")){
throw new IllegalStateException("This is not the User Listing page");
}
}
/**
* @return After deleting a user, returns back to the user listing page.
* @throws Exception
*/
public UserListingPage deleteUser() throws Exception {
//Don't use generic exceptions.
public UserListingPage deleteUser() throws IOException, InterruptedException {
WebElement deleteBtn = driver.findElement(By.xpath(
uiElementMapper.getElement("iot.admin.deleteUser.btn.xpath")));
if (deleteBtn!=null){
if (deleteBtn != null) {
deleteBtn.click();
} else {
return new UserListingPage(driver);
@ -60,6 +54,4 @@ public class UserListingPage {
return new UserListingPage(driver);
}
}

@ -5,6 +5,7 @@ import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIConstants;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
/**
@ -19,7 +20,7 @@ public class ViewUserPage {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
WebDriverWait webDriverWait = new WebDriverWait(driver, 10);
WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut);
if (!webDriverWait.until(ExpectedConditions.titleContains("User Management | IoT Server"))){
throw new IllegalStateException("This is not the User view page");
}

@ -19,27 +19,25 @@ package org.wso2.carbon.iot.integration.web.ui.test;
import org.openqa.selenium.WebDriver;
import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
import org.wso2.iot.integration.ui.pages.login.LoginPage;
import javax.xml.xpath.XPathExpressionException;
import java.io.IOException;
/**
* This class is used to login to the system as the Admin.
*/
public class LoginUtils {
private static UIElementMapper uiElementMapper;
/**
*
* This method is used to login as admin.
*
* @param driver The selenium web driver
* @param automationContext Test Automation context
* @param webAppURL The server url
* @throws Exception
*/
public static void login(WebDriver driver, AutomationContext automationContext,
String webAppURL) throws Exception {
uiElementMapper = UIElementMapper.getInstance();
String webAppURL) throws IOException, XPathExpressionException {
driver.get(webAppURL + Constants.IOT_LOGIN_PATH);
LoginPage test = new LoginPage(driver);
test.loginAsAdmin(automationContext.getSuperTenant().getTenantAdmin().getUserName(),

@ -45,7 +45,7 @@ public class DeviceGroupFailTest extends IOTIntegrationUIBaseTestCase {
}
@Test(description = "Test for empty group name.")
public void addNewGroupFailTest () throws Exception {
public void addNewGroupFailTest() throws Exception {
driver.get(getWebAppURL() + Constants.IOT_GROUP_ADD_URL);
DeviceAddGroupPage addGroupPage = new DeviceAddGroupPage(driver);

@ -47,13 +47,13 @@ public class DeviceGroupTest extends IOTIntegrationUIBaseTestCase {
}
@Test(description = "Test for adding a new device group.")
public void addNewGroupTest () throws Exception {
public void addNewGroupTest() throws Exception {
DeviceAddGroupPage addGroupPage = adminDashboard.addGroup();
addGroupPage.addNewGroup("group1", "This is test group");
}
@Test (description = "Check whether the created group exists", dependsOnMethods = {"addNewGroupTest"})
public void isGroupCreatedTest () throws Exception {
@Test(description = "Check whether the created group exists", dependsOnMethods = {"addNewGroupTest"})
public void isGroupCreatedTest() throws Exception {
driver.get(getWebAppURL() + Constants.IOT_HOME_URL);
DeviceGroupsPage groupsPage = adminDashboard.viewGroups();
Assert.assertTrue(groupsPage.isGroupCreated("group1"));

@ -46,7 +46,7 @@ public class LoginFailTest extends IOTIntegrationUIBaseTestCase {
WebElement passwordField;
WebElement loginButton;
@BeforeClass (alwaysRun = true)
@BeforeClass(alwaysRun = true)
public void setup() throws Exception {
super.init();
driver = BrowserManager.getWebDriver();
@ -60,16 +60,14 @@ public class LoginFailTest extends IOTIntegrationUIBaseTestCase {
loginButton.click();
Assert.assertEquals(driver.findElement(By.id(uiElementMapper.getElement("iot.user.login.username.error")))
.getText(), "Please enter a username");
Assert.assertEquals(driver.findElement(By.id(uiElementMapper.getElement("iot.user.login.password.error")))
.getText(), "Please provide a password");
Assert.assertEquals(driver.findElement(By.id(uiElementMapper.getElement("iot.user.login.username.error"))).
getText(), "Please enter a username");
Assert.assertEquals(driver.findElement(By.id(uiElementMapper.getElement("iot.user.login.password.error"))).
getText(), "Please provide a password");
}
@Test (description = "Test for incorrect username")
@Test(description = "Test for incorrect username")
public void incorrectUserNameTest() throws Exception {
clearForm();
userNameField.sendKeys("admin1");
@ -77,12 +75,11 @@ public class LoginFailTest extends IOTIntegrationUIBaseTestCase {
loginButton.click();
Assert.assertEquals(driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.login.incorrect.xpath")))
.getText(), "Incorrect username or password.!");
Assert.assertEquals(driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.login.incorrect.xpath"))).
getText(), "Incorrect username or password.!");
}
@Test (description = "Test for incorrect password")
@Test(description = "Test for incorrect password")
public void incorrectPasswordTest() throws Exception {
clearForm();
@ -91,15 +88,13 @@ public class LoginFailTest extends IOTIntegrationUIBaseTestCase {
loginButton.click();
Assert.assertEquals(driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.login.incorrect.xpath")))
.getText(), "Incorrect username or password.!");
Assert.assertEquals(driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.login.incorrect.xpath"))).
getText(), "Incorrect username or password.!");
}
@Test (description = "Test for short password")
@Test(description = "Test for short password")
public void shortPasswordTest() throws Exception {
clearForm();
userNameField.sendKeys(automationContext.getSuperTenant().getTenantAdmin().getUserName());
@ -107,12 +102,11 @@ public class LoginFailTest extends IOTIntegrationUIBaseTestCase {
loginButton.click();
Assert.assertEquals(driver.findElement(By.id(uiElementMapper.getElement("iot.user.login.password.error")))
.getText(), "Your password must be at least 3 characters long");
Assert.assertEquals(driver.findElement(By.id(uiElementMapper.getElement("iot.user.login.password.error"))).
getText(), "Your password must be at least 3 characters long");
}
public void clearForm() throws Exception{
public void clearForm() throws Exception {
driver.get(getWebAppURL() + Constants.IOT_LOGIN_PATH);
uiElementMapper = UIElementMapper.getInstance();

@ -29,30 +29,29 @@ import org.wso2.iot.integration.ui.pages.login.LoginPage;
/**
* Test Login as Admin
*
*/
public class LoginTest extends IOTIntegrationUIBaseTestCase {
private WebDriver driver;
@BeforeClass (alwaysRun = true)
@BeforeClass(alwaysRun = true)
public void setup() throws Exception {
super.init();
driver = BrowserManager.getWebDriver();
driver.get(getWebAppURL() + Constants.IOT_LOGIN_PATH);
}
@Test (description = "Verify login to IOT server dashboard")
@Test(description = "Verify login to IOT server dashboard")
public void testAdminLogin() throws Exception {
LoginPage test = new LoginPage(driver);
IOTAdminDashboard dashboard = test.loginAsAdmin(
automationContext.getSuperTenant().getTenantAdmin().getUserName(),
automationContext.getSuperTenant().getTenantAdmin().getPassword());
dashboard.logout();
driver.close();
}
@AfterClass(alwaysRun = true)
public void tearDown() throws Exception {
driver.close();
driver.quit();
}
}

@ -24,13 +24,16 @@ import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.carbon.automation.extensions.selenium.BrowserManager;
import org.wso2.carbon.iot.integration.web.ui.test.Constants;
import org.wso2.carbon.iot.integration.web.ui.test.LoginUtils;
import org.wso2.iot.integration.ui.pages.IOTIntegrationUIBaseTestCase;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
import javax.xml.stream.XMLStreamException;
import javax.xml.xpath.XPathExpressionException;
import java.io.IOException;
/**
* Test cases for
* 1. Empty form submission
@ -52,7 +55,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
WebElement addUserButton;
@BeforeClass(alwaysRun = true)
public void setup() throws Exception {
public void setup() throws XPathExpressionException, XMLStreamException, IOException {
super.init();
driver = BrowserManager.getWebDriver();
LoginUtils.login(driver, automationContext, getWebAppURL());
@ -82,7 +85,6 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
Assert.assertEquals(driver.findElement(By.xpath(
uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))).getText(),
"Username is a required field. It cannot be empty.");
}
@Test(description = "Test for short user name")
@ -99,7 +101,6 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
Assert.assertEquals(driver.findElement(By.xpath(
uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))).getText(),
"Username must be between 3 and 30 characters long.");
}
@Test(description = "Test for empty first name")
@ -116,7 +117,6 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
Assert.assertEquals(driver.findElement(By.xpath(
uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))).getText(),
"Firstname is a required field. It cannot be empty.");
}
@Test(description = "Test for empty last name")
@ -132,7 +132,6 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
Assert.assertEquals(driver.findElement(By.xpath(
uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))).getText(),
"Lastname is a required field. It cannot be empty.");
}
@Test(description = "Test for empty email name")
@ -149,7 +148,6 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
Assert.assertEquals(driver.findElement(By.xpath(
uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))).getText(),
"Email is a required field. It cannot be empty.");
}
@Test(description = "Test for incorrect email")
@ -168,7 +166,8 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
"Provided email is invalid. Please check.");
}
public void clearForm() {
private void clearForm() {
firstNameField.clear();
lastNameField.clear();
emailField.clear();

@ -18,6 +18,7 @@
package org.wso2.carbon.iot.integration.web.ui.test.user;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -29,23 +30,26 @@ import org.wso2.iot.integration.ui.pages.home.IOTHomePage;
import org.wso2.iot.integration.ui.pages.login.LoginPage;
import org.wso2.iot.integration.ui.pages.uesr.NewUserRegisterPage;
import javax.xml.stream.XMLStreamException;
import javax.xml.xpath.XPathExpressionException;
import java.io.IOException;
/**
* Test for registering a new user and login
*
*/
public class RegisterTest extends IOTIntegrationUIBaseTestCase {
private WebDriver driver;
UIElementMapper uiElementMapper;
@BeforeClass(alwaysRun = true)
public void setup() throws Exception {
public void setup() throws XPathExpressionException, XMLStreamException, IOException {
super.init();
driver = BrowserManager.getWebDriver();
driver.get(getWebAppURL() + Constants.IOT_LOGIN_PATH);
}
@Test(description = "Verify new User registration")
public void testUserRegister() throws Exception {
public void userRegisterTest() throws IOException {
LoginPage test = new LoginPage(driver);
uiElementMapper = UIElementMapper.getInstance();
NewUserRegisterPage registerTest = test.registerNewUser();
@ -60,9 +64,7 @@ public class RegisterTest extends IOTIntegrationUIBaseTestCase {
IOTHomePage homePage = loginPage.loginAsUser(uiElementMapper.getElement("iot.user.add.username"),
uiElementMapper.getElement("iot.user.add.password"));
if (!homePage.checkUserName()){
throw new Exception("Incorrect user logged in");
}
Assert.assertTrue(homePage.checkUserName());
homePage.logout();

@ -31,6 +31,10 @@ import org.wso2.carbon.iot.integration.web.ui.test.Constants;
import org.wso2.iot.integration.ui.pages.IOTIntegrationUIBaseTestCase;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
import javax.xml.stream.XMLStreamException;
import javax.xml.xpath.XPathExpressionException;
import java.io.IOException;
/**
* These test cases check for following:
* - Submitting an empty form
@ -38,7 +42,7 @@ import org.wso2.iot.integration.ui.pages.UIElementMapper;
* - Non matching passwords
* - Password, username length
*/
public class RegistrationFormTests extends IOTIntegrationUIBaseTestCase{
public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCase {
private WebDriver driver;
UIElementMapper uiElementMapper;
@ -51,7 +55,7 @@ public class RegistrationFormTests extends IOTIntegrationUIBaseTestCase{
WebElement registerButton;
@BeforeClass(alwaysRun = true)
public void setup() throws Exception {
public void setup() throws XPathExpressionException, XMLStreamException, IOException {
super.init();
driver = BrowserManager.getWebDriver();
driver.get(getWebAppURL() + Constants.IOT_USER_REGISTER_URL);
@ -78,7 +82,7 @@ public class RegistrationFormTests extends IOTIntegrationUIBaseTestCase{
}
@Test(description = "Test for submitting an empty registration form")
public void emptyFormTest() throws Exception {
public void emptyFormTest() {
clearForm();
firstNameField.sendKeys("");
lastNameField.sendKeys("");
@ -109,8 +113,8 @@ public class RegistrationFormTests extends IOTIntegrationUIBaseTestCase{
"Please enter a user login password");
}
@Test (description = "Test for non matching passwords")
public void nonMatchingPasswordTest() throws Exception {
@Test(description = "Test for non matching passwords")
public void nonMatchingPasswordTest() {
clearForm();
firstNameField.sendKeys("User");
@ -126,8 +130,8 @@ public class RegistrationFormTests extends IOTIntegrationUIBaseTestCase{
"Please enter the same password as above");
}
@Test (description = "Test for email")
public void incorrectEmail() throws Exception {
@Test(description = "Test for email")
public void incorrectEmailTest() {
clearForm();
firstNameField.sendKeys("User");
@ -138,11 +142,10 @@ public class RegistrationFormTests extends IOTIntegrationUIBaseTestCase{
Assert.assertEquals(driver.findElement(By.id(
uiElementMapper.getElement("iot.user.register.email.error"))).getText(),
"Email is not valid. Please enter a correct email address.");
}
@Test (description = "Test for password length")
public void passwordLengthTest() throws Exception {
@Test(description = "Test for password length")
public void passwordLengthTest() {
clearForm();
firstNameField.sendKeys("User");
@ -156,11 +159,10 @@ public class RegistrationFormTests extends IOTIntegrationUIBaseTestCase{
Assert.assertEquals(driver.findElement(By.id(
uiElementMapper.getElement("iot.user.register.password.error"))).getText(),
"Password should be between 5 and 30 characters.");
}
@AfterClass(alwaysRun = true)
public void tearDown() throws Exception {
public void tearDown() {
driver.quit();
}

@ -29,6 +29,10 @@ import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard;
import org.wso2.iot.integration.ui.pages.uesr.AddUserPage;
import org.wso2.iot.integration.ui.pages.uesr.UserListingPage;
import javax.xml.stream.XMLStreamException;
import javax.xml.xpath.XPathExpressionException;
import java.io.IOException;
/**
* Test for check following admin capabilities.
* - Create a new User
@ -39,28 +43,27 @@ public class TestAdminFunctions extends IOTIntegrationUIBaseTestCase {
private WebDriver driver;
@BeforeClass(alwaysRun = true)
public void setup() throws Exception {
public void setup() throws IOException, XPathExpressionException, XMLStreamException {
super.init();
driver = BrowserManager.getWebDriver();
LoginUtils.login(driver, automationContext, getWebAppURL());
}
@Test(description = "Test for creating a new user")
public void createUserTest() throws Exception {
public void createUserTest() throws IOException {
IOTAdminDashboard adminDashboard = new IOTAdminDashboard(driver);
AddUserPage addUserPage = adminDashboard.addUser();
addUserPage.createNewUser("user1", "User", "User", "user@wso2.com");
}
@Test(description = "Test for deleting a created user", dependsOnMethods = {"createUserTest"})
public void deleteUserTest() throws Exception {
public void deleteUserTest() throws XPathExpressionException, IOException, InterruptedException {
driver.get(getWebAppURL() + Constants.IOT_HOME_URL);
IOTAdminDashboard adminDashboard = new IOTAdminDashboard(driver);
UserListingPage userListingPage = adminDashboard.viewUser();
userListingPage.deleteUser();
}
@AfterClass(alwaysRun = true)
public void tearDown() throws Exception {
driver.quit();

@ -307,7 +307,7 @@
<dependency>
<groupId>org.wso2.iot</groupId>
<artifactId>org.wso2.carbon.iot.integration.ui.pages</artifactId>
<version>${carbon.device.mgt.plugin.version}</version>
<version>${carbon.iot.device.mgt.version}</version>
<scope>test</scope>
</dependency>
@ -1049,6 +1049,9 @@
<carbon.device.mgt.version>1.1.0-SNAPSHOT</carbon.device.mgt.version>
<carbon.device.mgt.version.range>[0.8.0, 2.0.0)</carbon.device.mgt.version.range>
<!-- IOT Device Management -->
<carbon.iot.device.mgt.version>1.0.0-SNAPSHOT</carbon.iot.device.mgt.version>
<!-- Carbon Device Management Plugins-->
<carbon.device.mgt.plugin.version>2.0.4-SNAPSHOT</carbon.device.mgt.plugin.version>
<mdm.version>2.0.0-SNAPSHOT</mdm.version>

Loading…
Cancel
Save