diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/IOTIntegrationUIBaseTestCase.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/IOTIntegrationUIBaseTestCase.java index 6b0a0b41..915d2a4c 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/IOTIntegrationUIBaseTestCase.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/IOTIntegrationUIBaseTestCase.java @@ -49,14 +49,12 @@ public class IOTIntegrationUIBaseTestCase { } protected String getSessionCookie(AutomationContext context) - throws RemoteException, XPathExpressionException, - LoginAuthenticationExceptionException { + throws RemoteException, XPathExpressionException, LoginAuthenticationExceptionException { AuthenticatorClient authenticationAdminClient = new AuthenticatorClient(context.getContextUrls().getBackEndUrl()); return authenticationAdminClient.login(automationContext.getSuperTenant(). - getTenantAdmin().getUserName(), automationContext.getSuperTenant(). - getTenantAdmin().getPassword(), - automationContext.getDefaultInstance().getHosts().get("default")); - + getTenantAdmin().getUserName(), automationContext.getSuperTenant(). + getTenantAdmin().getPassword(), + automationContext.getDefaultInstance().getHosts().get("default")); } protected String getServiceURL() throws XPathExpressionException { diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIConstants.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIConstants.java index c5508178..e43d90bb 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIConstants.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIConstants.java @@ -2,4 +2,5 @@ package org.wso2.iot.integration.ui.pages; public class UIConstants { public static long webDriverTimeOut = 10; + public static int threadTimeout = 1000; } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIElementMapper.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIElementMapper.java index c209d8cd..a39c3133 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIElementMapper.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIElementMapper.java @@ -30,7 +30,6 @@ public class UIElementMapper { private static UIElementMapper instance; private UIElementMapper(){ - } public static synchronized UIElementMapper getInstance() throws IOException { @@ -59,6 +58,4 @@ public class UIElementMapper { } return null; } - - } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/enroll/EnrollDevicePage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/enroll/EnrollDevicePage.java index 4171cf85..b2d00c1a 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/enroll/EnrollDevicePage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/enroll/EnrollDevicePage.java @@ -36,5 +36,4 @@ public class EnrollDevicePage { this.driver = driver; this.uiElementMapper = UIElementMapper.getInstance(); } - } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceAddGroupPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceAddGroupPage.java index d3f7f635..cd7d93fa 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceAddGroupPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceAddGroupPage.java @@ -65,7 +65,6 @@ public class DeviceAddGroupPage { addGroupButton.click(); return new DeviceGroupsPage(driver); - } /** @@ -87,5 +86,4 @@ public class DeviceAddGroupPage { return driver.findElement(By.xpath( uiElementMapper.getElement("iot.device.groups.add.emptyfrom.error"))).getText(); } - } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceGroupsPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceGroupsPage.java index 56a7aca0..939b9851 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceGroupsPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceGroupsPage.java @@ -63,6 +63,4 @@ public class DeviceGroupsPage { return groupsList.contains(groupName); } - - } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/login/LoginPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/login/LoginPage.java index dbad5c00..8edf8c16 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/login/LoginPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/login/LoginPage.java @@ -100,5 +100,4 @@ public class LoginPage { registerLink.click(); return new NewUserRegisterPage(driver); } - } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/AddUserPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/AddUserPage.java index 78039256..80361fbe 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/AddUserPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/AddUserPage.java @@ -62,6 +62,4 @@ public class AddUserPage { return new UserAddedConfirmationPage(driver); } - - } \ No newline at end of file diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/EditUserPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/EditUserPage.java index 8e87f150..075320c1 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/EditUserPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/EditUserPage.java @@ -30,5 +30,4 @@ public class EditUserPage { public void editUser(String password, String firstName, String lastName) { driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.add.input.password.xpath"))); } - } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/NewUserRegisterPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/NewUserRegisterPage.java index a371e6cb..862fc0f5 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/NewUserRegisterPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/NewUserRegisterPage.java @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.wso2.iot.integration.ui.pages.uesr; import org.openqa.selenium.By; @@ -13,19 +30,42 @@ import java.io.IOException; /** * This class represents the new user registration page. + * User registration page has the registration form for new users to enter the required data and the submit button. */ public class NewUserRegisterPage { private WebDriver driver; - private UIElementMapper uiElementMapper; + private WebElement firstNameField; + private WebElement lastNameField; + private WebElement emailField; + private WebElement userNameField; + private WebElement passwordField; + private WebElement passwordConfirmationField; + private WebElement registerButton; public NewUserRegisterPage(WebDriver driver) throws IOException { this.driver = driver; - this.uiElementMapper = UIElementMapper.getInstance(); + UIElementMapper uiElementMapper = UIElementMapper.getInstance(); + // Check that we're on the right page. WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut); if (!webDriverWait.until(ExpectedConditions.titleContains("Register | IoT Server"))) { throw new IllegalStateException("This is not the Register page"); } + + firstNameField = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.add.input.firstname.xpath"))); + lastNameField = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.add.input.lastname.xpath"))); + emailField = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.add.input.email.xpath"))); + userNameField = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.add.input.username.xpath"))); + passwordField = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.add.input.password.xpath"))); + passwordConfirmationField = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.add.input.confirmpassword.xpath"))); + registerButton = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.add.register.button.xpath"))); } /** @@ -41,28 +81,37 @@ public class NewUserRegisterPage { * @throws IOException */ public LoginPage registerUser(String firstName, String lastName, String email, String userName, String password, - String - confirmPassword) throws IOException { - WebElement firstNameField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.firstname.xpath"))); - WebElement lastNameField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.lastname.xpath"))); - WebElement emailField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.email.xpath"))); - WebElement userNameField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.username.xpath"))); - WebElement passwordField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.password.xpath"))); - WebElement passwordConfirmationField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.confirmpassword.xpath"))); + String confirmPassword) throws IOException { + handleAction(firstName, lastName, email, userName, password, confirmPassword); + return new LoginPage(driver); + } + + /** + * Following method is to validate the user registration form. + * */ + public void validateForm(String firstName, String lastName, String email, String userName, + String password, String confirmPassword) { + handleAction(firstName, lastName, email, userName, password, confirmPassword); + } + + public void handleAction(String firstName, String lastName, String email, String userName, String password, + String confirmPassword) { + clearForm(); firstNameField.sendKeys(firstName); lastNameField.sendKeys(lastName); emailField.sendKeys(email); userNameField.sendKeys(userName); passwordField.sendKeys(password); passwordConfirmationField.sendKeys(confirmPassword); - driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.add.register.button.xpath"))).click(); - return new LoginPage(driver); + registerButton.click(); } + public void clearForm() { + firstNameField.clear(); + lastNameField.clear(); + emailField.clear(); + userNameField.clear(); + passwordField.clear(); + passwordConfirmationField.clear(); + } } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserAddedConfirmationPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserAddedConfirmationPage.java index a137db69..4fb93af4 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserAddedConfirmationPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserAddedConfirmationPage.java @@ -21,8 +21,5 @@ public class UserAddedConfirmationPage { this.uiElementMapper = UIElementMapper.getInstance(); driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.addUser.view.btn.xpath"))).click(); - } - - } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserListingPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserListingPage.java index 86df142a..d6afbb28 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserListingPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserListingPage.java @@ -20,6 +20,9 @@ package org.wso2.iot.integration.ui.pages.uesr; 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; @@ -39,18 +42,23 @@ public class UserListingPage { /** * @return After deleting a user, returns back to the user listing page. */ - //Don't use generic exceptions. - public UserListingPage deleteUser() throws IOException, InterruptedException { + public UserListingPage deleteUser() throws IOException { WebElement deleteBtn = driver.findElement(By.xpath( uiElementMapper.getElement("iot.admin.deleteUser.btn.xpath"))); - if (deleteBtn != null) { - deleteBtn.click(); - } else { - return new UserListingPage(driver); - } - driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.deleteUser.yes.link.xpath"))).click(); - Thread.sleep(1000); - driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.deleteUser.success.link.xpath"))).click(); + + WebDriverWait wait = new WebDriverWait(driver, UIConstants.webDriverTimeOut); + wait.until(ExpectedConditions.visibilityOf(deleteBtn)); + deleteBtn.click(); + + WebElement deleteConfirmationBtn = driver.findElement( + By.xpath(uiElementMapper.getElement("iot.admin.deleteUser.yes.link.xpath"))); + wait.until(ExpectedConditions.visibilityOf(deleteConfirmationBtn)); + deleteConfirmationBtn.click(); + + WebElement deleteSuccessBtn = driver.findElement( + By.xpath(uiElementMapper.getElement("iot.admin.deleteUser.success.link.xpath"))); + wait.until(ExpectedConditions.visibilityOf(deleteSuccessBtn)); + deleteSuccessBtn.click(); return new UserListingPage(driver); } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/ViewUserPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/ViewUserPage.java index dc514154..b691e9ff 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/ViewUserPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/ViewUserPage.java @@ -25,7 +25,4 @@ public class ViewUserPage { throw new IllegalStateException("This is not the User view page"); } } - - - } diff --git a/modules/integration/tests-iot-web-ui/pom.xml b/modules/integration/tests-iot-web-ui/pom.xml index b79b49a6..d35748df 100644 --- a/modules/integration/tests-iot-web-ui/pom.xml +++ b/modules/integration/tests-iot-web-ui/pom.xml @@ -48,9 +48,9 @@ src/test/resources/testng.xml - + true maven.test.haltafterfailure false @@ -245,30 +245,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -291,8 +267,5 @@ - - true - diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/LoginUtils.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/LoginUtils.java index e1102919..f03f21aa 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/LoginUtils.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/LoginUtils.java @@ -25,7 +25,7 @@ import javax.xml.xpath.XPathExpressionException; import java.io.IOException; /** - * This class is used to login to the system as the Admin. + * This class is used to login to the server as the Admin. */ public class LoginUtils { @@ -43,6 +43,4 @@ public class LoginUtils { test.loginAsAdmin(automationContext.getSuperTenant().getTenantAdmin().getUserName(), automationContext.getSuperTenant().getTenantAdmin().getPassword()); } - - } diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/TestRestartServer.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/TestRestartServer.java deleted file mode 100644 index f75f7555..00000000 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/TestRestartServer.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.wso2.carbon.iot.integration.web.ui.test; - -/** - * Created by menaka on 2/23/16. - */ -public class TestRestartServer { -} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/group/DeviceGroupTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/group/DeviceGroupTest.java index 42e935c5..77a8a3c5 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/group/DeviceGroupTest.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/group/DeviceGroupTest.java @@ -31,6 +31,9 @@ import org.wso2.iot.integration.ui.pages.groups.DeviceAddGroupPage; import org.wso2.iot.integration.ui.pages.groups.DeviceGroupsPage; import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + /** * Test cases for grouping feature of IOT server. */ @@ -47,13 +50,13 @@ public class DeviceGroupTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for adding a new device group.") - public void addNewGroupTest() throws Exception { + public void addNewGroupTest() throws IOException { 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 { + public void isGroupCreatedTest() throws IOException, XPathExpressionException { driver.get(getWebAppURL() + Constants.IOT_HOME_URL); DeviceGroupsPage groupsPage = adminDashboard.viewGroups(); Assert.assertTrue(groupsPage.isGroupCreated("group1")); @@ -63,5 +66,4 @@ public class DeviceGroupTest extends IOTIntegrationUIBaseTestCase { public void tearDown() throws Exception { driver.quit(); } - } diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/login/LoginTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/login/LoginTest.java index 399caa86..db8733e3 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/login/LoginTest.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/login/LoginTest.java @@ -27,6 +27,10 @@ import org.wso2.iot.integration.ui.pages.IOTIntegrationUIBaseTestCase; import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard; import org.wso2.iot.integration.ui.pages.login.LoginPage; +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + /** * Test Login as Admin */ @@ -34,14 +38,14 @@ public class LoginTest extends IOTIntegrationUIBaseTestCase { private WebDriver driver; @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 login to IOT server dashboard") - public void testAdminLogin() throws Exception { + public void testAdminLogin() throws IOException, XPathExpressionException { LoginPage test = new LoginPage(driver); IOTAdminDashboard dashboard = test.loginAsAdmin( automationContext.getSuperTenant().getTenantAdmin().getUserName(), @@ -50,8 +54,7 @@ public class LoginTest extends IOTIntegrationUIBaseTestCase { } @AfterClass(alwaysRun = true) - public void tearDown() throws Exception { - driver.close(); + public void tearDown(){ driver.quit(); } } diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstall.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstall.java deleted file mode 100644 index 45b06c90..00000000 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstall.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.wso2.carbon.iot.integration.web.ui.test.samples; - -/** - * Created by menaka on 2/24/16. - */ -public class SampleInstall { -} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationTest.java new file mode 100644 index 00000000..863f6075 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationTest.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.iot.integration.web.ui.test.samples; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +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.exceptions.AutomationFrameworkException; +import org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerManager; +import org.wso2.iot.integration.ui.pages.IOTIntegrationUIBaseTestCase; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Properties; + + +/** + * Test cases for building and installation of sample device types. + * When installing a custom device type to the IOT server, developer has to create the device type as a feature and + * put it in to the samples folder. + * Then build the device type created with maven. + * After that install the device type by running the device-deployer.xml. + * Then the server has to be restarted, in order to activate newly installed device type. + *

+ * In this test case, the build process of a new device type and installation to the server is tested. + */ +public class SampleInstallationTest extends IOTIntegrationUIBaseTestCase { + Log log = LogFactory.getLog(SampleInstallationTest.class); + private Process tempProcess = null; + private Properties properties = System.getProperties(); + private String carbonHome = properties.getProperty("carbon.home"); + private String[] cmdArray; + + @BeforeClass(alwaysRun = true) + public void setup() throws XPathExpressionException, XMLStreamException, IOException, AutomationFrameworkException { + super.init(); + } + + @Test(description = "Verify the sample build process") + public void sampleBuildTest() throws IOException { + String connectedCupDir = carbonHome + File.pathSeparator + "samples" + File.pathSeparator + "connectedcup"; + log.info("Connected cup Sample: " + connectedCupDir); + File dir = new File(connectedCupDir); + try { + if (System.getProperty("os.name").toLowerCase().contains("windows")) { + log.info("Executing maven clean install --------------------------------"); + cmdArray = new String[]{"cmd.exe", "/c", "mvn clean install"}; + tempProcess = Runtime.getRuntime().exec(cmdArray, null, dir); + + } else { + log.info("Executing maven clean install --------------------------------"); + cmdArray = new String[]{"mvn", "clean", "install"}; + tempProcess = Runtime.getRuntime().exec(cmdArray, null, dir); + } + + boolean buildStatus = waitForMessage(tempProcess.getInputStream(), "BUILD SUCCESS"); + Assert.assertTrue(buildStatus, "Building the sample was not successful"); + } finally { + if (tempProcess != null) { + tempProcess.destroy(); + } + } + } + + @Test(description = "Verify the sample installation process", dependsOnMethods = {"sampleBuildTest"}) + public void sampleInstallationTest() throws IOException { + + log.info("CARBON_HOME: " + System.getProperty("carbon.home")); + File dir = new File(carbonHome); + log.info("Sample installation started : mvn clean install -f device-deployer.xml"); + try { + if (System.getProperty("os.name").toLowerCase().contains("windows")) { + cmdArray = new String[]{"cmd.exe", "/c", "mvn clean install -f device-deployer.xml"}; + tempProcess = Runtime.getRuntime().exec(cmdArray, null, dir); + } else { + cmdArray = new String[]{"mvn", "clean", "install", "-f", "device-deployer.xml"}; + tempProcess = Runtime.getRuntime().exec(cmdArray, null, dir); + } + boolean buildStatus = waitForMessage(tempProcess.getInputStream(), "BUILD SUCCESS"); + Assert.assertTrue(buildStatus, "Sample installation was not successful"); + } finally { + if (tempProcess != null) { + tempProcess.destroy(); + } + } + } + + @Test(description = "Test restarting the server", dependsOnMethods = {"sampleInstallationTest"}) + public void serverRestartTest() { + CarbonServerManager serverManager = new CarbonServerManager(automationContext); + try { + serverManager.restartGracefully(); + } catch (AutomationFrameworkException e) { + log.error("Restart failed...."); + } + } + + @AfterClass(alwaysRun = true) + public void tearDown() throws Exception { + } + + public boolean waitForMessage(InputStream inputStream, String message) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); + String line; + boolean status = false; + while ((line = br.readLine()) != null) { + log.info(line); + if (!status && line.contains(message)) { + status = true; + } + } + return status; + } +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFailTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFormValidationTest.java similarity index 90% rename from modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFailTest.java rename to modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFormValidationTest.java index 8ea6b5d0..472cf2d4 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFailTest.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFormValidationTest.java @@ -43,16 +43,16 @@ import java.io.IOException; * 5. Empty email * 6. Incorrect email */ -public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { +public class AddUserFormValidationTest extends IOTIntegrationUIBaseTestCase { private WebDriver driver; - UIElementMapper uiElementMapper; + private UIElementMapper uiElementMapper; - WebElement firstNameField; - WebElement lastNameField; - WebElement emailField; - WebElement userNameField; - WebElement addUserButton; + private WebElement firstNameField; + private WebElement lastNameField; + private WebElement emailField; + private WebElement userNameField; + private WebElement addUserButton; @BeforeClass(alwaysRun = true) public void setup() throws XPathExpressionException, XMLStreamException, IOException { @@ -60,7 +60,6 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { driver = BrowserManager.getWebDriver(); LoginUtils.login(driver, automationContext, getWebAppURL()); driver.get(getWebAppURL() + Constants.IOT_USER_ADD_URL); - uiElementMapper = UIElementMapper.getInstance(); userNameField = driver.findElement(By.id(uiElementMapper.getElement("iot.admin.addUser.username.id"))); @@ -72,7 +71,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for empty form submission") - public void emptyFormTest() throws Exception { + public void emptyFormTest(){ clearForm(); firstNameField.sendKeys(""); @@ -88,7 +87,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for short user name") - public void shortUserNameTest() throws Exception { + public void shortUserNameTest() { clearForm(); firstNameField.sendKeys("User"); @@ -104,7 +103,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for empty first name") - public void emptyFirstNameTest() throws Exception { + public void emptyFirstNameTest() { clearForm(); firstNameField.sendKeys(""); @@ -120,7 +119,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for empty last name") - public void emptyLastNameTest() throws Exception { + public void emptyLastNameTest() { clearForm(); firstNameField.sendKeys("User"); @@ -135,7 +134,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for empty email name") - public void emptyEmailTest() throws Exception { + public void emptyEmailTest() { clearForm(); firstNameField.sendKeys("User"); @@ -151,7 +150,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for incorrect email") - public void incorrectEmailTest() throws Exception { + public void incorrectEmailTest() { clearForm(); firstNameField.sendKeys("User"); @@ -164,7 +163,6 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { Assert.assertEquals(driver.findElement(By.xpath( uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))).getText(), "Provided email is invalid. Please check."); - } private void clearForm() { @@ -175,8 +173,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @AfterClass(alwaysRun = true) - public void tearDown() throws Exception { + public void tearDown() { driver.quit(); } - } diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegisterTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java similarity index 83% rename from modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegisterTest.java rename to modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java index 0094ce43..057098ef 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegisterTest.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java @@ -37,9 +37,9 @@ import java.io.IOException; /** * Test for registering a new user and login */ -public class RegisterTest extends IOTIntegrationUIBaseTestCase { +public class NewUserRegistrationTest extends IOTIntegrationUIBaseTestCase { private WebDriver driver; - UIElementMapper uiElementMapper; + private UIElementMapper uiElementMapper; @BeforeClass(alwaysRun = true) public void setup() throws XPathExpressionException, XMLStreamException, IOException { @@ -50,10 +50,10 @@ public class RegisterTest extends IOTIntegrationUIBaseTestCase { @Test(description = "Verify new User registration") public void userRegisterTest() throws IOException { - LoginPage test = new LoginPage(driver); + LoginPage loginPage = new LoginPage(driver); uiElementMapper = UIElementMapper.getInstance(); - NewUserRegisterPage registerTest = test.registerNewUser(); - LoginPage loginPage = registerTest.registerUser( + NewUserRegisterPage registerTest = loginPage.registerNewUser(); + loginPage = registerTest.registerUser( uiElementMapper.getElement("iot.user.add.firstname"), uiElementMapper.getElement("iot.user.add.lastname"), uiElementMapper.getElement("iot.user.add.email"), @@ -65,10 +65,13 @@ public class RegisterTest extends IOTIntegrationUIBaseTestCase { uiElementMapper.getElement("iot.user.add.password")); Assert.assertTrue(homePage.checkUserName()); + } + @Test(description = "Test user logout function", dependsOnMethods = {"userRegisterTest"}) + public void logoutTest() throws IOException { + IOTHomePage homePage = new IOTHomePage(driver); homePage.logout(); - - driver.close(); + Assert.assertEquals(driver.getTitle(), "Login | IoT Server"); } @AfterClass(alwaysRun = true) diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTests.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTests.java index b14e9412..b605394a 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTests.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTests.java @@ -19,9 +19,6 @@ 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.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -30,6 +27,7 @@ import org.wso2.carbon.automation.extensions.selenium.BrowserManager; 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 org.wso2.iot.integration.ui.pages.uesr.NewUserRegisterPage; import javax.xml.stream.XMLStreamException; import javax.xml.xpath.XPathExpressionException; @@ -44,54 +42,22 @@ import java.io.IOException; */ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCase { private WebDriver driver; - UIElementMapper uiElementMapper; - - WebElement firstNameField; - WebElement lastNameField; - WebElement emailField; - WebElement userNameField; - WebElement passwordField; - WebElement passwordConfirmationField; - WebElement registerButton; + private UIElementMapper uiElementMapper; + private NewUserRegisterPage registerPage; @BeforeClass(alwaysRun = true) public void setup() throws XPathExpressionException, XMLStreamException, IOException { super.init(); driver = BrowserManager.getWebDriver(); driver.get(getWebAppURL() + Constants.IOT_USER_REGISTER_URL); - + registerPage = new NewUserRegisterPage(driver); uiElementMapper = UIElementMapper.getInstance(); - - WebDriverWait wait = new WebDriverWait(driver, 10); - wait.until(ExpectedConditions.titleContains("Register | IoT Server")); - - firstNameField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.firstname.xpath"))); - lastNameField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.lastname.xpath"))); - emailField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.email.xpath"))); - userNameField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.username.xpath"))); - passwordField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.password.xpath"))); - passwordConfirmationField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.confirmpassword.xpath"))); - registerButton = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.register.button.xpath"))); - } +} @Test(description = "Test for submitting an empty registration form") - public void emptyFormTest() { - clearForm(); - firstNameField.sendKeys(""); - lastNameField.sendKeys(""); - emailField.sendKeys(""); - userNameField.sendKeys(""); - passwordField.sendKeys(""); - passwordConfirmationField.sendKeys(""); - - registerButton.click(); + public void emptyFormTest() throws IOException { + registerPage.clearForm(); + registerPage.validateForm("", "", "", "", "", ""); Assert.assertEquals(driver.findElement(By.id( uiElementMapper.getElement("iot.user.register.firstname.error"))).getText(), @@ -115,15 +81,7 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas @Test(description = "Test for non matching passwords") public void nonMatchingPasswordTest() { - clearForm(); - - firstNameField.sendKeys("User"); - lastNameField.sendKeys("User"); - emailField.sendKeys("user@user.com"); - userNameField.sendKeys("user"); - passwordField.sendKeys("user123"); - passwordConfirmationField.sendKeys("user234"); - registerButton.click(); + registerPage.validateForm("user", "user", "user@wso2.com", "user1", "password", "Password"); Assert.assertEquals(driver.findElement(By.id( uiElementMapper.getElement("iot.user.register.confirmPassword.error"))).getText(), @@ -132,12 +90,7 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas @Test(description = "Test for email") public void incorrectEmailTest() { - clearForm(); - - firstNameField.sendKeys("User"); - lastNameField.sendKeys("User"); - emailField.sendKeys("user.com"); - registerButton.click(); + registerPage.validateForm("user", "user", "user123", "user1", "password", "password"); Assert.assertEquals(driver.findElement(By.id( uiElementMapper.getElement("iot.user.register.email.error"))).getText(), @@ -146,16 +99,7 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas @Test(description = "Test for password length") public void passwordLengthTest() { - clearForm(); - - firstNameField.sendKeys("User"); - lastNameField.sendKeys("User"); - emailField.sendKeys("user@user.com"); - userNameField.sendKeys("user"); - passwordField.sendKeys("user"); - - registerButton.click(); - + registerPage.validateForm("user", "user", "user@wso2.com", "user1", "passw", "passw"); Assert.assertEquals(driver.findElement(By.id( uiElementMapper.getElement("iot.user.register.password.error"))).getText(), "Password should be between 5 and 30 characters."); @@ -166,12 +110,5 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas driver.quit(); } - public void clearForm() { - firstNameField.clear(); - lastNameField.clear(); - emailField.clear(); - userNameField.clear(); - passwordField.clear(); - passwordConfirmationField.clear(); - } + } diff --git a/modules/samples/connectedcup/component/controller/src/main/java/org/coffeeking/controller/service/transport/ConnectedCupMQTTConnector.java b/modules/samples/connectedcup/component/controller/src/main/java/org/coffeeking/controller/service/transport/ConnectedCupMQTTConnector.java index fbb508cc..142d6569 100644 --- a/modules/samples/connectedcup/component/controller/src/main/java/org/coffeeking/controller/service/transport/ConnectedCupMQTTConnector.java +++ b/modules/samples/connectedcup/component/controller/src/main/java/org/coffeeking/controller/service/transport/ConnectedCupMQTTConnector.java @@ -134,26 +134,6 @@ public class ConnectedCupMQTTConnector extends MQTTTransportHandler { String[] messageData = mqttMessage.toString().split(":"); Float value = Float.valueOf(messageData[1]); -// if (actualMessage.contains("PUBLISHER")) { -// float temperature = Float.parseFloat(actualMessage.split(":")[2]); -// -// if (!ConnectedCupServiceUtils.publishToDAS(owner, deviceId, messageData[0], value)) { -// log.error("MQTT Subscriber: Publishing data to DAS failed."); -// } -// -// if (log.isDebugEnabled()) { -// log.debug("MQTT Subscriber: Published data to DAS successfully."); -// } -// -// } else if (actualMessage.contains("TEMPERATURE")) { -// String temperatureValue = actualMessage.split(":")[1]; -// SensorDataManager.getInstance().setSensorRecord(deviceId, ConnectedCupConstants.SENSOR_TEMPERATURE, -// temperatureValue, -// Calendar.getInstance().getTimeInMillis()); -// } -// -// - switch(messageData[0]) { case "temperature": SensorDataManager.getInstance().setSensorRecord(deviceId, ConnectedCupConstants.SENSOR_TEMPERATURE,