Code formatting and fixes

merge-requests/1/head
Menaka Madushanka 9 years ago
parent fcd5669361
commit 57f91949a3

@ -49,14 +49,12 @@ public class IOTIntegrationUIBaseTestCase {
} }
protected String getSessionCookie(AutomationContext context) protected String getSessionCookie(AutomationContext context)
throws RemoteException, XPathExpressionException, throws RemoteException, XPathExpressionException, LoginAuthenticationExceptionException {
LoginAuthenticationExceptionException {
AuthenticatorClient authenticationAdminClient = new AuthenticatorClient(context.getContextUrls().getBackEndUrl()); AuthenticatorClient authenticationAdminClient = new AuthenticatorClient(context.getContextUrls().getBackEndUrl());
return authenticationAdminClient.login(automationContext.getSuperTenant(). return authenticationAdminClient.login(automationContext.getSuperTenant().
getTenantAdmin().getUserName(), automationContext.getSuperTenant(). getTenantAdmin().getUserName(), automationContext.getSuperTenant().
getTenantAdmin().getPassword(), getTenantAdmin().getPassword(),
automationContext.getDefaultInstance().getHosts().get("default")); automationContext.getDefaultInstance().getHosts().get("default"));
} }
protected String getServiceURL() throws XPathExpressionException { protected String getServiceURL() throws XPathExpressionException {

@ -2,4 +2,5 @@ package org.wso2.iot.integration.ui.pages;
public class UIConstants { public class UIConstants {
public static long webDriverTimeOut = 10; public static long webDriverTimeOut = 10;
public static int threadTimeout = 1000;
} }

@ -30,7 +30,6 @@ public class UIElementMapper {
private static UIElementMapper instance; private static UIElementMapper instance;
private UIElementMapper(){ private UIElementMapper(){
} }
public static synchronized UIElementMapper getInstance() throws IOException { public static synchronized UIElementMapper getInstance() throws IOException {
@ -59,6 +58,4 @@ public class UIElementMapper {
} }
return null; return null;
} }
} }

@ -36,5 +36,4 @@ public class EnrollDevicePage {
this.driver = driver; this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance(); this.uiElementMapper = UIElementMapper.getInstance();
} }
} }

