From adfa5762c97fb94b36dde1bbd8e5435d18dc2f2e Mon Sep 17 00:00:00 2001 From: Menaka Madushanka Date: Fri, 4 Mar 2016 11:22:48 +0530 Subject: [PATCH] Sample Enrollment and verification --- .../pages/IOTIntegrationUIBaseTestCase.java | 2 - .../iot/integration/ui/pages/UIConstants.java | 22 +++++ .../ui/pages/devices/DevicesPage.java | 60 +++++++++++++- .../ui/pages/devices/EnrollDevicePage.java | 40 ++++++---- .../ui/pages/groups/DeviceGroupsPage.java | 8 +- .../ConnectedCupDeviceTypeViewPage.java | 19 ++++- .../samples/ConnectedCupDeviceViewPage.java | 30 +++++++ .../pages/samples/VirtualSampleViewPage.java | 80 +++++++++++++++++++ .../ui/pages/uesr/AddUserPage.java | 4 - .../pages/uesr/UserAddedConfirmationPage.java | 6 +- .../src/main/resources/mapper.properties | 24 ++++-- .../integration/web/ui/test/Constants.java | 6 ++ .../ui/test/samples/SampleEnrollmentTest.java | 51 +++++++++++- .../SampleEnrolmentVerificationTest.java | 73 +++++++++++++++++ .../SampleInstallationVerification.java | 16 +--- .../ui/test/user/NewUserRegistrationTest.java | 3 +- .../src/test/resources/testng.xml | 3 +- 17 files changed, 388 insertions(+), 59 deletions(-) create mode 100644 modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/VirtualSampleViewPage.java create mode 100644 modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleEnrolmentVerificationTest.java 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 f1d743cd..27fabe95 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 @@ -32,8 +32,6 @@ import java.rmi.RemoteException; public class IOTIntegrationUIBaseTestCase { - - private static final Log log = LogFactory.getLog(IOTIntegrationUIBaseTestCase.class); protected AutomationContext automationContext; protected void init() throws IOException, XMLStreamException, 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 680d5bba..d5ea1e86 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 @@ -17,7 +17,29 @@ */ package org.wso2.iot.integration.ui.pages; +import org.apache.commons.logging.Log; +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + public class UIConstants { public static long webDriverTimeOut = 10; + public static long webDriverTime = 60; public static int threadTimeout = 1000; + + public static boolean isElementPresent(Log log, WebDriver driver, By by) { + try { + WebDriverWait wait = new WebDriverWait(driver, webDriverTime); + wait.until(ExpectedConditions.presenceOfElementLocated(by)); + driver.findElement(by); + return true; + } catch (NoSuchElementException e) { + log.error(by.toString() + " is not present"); + return false; + } + + } + } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/DevicesPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/DevicesPage.java index 00130d36..d8e7d918 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/DevicesPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/DevicesPage.java @@ -1,25 +1,83 @@ +/* + * 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.iot.integration.ui.pages.devices; +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.samples.ConnectedCupDeviceViewPage; import java.io.IOException; +import java.util.List; public class DevicesPage { private WebDriver driver; private UIElementMapper uiElementMapper; + Log log = LogFactory.getLog(DevicesPage.class); public DevicesPage(WebDriver driver) throws IOException { + this.driver = driver; this.uiElementMapper = UIElementMapper.getInstance(); - WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut); if (!webDriverWait.until(ExpectedConditions.titleContains("Device Management | IoT Server"))) { throw new IllegalStateException("This is not the Device Management page"); } } + public boolean isDeviceEnrolled(String name) { + List deviceNames = driver.findElements(By.tagName("h4")); + if (!deviceNames.isEmpty()) { + for (WebElement deviceName : deviceNames) { + if (deviceName.getText().contains(name)) { + return true; + } + } + } + return false; + } + + public ConnectedCupDeviceViewPage viewDevice(String deviceName) throws IOException { + WebElement deviceTable = driver.findElement(By.xpath(uiElementMapper.getElement("iot.devices.table.xpath"))); + List data = deviceTable.findElements(By.cssSelector("a")); + for (WebElement e : data) { + String s = getLink(e, "/device/connectedcup?id="); + if (s != null) { + driver.get(s); + return new ConnectedCupDeviceViewPage(driver, deviceName); + } + } + return null; + } + + public String getLink(WebElement element, String lookupText) { + String link = element.getAttribute("href"); + log.info("Link -----------------------> " + link); + if (link.contains(lookupText)) { + log.info("returned ----------------->>>> " + link); + return link; + } + return null; + } } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/EnrollDevicePage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/EnrollDevicePage.java index eccb26a2..7a88f063 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/EnrollDevicePage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/EnrollDevicePage.java @@ -20,6 +20,7 @@ package org.wso2.iot.integration.ui.pages.devices; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; @@ -34,9 +35,9 @@ import java.io.IOException; * Device Enrollment page for new user */ public class EnrollDevicePage { - private static final Log log = LogFactory.getLog(EnrollDevicePage.class); private WebDriver driver; private UIElementMapper uiElementMapper; + private Log log = LogFactory.getLog(EnrollDevicePage.class); public EnrollDevicePage(WebDriver driver) throws IOException { this.driver = driver; @@ -48,22 +49,31 @@ public class EnrollDevicePage { } } - public boolean isInstalled(String name) { - - return driver.findElement(By.id("#" + name.toLowerCase())) != null; - -// WebElement sample = null; -// try { -// sample = driver.findElement(By.id("#"+name.toLowerCase())); -// } catch (NoSuchElementException e){ -// log.error("No element found for id: " + name); -// } -// return sample != null; + public boolean isInstalled() { + boolean check = UIConstants.isElementPresent(log, driver, By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.xpath"))); + if (check) { + WebElement deviceDiv = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.xpath"))); + WebElement tryBtn = deviceDiv.findElement(By.tagName("button")); + return tryBtn.isDisplayed(); + } + return false; } public ConnectedCupDeviceTypeViewPage gotoConnectedCupDeviceTypeViewPage() throws IOException { - WebElement tryBtn = driver.findElement(By.id(uiElementMapper.getElement("iot.sample.connectedcup.try.btn.id"))); - tryBtn.click(); - return new ConnectedCupDeviceTypeViewPage(driver); + boolean check = UIConstants.isElementPresent(log, driver,By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.xpath"))); + if (check){ + WebElement deviceDiv = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.xpath"))); + WebElement tryBtn = deviceDiv.findElement(By.tagName("button")); + tryBtn.click(); + return new ConnectedCupDeviceTypeViewPage(driver); + } else { + log.error("Element not found..........................."); + return null; + } } + } 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 bdaad4f2..c91bbe0b 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 @@ -54,13 +54,13 @@ public class DeviceGroupsPage { public boolean isGroupCreated(String groupName) { WebElement table = driver.findElement(By.id(uiElementMapper.getElement("iot.device.table.id"))); List allGroupNames = table.findElements(By.tagName("h4")); - List groupsList = new ArrayList<>(); for (WebElement name : allGroupNames) { - groupsList.add(name.getText()); - + if (name.getText().contains(groupName)){ + return true; + } } - return groupsList.contains(groupName); + return false; } } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceTypeViewPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceTypeViewPage.java index c0a169a6..c2d9e3bb 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceTypeViewPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceTypeViewPage.java @@ -21,6 +21,7 @@ package org.wso2.iot.integration.ui.pages.samples; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.wso2.iot.integration.ui.pages.UIConstants; import org.wso2.iot.integration.ui.pages.UIElementMapper; import java.io.IOException; @@ -32,24 +33,34 @@ public class ConnectedCupDeviceTypeViewPage { public ConnectedCupDeviceTypeViewPage(WebDriver driver) throws IOException { this.driver = driver; this.uiElementMapper = UIElementMapper.getInstance(); - -// WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut); - if (driver.findElement(By.xpath( + if (!driver.findElement(By.xpath( uiElementMapper.getElement("iot.sample.connectedcup.page.title"))).getText(). contains("Connected Cup")) { throw new IllegalStateException("This is not the Connected cup device type view page"); } } - public void enrollDevice(String name) { + public boolean isPopUpPresent() throws InterruptedException { WebElement createInstanceBtn = driver.findElement(By.xpath( uiElementMapper.getElement("iot.sample.connectedcup.createInstanceBtn.xpath"))); createInstanceBtn.click(); + + Thread.sleep(UIConstants.threadTimeout); + + return driver.findElement(By.xpath(uiElementMapper.getElement("iot.sample.modal.popup.xpath"))).isDisplayed(); + + } + + public boolean enrollDevice(String name) throws InterruptedException { + WebElement nameField = driver.findElement(By.xpath( uiElementMapper.getElement("iot.sample.connectedcup.createInstance.nameField.xpath"))); WebElement createButton = driver.findElement(By.xpath( uiElementMapper.getElement("iot.sample.connectedcup.createInstance.downloadBtn.xpath"))); nameField.sendKeys(name); createButton.click(); + return driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.page.title"))).getText().contains("Connected Cup"); } + } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceViewPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceViewPage.java index 4391fa64..2a9fd7c5 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceViewPage.java +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceViewPage.java @@ -18,6 +18,36 @@ package org.wso2.iot.integration.ui.pages.samples; +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; + +import java.io.IOException; + public class ConnectedCupDeviceViewPage { + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public ConnectedCupDeviceViewPage(WebDriver driver, String name) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + + if (!driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.view.page.title"))).getText(). + contains(name)) { + throw new IllegalStateException("This is not the Connected cup device type view page"); + } + } + + public VirtualSampleViewPage gotoDevice() throws IOException { + WebDriverWait wait = new WebDriverWait(driver, UIConstants.webDriverTime); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath")))); + driver.findElement(By.xpath(uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath"))).click(); + return new VirtualSampleViewPage(driver); + } } diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/VirtualSampleViewPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/VirtualSampleViewPage.java new file mode 100644 index 00000000..c4d66ea9 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/VirtualSampleViewPage.java @@ -0,0 +1,80 @@ +/* + * 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.iot.integration.ui.pages.samples; + +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; + +public class VirtualSampleViewPage { + Log log = LogFactory.getLog(VirtualSampleViewPage.class); + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public VirtualSampleViewPage(WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + WebDriverWait webDriverWait = new WebDriverWait(driver, UIConstants.webDriverTimeOut); + if (!webDriverWait.until(ExpectedConditions.titleContains("Connected Coffee Cup"))) { + throw new IllegalStateException("This is not the Connected cup device page"); + } + } + + public boolean orderCoffee() { + if (UIConstants.isElementPresent(log, driver, By.xpath( + uiElementMapper.getElement("iot.sample.orderCoffee.xpath")))) { + WebElement orderBtn = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.orderCoffee.xpath"))); + orderBtn.click(); + return true; + } + return false; + } + + public boolean changeTemperature(String val) { + if (UIConstants.isElementPresent(log, driver, By.xpath( + uiElementMapper.getElement("iot.sample.temperature.xpath")))) { + WebElement tempSlider = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.temperature.xpath"))); + tempSlider.clear(); + tempSlider.sendKeys(val); + return true; + } + return false; + } + + public boolean changeCoffeeLevel(String level) { + if (UIConstants.isElementPresent(log, driver, By.xpath( + uiElementMapper.getElement("iot.sample.coffee.level.xpath")))) { + WebElement tempSlider = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.coffee.level.xpath"))); + tempSlider.clear(); + tempSlider.sendKeys(level); + return true; + } + return false; + } +} \ 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/AddUserPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/AddUserPage.java index 21291fad..f8bbf45c 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 @@ -71,10 +71,6 @@ public class AddUserPage { lastNameField.sendKeys(lastName); emailField.sendKeys(email); - WebDriverWait wait = new WebDriverWait(driver, UIConstants.webDriverTimeOut); -// wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( -// uiElementMapper.getElement("iot.admin.addUser.add.btn.xpath")))); - driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.addUser.add.btn.xpath"))).click(); return new UserAddedConfirmationPage(driver); 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 200339d0..8d2b405b 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 @@ -17,8 +17,6 @@ */ 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.wso2.iot.integration.ui.pages.UIElementMapper; @@ -29,13 +27,11 @@ import java.io.IOException; * This class represents the confirmation page for adding a new user. */ public class UserAddedConfirmationPage { - private static final Log log = LogFactory.getLog(UserAddedConfirmationPage.class); private WebDriver driver; - private UIElementMapper uiElementMapper; public UserAddedConfirmationPage(WebDriver driver) throws IOException { this.driver = driver; - this.uiElementMapper = UIElementMapper.getInstance(); + UIElementMapper 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/resources/mapper.properties b/modules/integration/tests-common/web-ui-pages/src/main/resources/mapper.properties index e1851b2e..fa42406b 100644 --- a/modules/integration/tests-common/web-ui-pages/src/main/resources/mapper.properties +++ b/modules/integration/tests-common/web-ui-pages/src/main/resources/mapper.properties @@ -60,6 +60,8 @@ iot.admin.dashboard.title.xpath=/html/body/div[3]/div[1]/div/span iot.home.enrollDevice.xpath=//*[@id="ast-container"]/div/p/a iot.user.logout.link.xpath=/html/body/header/div/div[2]/ul/li[3]/a +iot.devices.table.xpath=//*[@id="device-grid"] + # Register page error elements ----------------------------------------------------------------------------------------- iot.user.register.firstname.error=first_name-error @@ -134,14 +136,26 @@ iot.admin.editUser.btn.xpath=//*[@id="userEditBtn"] iot.admin.editUser.edit.btn.xpath=//*[@id="add-user-btn"] #---------------------------Testing the samples ------------------------------------------------------------------------ -iot.sample.connectedcup.id=#connectedcup -iot.sample.connectedcup.try.btn.id=#connectedcup -iot.sample.connectedcup.createInstanceBtn.xpath=/html/body/div[5]/div/div/div[2]/div[1]/div[4]/a[2] -iot.sample.connectedcup.createInstance.nameField.xpath=//*[@id="downloadForm"]/div[1]/div/input[1] -iot.sample.connectedcup.createInstance.downloadBtn.xpath=//*[@id="downloadForm"]/div[2]/a +iot.sample.connectedcup.xpath=//*[@id="connectedcup"] +iot.sample.connectedcup.try.btn.xpath=//button[contains(@id,'connectedcup_btn')] +iot.sample.connectedcup.try.btn.id=connectedcup_btn +iot.sample.connectedcup.page.title=//h1[@class='grey '] +iot.sample.connectedcup.view.page.title=//label[@class='device-id device-select'] +iot.sample.connectedcup.createInstanceBtn.xpath=//a[@class='download-link btn-operations'] +iot.sample.connectedcup.createInstance.nameField.xpath=//input[@class='connectedCupName'] +iot.sample.connectedcup.createInstance.downloadBtn.xpath=//a[contains(@class,'btn-operations')] +iot.sample.modal.popup.xpath=//div[@class='modalpopup-content'] + +iot.sample.connectedcup.gotodevice.xpath=//a[@class='btn-operations'] +iot.sample.connectedcup.device.title.xpath=/html/body/div[4]/h1 + +iot.sample.orderCoffee.xpath=//*[@id="order-cup"] +iot.sample.coffee.level.xpath=//*[@id="amount_coffee"] +iot.sample.temperature.xpath=//*[@id="amount_temp"] iot.try.devices.div.classname=//div[@class='try-device-container'] iot.try.device.text.xpath=//p[contains(@class,'try-device-text')] + #----------------------------------------------------------------------------------------------------------------------- #iot.user.delete.button=//*[@id="inosh"]/td[5]/a[3] #iot.user.delete.button.confirm=remove-user-yes-link diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/Constants.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/Constants.java index 3cf00040..67cfdc6a 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/Constants.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/Constants.java @@ -23,4 +23,10 @@ public class Constants { public static final String IOT_USER_ADD_URL = "/devicemgt/user/add"; public static final String IOT_GROUP_ADD_URL = "/devicemgt/group/add"; public static final String IOT_HOME_URL = "/devicemgt/"; + public static final String IOT_ENROLL_CONNECTED_CUP = "/device/connectedcup/enroll"; + public static final String IOT_DEVICES_URL = "/devicemgt/devices"; + public static final String IOT_CONNECTED_CUP_NAME = "testDevice"; + + + } diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleEnrollmentTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleEnrollmentTest.java index 2a923bfe..bf198f55 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleEnrollmentTest.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleEnrollmentTest.java @@ -1,7 +1,50 @@ package org.wso2.carbon.iot.integration.web.ui.test.samples; -/** - * Created by menaka on 2/29/16. - */ -public class SampleEnrollmentTest { +import junit.framework.Assert; +import org.openqa.selenium.WebDriver; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +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.devices.EnrollDevicePage; +import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard; +import org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceTypeViewPage; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +public class SampleEnrollmentTest extends IOTIntegrationUIBaseTestCase { + private WebDriver driver; + private ConnectedCupDeviceTypeViewPage connectedCupDeviceTypeViewPage; + + @BeforeClass(alwaysRun = true) + public void setup() throws XPathExpressionException, XMLStreamException, IOException { + super.init(); + driver = BrowserManager.getWebDriver(); + LoginUtils.login(driver, automationContext, getWebAppURL()); + IOTAdminDashboard adminDashboard = new IOTAdminDashboard(driver); + EnrollDevicePage enrollDevicePage = adminDashboard.enrollNewDevice(); + connectedCupDeviceTypeViewPage = enrollDevicePage.gotoConnectedCupDeviceTypeViewPage(); + } + + @Test(description = "Verify the pop up modal is displayed.", groups = {"iot.enroll"}, dependsOnGroups = {"iot.install"}) + public void enrollDevicePopUpModalTest() throws InterruptedException, IOException { + Assert.assertTrue(connectedCupDeviceTypeViewPage.isPopUpPresent()); + } + + @Test(description = "Test case for device enrolment", groups = {"iot.enroll"}, dependsOnMethods = + {"enrollDevicePopUpModalTest"}) + public void enrollDeviceTest() throws InterruptedException { + Assert.assertTrue(connectedCupDeviceTypeViewPage.enrollDevice(Constants.IOT_CONNECTED_CUP_NAME)); + } + + @AfterClass(alwaysRun = true) + 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/SampleEnrolmentVerificationTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleEnrolmentVerificationTest.java new file mode 100644 index 00000000..893a4532 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleEnrolmentVerificationTest.java @@ -0,0 +1,73 @@ +/* +* 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 junit.framework.Assert; +import org.openqa.selenium.WebDriver; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +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.devices.DevicesPage; +import org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceViewPage; +import org.wso2.iot.integration.ui.pages.samples.VirtualSampleViewPage; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +public class SampleEnrolmentVerificationTest extends IOTIntegrationUIBaseTestCase { + private WebDriver webDriver; + private DevicesPage devicesPage; + private ConnectedCupDeviceViewPage connectedCupDeviceViewPage; + @BeforeClass(alwaysRun = true) + public void setUp() throws XPathExpressionException, XMLStreamException, IOException { + super.init(); + webDriver = BrowserManager.getWebDriver(); + LoginUtils.login(webDriver, automationContext, getWebAppURL()); + webDriver.get(getWebAppURL() + Constants.IOT_DEVICES_URL); + devicesPage = new DevicesPage(webDriver); + } + + @Test(description = "Verify enrolment of the sample device", groups = {"iot.enroll.verify"}, dependsOnGroups = "iot.enroll") + public void verifyEnrollmentTest() { + Assert.assertTrue(devicesPage.isDeviceEnrolled(Constants.IOT_CONNECTED_CUP_NAME)); + } + + @Test(description = "Verify navigation to device view", dependsOnMethods = "verifyEnrollmentTest", + groups = {"iot.enroll.verify"}) + public void verifyNavigationTest() throws IOException { + connectedCupDeviceViewPage = devicesPage.viewDevice(Constants.IOT_CONNECTED_CUP_NAME); + Assert.assertNotNull(connectedCupDeviceViewPage); + } + + @Test(description = "Verify sample functions", dependsOnMethods = {"verifyNavigationTest"}) + public void sampleStartUpTest() throws IOException { + VirtualSampleViewPage sampleViewPage = connectedCupDeviceViewPage.gotoDevice(); + Assert.assertNotNull(sampleViewPage); + } + + @AfterClass(alwaysRun = true) + public void tearDown() { + webDriver.quit(); + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationVerification.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationVerification.java index 9dcfdda8..52990dfc 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationVerification.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationVerification.java @@ -27,7 +27,6 @@ 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.devices.EnrollDevicePage; import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard; -import org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceTypeViewPage; import javax.xml.stream.XMLStreamException; import javax.xml.xpath.XPathExpressionException; @@ -36,7 +35,6 @@ import java.io.IOException; public class SampleInstallationVerification extends IOTIntegrationUIBaseTestCase { private WebDriver driver; - private EnrollDevicePage enrollDevicePage; private IOTAdminDashboard adminDashboard; @BeforeClass(alwaysRun = true) @@ -47,17 +45,11 @@ public class SampleInstallationVerification extends IOTIntegrationUIBaseTestCase adminDashboard = new IOTAdminDashboard(driver); } - @Test(description = "Verify the sample is available in Virtual devices section.") + @Test(description = "Verify the sample is available in Virtual devices section.", groups = {"iot.install"}, + dependsOnGroups = {"iot.sample"}) public void installationVerificationTest() throws IOException { - enrollDevicePage = adminDashboard.enrollNewDevice(); - Assert.assertTrue(enrollDevicePage.isInstalled("ConnectedCup")); -// Assert.assertTrue(enrollDevicePage.isInstalled("Virtual Fire Alarm")); - } - - @Test(description = "Verify the installation of UI components.", dependsOnMethods = - {"installationVerificationTest"}) - public void verifyNavigationToDeviceTypeView() throws IOException { - ConnectedCupDeviceTypeViewPage connectedCupDeviceTypeViewPage = enrollDevicePage.gotoConnectedCupDeviceTypeViewPage(); + EnrollDevicePage enrollDevicePage = adminDashboard.enrollNewDevice(); + Assert.assertTrue(enrollDevicePage.isInstalled()); } @AfterClass(alwaysRun = true) diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java index 728a2e08..74ea1715 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java @@ -39,7 +39,6 @@ import java.io.IOException; */ public class NewUserRegistrationTest extends IOTIntegrationUIBaseTestCase { private WebDriver driver; - private UIElementMapper uiElementMapper; @BeforeClass(alwaysRun = true) public void setup() throws XPathExpressionException, XMLStreamException, IOException { @@ -51,7 +50,7 @@ public class NewUserRegistrationTest extends IOTIntegrationUIBaseTestCase { @Test(description = "Verify new User registration") public void userRegisterTest() throws IOException { LoginPage login = new LoginPage(driver); - uiElementMapper = UIElementMapper.getInstance(); + UIElementMapper uiElementMapper = UIElementMapper.getInstance(); NewUserRegisterPage registerTest = login.registerNewUser(); LoginPage loginPage = registerTest.registerUser( uiElementMapper.getElement("iot.user.add.firstname"), diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/testng.xml b/modules/integration/tests-iot-web-ui/src/test/resources/testng.xml index abee28b8..a9e541d4 100644 --- a/modules/integration/tests-iot-web-ui/src/test/resources/testng.xml +++ b/modules/integration/tests-iot-web-ui/src/test/resources/testng.xml @@ -23,7 +23,6 @@ - @@ -37,6 +36,8 @@ + +