@ -65,7 +65,6 @@ public class DeviceAddGroupPage {
addGroupButton.click(); addGroupButton.click();
return new DeviceGroupsPage(driver); return new DeviceGroupsPage(driver);
} }
/** /**
@ -87,5 +86,4 @@ public class DeviceAddGroupPage {
return driver.findElement(By.xpath( return driver.findElement(By.xpath(
uiElementMapper.getElement("iot.device.groups.add.emptyfrom.error"))).getText(); uiElementMapper.getElement("iot.device.groups.add.emptyfrom.error"))).getText();
} }
} }

@ -63,6 +63,4 @@ public class DeviceGroupsPage {
return groupsList.contains(groupName); return groupsList.contains(groupName);
} }
} }

@ -100,5 +100,4 @@ public class LoginPage {
registerLink.click(); registerLink.click();
return new NewUserRegisterPage(driver); return new NewUserRegisterPage(driver);
} }
} }

@ -62,6 +62,4 @@ public class AddUserPage {
return new UserAddedConfirmationPage(driver); return new UserAddedConfirmationPage(driver);
} }
} }

@ -30,5 +30,4 @@ public class EditUserPage {
public void editUser(String password, String firstName, String lastName) { public void editUser(String password, String firstName, String lastName) {
driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.add.input.password.xpath"))); driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.add.input.password.xpath")));
} }
} }

@ -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; package org.wso2.iot.integration.ui.pages.uesr;
import org.openqa.selenium.By; import org.openqa.selenium.By;
@ -13,19 +30,42 @@ import java.io.IOException;
/** /**
* This class represents the new user registration page. * 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 { public class NewUserRegisterPage {
private WebDriver driver; 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 { public NewUserRegisterPage(WebDriver driver) throws IOException {
this.driver = driver; this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance(); UIElementMapper uiElementMapper = UIElementMapper.getInstance();
// Check that we're on the right page. // Check that we're on the right page.
WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut); WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut);
if (!webDriverWait.until(ExpectedConditions.titleContains("Register | IoT Server"))) { if (!webDriverWait.until(ExpectedConditions.titleContains("Register | IoT Server"))) {
throw new IllegalStateException("This is not the Register page"); 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 * @throws IOException
*/ */
public LoginPage registerUser(String firstName, String lastName, String email, String userName, String password, public LoginPage registerUser(String firstName, String lastName, String email, String userName, String password,
String String confirmPassword) throws IOException {
confirmPassword) throws IOException { handleAction(firstName, lastName, email, userName, password, confirmPassword);
WebElement firstNameField = driver.findElement(By.xpath( return new LoginPage(driver);
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( * Following method is to validate the user registration form.
uiElementMapper.getElement("iot.user.add.input.email.xpath"))); * */
WebElement userNameField = driver.findElement(By.xpath( public void validateForm(String firstName, String lastName, String email, String userName,
uiElementMapper.getElement("iot.user.add.input.username.xpath"))); String password, String confirmPassword) {
WebElement passwordField = driver.findElement(By.xpath( handleAction(firstName, lastName, email, userName, password, confirmPassword);
uiElementMapper.getElement("iot.user.add.input.password.xpath"))); }
WebElement passwordConfirmationField = driver.findElement(By.xpath(
uiElementMapper.getElement("iot.user.add.input.confirmpassword.xpath"))); public void handleAction(String firstName, String lastName, String email, String userName, String password,
String confirmPassword) {
clearForm();
firstNameField.sendKeys(firstName); firstNameField.sendKeys(firstName);
lastNameField.sendKeys(lastName); lastNameField.sendKeys(lastName);
emailField.sendKeys(email); emailField.sendKeys(email);
userNameField.sendKeys(userName); userNameField.sendKeys(userName);
passwordField.sendKeys(password); passwordField.sendKeys(password);
passwordConfirmationField.sendKeys(confirmPassword); passwordConfirmationField.sendKeys(confirmPassword);
driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.add.register.button.xpath"))).click(); registerButton.click();
return new LoginPage(driver);
} }
public void clearForm() {
firstNameField.clear();
lastNameField.clear();
emailField.clear();
userNameField.clear();
passwordField.clear();
passwordConfirmationField.clear();
}
} }

@ -21,8 +21,5 @@ public class UserAddedConfirmationPage {
this.uiElementMapper = UIElementMapper.getInstance(); this.uiElementMapper = UIElementMapper.getInstance();
driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.addUser.view.btn.xpath"))).click(); driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.addUser.view.btn.xpath"))).click();
} }
} }

@ -20,6 +20,9 @@ package org.wso2.iot.integration.ui.pages.uesr;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; 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.UIElementMapper;
import java.io.IOException; import java.io.IOException;
@ -39,18 +42,23 @@ public class UserListingPage {
/** /**
* @return After deleting a user, returns back to the user listing page. * @return After deleting a user, returns back to the user listing page.
*/ */
//Don't use generic exceptions. public UserListingPage deleteUser() throws IOException {
public UserListingPage deleteUser() throws IOException, InterruptedException {
WebElement deleteBtn = driver.findElement(By.xpath( WebElement deleteBtn = driver.findElement(By.xpath(
uiElementMapper.getElement("iot.admin.deleteUser.btn.xpath"))); uiElementMapper.getElement("iot.admin.deleteUser.btn.xpath")));
if (deleteBtn != null) {
WebDriverWait wait = new WebDriverWait(driver, UIConstants.webDriverTimeOut);
wait.until(ExpectedConditions.visibilityOf(deleteBtn));
deleteBtn.click(); deleteBtn.click();
} else {
return new UserListingPage(driver); WebElement deleteConfirmationBtn = driver.findElement(
} By.xpath(uiElementMapper.getElement("iot.admin.deleteUser.yes.link.xpath")));
driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.deleteUser.yes.link.xpath"))).click(); wait.until(ExpectedConditions.visibilityOf(deleteConfirmationBtn));
Thread.sleep(1000); deleteConfirmationBtn.click();
driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.deleteUser.success.link.xpath"))).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); return new UserListingPage(driver);
} }

@ -25,7 +25,4 @@ public class ViewUserPage {
throw new IllegalStateException("This is not the User view page"); throw new IllegalStateException("This is not the User view page");
} }
} }
} }

@ -48,9 +48,9 @@
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles> </suiteXmlFiles>
<!--<skipTests>${skipUiTests}</skipTests>-->
<systemProperties> <systemProperties>
<skipTests>true</skipTests>
<property> <property>
<name>maven.test.haltafterfailure</name> <name>maven.test.haltafterfailure</name>
<value>false</value> <value>false</value>
@ -245,30 +245,6 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-antrun-plugin</artifactId>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>Test.Connected.Cup</id>-->
<!--<phase>compile</phase>-->
<!--<goals>-->
<!--<goal>run</goal>-->
<!--</goals>-->
<!--<configuration>-->
<!--<tasks>-->
<!--<echo message="********************** installing ************************"/>-->
<!--&lt;!&ndash;<property name="tempDir" refid="**/wso2iots-1.0.0-SNAPSHOT"/>&ndash;&gt;-->
<!--<ant antfile="${basedir}/src/test/resources/build.xml">-->
<!--<target name="mvn clean"/>-->
<!--<target name="mvn clean package"/>-->
<!--</ant>-->
<!--</tasks>-->
<!--</configuration>-->
<!--</execution>-->
<!--</executions>-->
<!--<version>1.8</version>-->
<!--</plugin>-->
</plugins> </plugins>
</build> </build>
@ -291,8 +267,5 @@
</dependency> </dependency>
</dependencies> </dependencies>
<properties>
<skipUiTests>true</skipUiTests>
</properties>
</project> </project>

@ -25,7 +25,7 @@ import javax.xml.xpath.XPathExpressionException;
import java.io.IOException; 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 { public class LoginUtils {
@ -43,6 +43,4 @@ public class LoginUtils {
test.loginAsAdmin(automationContext.getSuperTenant().getTenantAdmin().getUserName(), test.loginAsAdmin(automationContext.getSuperTenant().getTenantAdmin().getUserName(),
automationContext.getSuperTenant().getTenantAdmin().getPassword()); automationContext.getSuperTenant().getTenantAdmin().getPassword());
} }
} }

@ -1,7 +0,0 @@
package org.wso2.carbon.iot.integration.web.ui.test;
/**
* Created by menaka on 2/23/16.
*/
public class TestRestartServer {
}

@ -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.groups.DeviceGroupsPage;
import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard; 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. * 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.") @Test(description = "Test for adding a new device group.")
public void addNewGroupTest() throws Exception { public void addNewGroupTest() throws IOException {
DeviceAddGroupPage addGroupPage = adminDashboard.addGroup(); DeviceAddGroupPage addGroupPage = adminDashboard.addGroup();
addGroupPage.addNewGroup("group1", "This is test group"); addGroupPage.addNewGroup("group1", "This is test group");
} }
@Test(description = "Check whether the created group exists", dependsOnMethods = {"addNewGroupTest"}) @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); driver.get(getWebAppURL() + Constants.IOT_HOME_URL);
DeviceGroupsPage groupsPage = adminDashboard.viewGroups(); DeviceGroupsPage groupsPage = adminDashboard.viewGroups();
Assert.assertTrue(groupsPage.isGroupCreated("group1")); Assert.assertTrue(groupsPage.isGroupCreated("group1"));
@ -63,5 +66,4 @@ public class DeviceGroupTest extends IOTIntegrationUIBaseTestCase {
public void tearDown() throws Exception { public void tearDown() throws Exception {
driver.quit(); driver.quit();
} }
} }

@ -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.home.IOTAdminDashboard;
import org.wso2.iot.integration.ui.pages.login.LoginPage; 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 * Test Login as Admin
*/ */
@ -34,14 +38,14 @@ public class LoginTest extends IOTIntegrationUIBaseTestCase {
private WebDriver driver; private WebDriver driver;
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void setup() throws Exception { public void setup() throws XPathExpressionException, XMLStreamException, IOException {
super.init(); super.init();
driver = BrowserManager.getWebDriver(); driver = BrowserManager.getWebDriver();
driver.get(getWebAppURL() + Constants.IOT_LOGIN_PATH); 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 { public void testAdminLogin() throws IOException, XPathExpressionException {
LoginPage test = new LoginPage(driver); LoginPage test = new LoginPage(driver);
IOTAdminDashboard dashboard = test.loginAsAdmin( IOTAdminDashboard dashboard = test.loginAsAdmin(
automationContext.getSuperTenant().getTenantAdmin().getUserName(), automationContext.getSuperTenant().getTenantAdmin().getUserName(),
@ -50,8 +54,7 @@ public class LoginTest extends IOTIntegrationUIBaseTestCase {
} }
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)
public void tearDown() throws Exception { public void tearDown(){
driver.close();
driver.quit(); driver.quit();
} }
} }

@ -1,7 +0,0 @@
package org.wso2.carbon.iot.integration.web.ui.test.samples;
/**
* Created by menaka on 2/24/16.
*/
public class SampleInstall {
}

@ -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.
* <p>
* 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;
}
}

@ -43,16 +43,16 @@ import java.io.IOException;
* 5. Empty email * 5. Empty email
* 6. Incorrect email * 6. Incorrect email
*/ */
public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { public class AddUserFormValidationTest extends IOTIntegrationUIBaseTestCase {
private WebDriver driver; private WebDriver driver;
UIElementMapper uiElementMapper; private UIElementMapper uiElementMapper;
WebElement firstNameField; private WebElement firstNameField;
WebElement lastNameField; private WebElement lastNameField;
WebElement emailField; private WebElement emailField;
WebElement userNameField; private WebElement userNameField;
WebElement addUserButton; private WebElement addUserButton;
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void setup() throws XPathExpressionException, XMLStreamException, IOException { public void setup() throws XPathExpressionException, XMLStreamException, IOException {
@ -60,7 +60,6 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
driver = BrowserManager.getWebDriver(); driver = BrowserManager.getWebDriver();
LoginUtils.login(driver, automationContext, getWebAppURL()); LoginUtils.login(driver, automationContext, getWebAppURL());
driver.get(getWebAppURL() + Constants.IOT_USER_ADD_URL); driver.get(getWebAppURL() + Constants.IOT_USER_ADD_URL);
uiElementMapper = UIElementMapper.getInstance(); uiElementMapper = UIElementMapper.getInstance();
userNameField = driver.findElement(By.id(uiElementMapper.getElement("iot.admin.addUser.username.id"))); 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") @Test(description = "Test for empty form submission")
public void emptyFormTest() throws Exception { public void emptyFormTest(){
clearForm(); clearForm();
firstNameField.sendKeys(""); firstNameField.sendKeys("");
@ -88,7 +87,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
} }
@Test(description = "Test for short user name") @Test(description = "Test for short user name")
public void shortUserNameTest() throws Exception { public void shortUserNameTest() {
clearForm(); clearForm();
firstNameField.sendKeys("User"); firstNameField.sendKeys("User");
@ -104,7 +103,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
} }
@Test(description = "Test for empty first name") @Test(description = "Test for empty first name")
public void emptyFirstNameTest() throws Exception { public void emptyFirstNameTest() {
clearForm(); clearForm();
firstNameField.sendKeys(""); firstNameField.sendKeys("");
@ -120,7 +119,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
} }
@Test(description = "Test for empty last name") @Test(description = "Test for empty last name")
public void emptyLastNameTest() throws Exception { public void emptyLastNameTest() {
clearForm(); clearForm();
firstNameField.sendKeys("User"); firstNameField.sendKeys("User");
@ -135,7 +134,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
} }
@Test(description = "Test for empty email name") @Test(description = "Test for empty email name")
public void emptyEmailTest() throws Exception { public void emptyEmailTest() {
clearForm(); clearForm();
firstNameField.sendKeys("User"); firstNameField.sendKeys("User");
@ -151,7 +150,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
} }
@Test(description = "Test for incorrect email") @Test(description = "Test for incorrect email")
public void incorrectEmailTest() throws Exception { public void incorrectEmailTest() {
clearForm(); clearForm();
firstNameField.sendKeys("User"); firstNameField.sendKeys("User");
@ -164,7 +163,6 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
Assert.assertEquals(driver.findElement(By.xpath( Assert.assertEquals(driver.findElement(By.xpath(
uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))).getText(), uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))).getText(),
"Provided email is invalid. Please check."); "Provided email is invalid. Please check.");
} }
private void clearForm() { private void clearForm() {
@ -175,8 +173,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
} }
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)
public void tearDown() throws Exception { public void tearDown() {
driver.quit(); driver.quit();
} }
} }

@ -37,9 +37,9 @@ import java.io.IOException;
/** /**
* Test for registering a new user and login * Test for registering a new user and login
*/ */
public class RegisterTest extends IOTIntegrationUIBaseTestCase { public class NewUserRegistrationTest extends IOTIntegrationUIBaseTestCase {
private WebDriver driver; private WebDriver driver;
UIElementMapper uiElementMapper; private UIElementMapper uiElementMapper;
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void setup() throws XPathExpressionException, XMLStreamException, IOException { public void setup() throws XPathExpressionException, XMLStreamException, IOException {
@ -50,10 +50,10 @@ public class RegisterTest extends IOTIntegrationUIBaseTestCase {
@Test(description = "Verify new User registration") @Test(description = "Verify new User registration")
public void userRegisterTest() throws IOException { public void userRegisterTest() throws IOException {
LoginPage test = new LoginPage(driver); LoginPage loginPage = new LoginPage(driver);
uiElementMapper = UIElementMapper.getInstance(); uiElementMapper = UIElementMapper.getInstance();
NewUserRegisterPage registerTest = test.registerNewUser(); NewUserRegisterPage registerTest = loginPage.registerNewUser();
LoginPage loginPage = registerTest.registerUser( loginPage = registerTest.registerUser(
uiElementMapper.getElement("iot.user.add.firstname"), uiElementMapper.getElement("iot.user.add.firstname"),
uiElementMapper.getElement("iot.user.add.lastname"), uiElementMapper.getElement("iot.user.add.lastname"),
uiElementMapper.getElement("iot.user.add.email"), uiElementMapper.getElement("iot.user.add.email"),
@ -65,10 +65,13 @@ public class RegisterTest extends IOTIntegrationUIBaseTestCase {
uiElementMapper.getElement("iot.user.add.password")); uiElementMapper.getElement("iot.user.add.password"));
Assert.assertTrue(homePage.checkUserName()); Assert.assertTrue(homePage.checkUserName());
}
@Test(description = "Test user logout function", dependsOnMethods = {"userRegisterTest"})
public void logoutTest() throws IOException {
IOTHomePage homePage = new IOTHomePage(driver);
homePage.logout(); homePage.logout();
Assert.assertEquals(driver.getTitle(), "Login | IoT Server");
driver.close();
} }
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)

@ -19,9 +19,6 @@ package org.wso2.carbon.iot.integration.web.ui.test.user;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver; 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.Assert;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; 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.carbon.iot.integration.web.ui.test.Constants;
import org.wso2.iot.integration.ui.pages.IOTIntegrationUIBaseTestCase; import org.wso2.iot.integration.ui.pages.IOTIntegrationUIBaseTestCase;
import org.wso2.iot.integration.ui.pages.UIElementMapper; 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.stream.XMLStreamException;
import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathExpressionException;
@ -44,54 +42,22 @@ import java.io.IOException;
*/ */
public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCase { public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCase {
private WebDriver driver; private WebDriver driver;
UIElementMapper uiElementMapper; private UIElementMapper uiElementMapper;
private NewUserRegisterPage registerPage;
WebElement firstNameField;
WebElement lastNameField;
WebElement emailField;
WebElement userNameField;
WebElement passwordField;
WebElement passwordConfirmationField;
WebElement registerButton;
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void setup() throws XPathExpressionException, XMLStreamException, IOException { public void setup() throws XPathExpressionException, XMLStreamException, IOException {
super.init(); super.init();
driver = BrowserManager.getWebDriver(); driver = BrowserManager.getWebDriver();
driver.get(getWebAppURL() + Constants.IOT_USER_REGISTER_URL); driver.get(getWebAppURL() + Constants.IOT_USER_REGISTER_URL);
registerPage = new NewUserRegisterPage(driver);
uiElementMapper = UIElementMapper.getInstance(); 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") @Test(description = "Test for submitting an empty registration form")
public void emptyFormTest() { public void emptyFormTest() throws IOException {
clearForm(); registerPage.clearForm();
firstNameField.sendKeys(""); registerPage.validateForm("", "", "", "", "", "");
lastNameField.sendKeys("");
emailField.sendKeys("");
userNameField.sendKeys("");
passwordField.sendKeys("");
passwordConfirmationField.sendKeys("");
registerButton.click();
Assert.assertEquals(driver.findElement(By.id( Assert.assertEquals(driver.findElement(By.id(
uiElementMapper.getElement("iot.user.register.firstname.error"))).getText(), uiElementMapper.getElement("iot.user.register.firstname.error"))).getText(),
@ -115,15 +81,7 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas
@Test(description = "Test for non matching passwords") @Test(description = "Test for non matching passwords")
public void nonMatchingPasswordTest() { public void nonMatchingPasswordTest() {
clearForm(); registerPage.validateForm("user", "user", "user@wso2.com", "user1", "password", "Password");
firstNameField.sendKeys("User");
lastNameField.sendKeys("User");
emailField.sendKeys("user@user.com");
userNameField.sendKeys("user");
passwordField.sendKeys("user123");
passwordConfirmationField.sendKeys("user234");
registerButton.click();
Assert.assertEquals(driver.findElement(By.id( Assert.assertEquals(driver.findElement(By.id(
uiElementMapper.getElement("iot.user.register.confirmPassword.error"))).getText(), uiElementMapper.getElement("iot.user.register.confirmPassword.error"))).getText(),
@ -132,12 +90,7 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas
@Test(description = "Test for email") @Test(description = "Test for email")
public void incorrectEmailTest() { public void incorrectEmailTest() {
clearForm(); registerPage.validateForm("user", "user", "user123", "user1", "password", "password");
firstNameField.sendKeys("User");
lastNameField.sendKeys("User");
emailField.sendKeys("user.com");
registerButton.click();
Assert.assertEquals(driver.findElement(By.id( Assert.assertEquals(driver.findElement(By.id(
uiElementMapper.getElement("iot.user.register.email.error"))).getText(), uiElementMapper.getElement("iot.user.register.email.error"))).getText(),
@ -146,16 +99,7 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas
@Test(description = "Test for password length") @Test(description = "Test for password length")
public void passwordLengthTest() { public void passwordLengthTest() {
clearForm(); registerPage.validateForm("user", "user", "user@wso2.com", "user1", "passw", "passw");
firstNameField.sendKeys("User");
lastNameField.sendKeys("User");
emailField.sendKeys("user@user.com");
userNameField.sendKeys("user");
passwordField.sendKeys("user");
registerButton.click();
Assert.assertEquals(driver.findElement(By.id( Assert.assertEquals(driver.findElement(By.id(
uiElementMapper.getElement("iot.user.register.password.error"))).getText(), uiElementMapper.getElement("iot.user.register.password.error"))).getText(),
"Password should be between 5 and 30 characters."); "Password should be between 5 and 30 characters.");
@ -166,12 +110,5 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas
driver.quit(); driver.quit();
} }
public void clearForm() {
firstNameField.clear();
lastNameField.clear();
emailField.clear();
userNameField.clear();
passwordField.clear();
passwordConfirmationField.clear();
}
} }

@ -134,26 +134,6 @@ public class ConnectedCupMQTTConnector extends MQTTTransportHandler {
String[] messageData = mqttMessage.toString().split(":"); String[] messageData = mqttMessage.toString().split(":");
Float value = Float.valueOf(messageData[1]); 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]) { switch(messageData[0]) {
case "temperature": case "temperature":
SensorDataManager.getInstance().setSensorRecord(deviceId, ConnectedCupConstants.SENSOR_TEMPERATURE, SensorDataManager.getInstance().setSensorRecord(deviceId, ConnectedCupConstants.SENSOR_TEMPERATURE,

Loading…
Cancel
Save