Completed the sample test cases.

merge-requests/1/head
Menaka Madushanka 9 years ago
parent adfa5762c9
commit ead5b6e2bb

@ -0,0 +1,45 @@
package org.wso2.iot.integration.ui.pages.graphs;
/**
* Class to store graph data
*/
public class Graph {
private String graphId;
private String yAxis;
private String xAxis;
private String legend;
public void setGraphId(String graphId) {
this.graphId = graphId;
}
public String getyAxis() {
return yAxis;
}
public void setyAxis(String yAxis) {
this.yAxis = yAxis;
}
public String getxAxis() {
return xAxis;
}
public void setxAxis(String xAxis) {
this.xAxis = xAxis;
}
public String getLegend() {
return legend;
}
public void setLegend(String legend) {
this.legend = legend;
}
@Override
public String toString(){
return String.format("The graph for graph id : %s, X - axis : %s, Y - axis : %s, legend : %s ", graphId,
xAxis, yAxis, legend);
}
}

@ -0,0 +1,165 @@
/*
* 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.graphs;
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;
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;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* Graphs should also be tested in UI tests. So, this class contains methods to extract various properties of graphs..
* Such as,
* - Legend
* - Tool Tips
* - X, Y axis properties
* - get the graph path values etc.
* Works with IOT server device view graphs and analytics graphs.
*/
public class GraphHandler {
private UIElementMapper uiElementMapper;
private Log log = LogFactory.getLog(GraphHandler.class);
private WebElement graphDiv;
private WebDriver driver;
private List<WebElement> graphs;
public GraphHandler(WebDriver driver) throws IOException {
this.driver = driver;
uiElementMapper = UIElementMapper.getInstance();
graphDiv = driver.findElement(By.xpath(uiElementMapper.getElement("iot.stats.graph.container.xpath")));
}
/**
* This method is to get all the elements of graphs and store in a Hash map.
* This simplifies iterating through the DOM every time finding for an element when having multiple graphs.
*/
public HashMap<String, Graph> getGraphMap() {
HashMap<String, Graph> graphMap = new HashMap<>();
WebDriverWait wait = new WebDriverWait(driver, UIConstants.webDriverTimeOut);
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath(
uiElementMapper.getElement("iot.stat.graph.wrapper.xpath")))));
List<WebElement> graphs = driver.findElements(By.xpath(
uiElementMapper.getElement("iot.stat.graph.wrapper.xpath")));
for (WebElement e : graphs) {
Graph g = new Graph();
String key = e.getAttribute("id").split("-")[1];
g.setGraphId(key.toLowerCase().replace(" ", ""));
String xAxis = e.findElement(By.xpath(uiElementMapper.getElement("ot.stat.graph.xAxis.xpath"))).getText();
g.setxAxis(xAxis);
String yAxis = e.findElement(By.xpath("//*[contains(@id, \"y_axis-" + key + "\")]")).getText();
g.setyAxis(yAxis);
String legend = e.findElement(By.xpath("//*[contains(@id, \"legend-" + key + "\")]")).findElement(
By.tagName("span")).getText();
g.setLegend(legend);
graphMap.put(key, g);
log.info(g.toString());
}
return graphMap;
}
/**
* Get the number of graphs in the UI
*/
public int getGraphCount() {
try {
graphs = this.graphDiv.findElements(By.xpath("//*[contains(@class, \"chartWrapper\")]"));
} catch (NoSuchElementException e) {
log.info("Graph element not found");
}
return graphs.size();
}
/**
* Get the Web Element corresponds to the given graph id
*
* @param graphId : the id of the graph.
* @return Web Element of the graph
*/
public WebElement getGraphById(String graphId) {
graphs = this.graphDiv.findElements(By.xpath(uiElementMapper.getElement("iot.stat.graph.wrapper.xpath")));
for (int i = 0; i < graphs.size() && graphs.size() > 0; i++) {
WebElement element = graphs.get(i);
if (element.getAttribute("id").toLowerCase().replace(" ", "").contains(graphId.toLowerCase())) {
log.info(">>>>>>>>>>>>>>>>>>> Graph for id: " + graphId + " is present ");
return element;
}
}
return null;
}
/**
* Check the graph path is visible or not.
*
* @param graph : web element of the graph
* @return : True if the path is visible. False otherwise
*/
public boolean isPathAvailable(WebElement graph) {
try {
WebElement graphContainer = getGraph(graph, uiElementMapper.getElement("iot.stat.graph.class.name"));
return graphContainer != null && graphContainer.findElement(By.tagName("path")).isDisplayed();
} catch (NoSuchElementException e) {
log.error("No element found. " + e.getMessage());
return false;
}
}
/**
* Check the path of the graph draws the values pushed by the device. As it takes some time, explicit wait of 10
* seconds is added.
*
* @param graph : Web element of the graph
* @param val : Value which pushed by the device
* @return : True if the path is drawn to the values. False otherwise.
*/
public boolean isPathGetValues(WebElement graph, String val) {
WebElement graphContainer = getGraph(graph, uiElementMapper.getElement("iot.stat.graph.class.name"));
driver.manage().timeouts().implicitlyWait(UIConstants.webDriverTimeOut, TimeUnit.SECONDS);
String[] values;
if (graphContainer != null) {
values = graphContainer.findElement(By.tagName("path")).getAttribute("d").split(",");
for (String value : values) {
if (value.contains(val)) {
log.info("Graph values : " + value);
return true;
}
}
}
return false;
}
private WebElement getGraph(WebElement graph, String className) {
List<WebElement> elements = graph.findElements(By.tagName("div"));
for (WebElement e : elements) {
if (e.getAttribute("class").contains(className)) {
return e;
}
}
return null;
}
}

@ -48,7 +48,6 @@ public class ConnectedCupDeviceTypeViewPage {
Thread.sleep(UIConstants.threadTimeout); Thread.sleep(UIConstants.threadTimeout);
return driver.findElement(By.xpath(uiElementMapper.getElement("iot.sample.modal.popup.xpath"))).isDisplayed(); return driver.findElement(By.xpath(uiElementMapper.getElement("iot.sample.modal.popup.xpath"))).isDisplayed();
} }
public boolean enrollDevice(String name) throws InterruptedException { public boolean enrollDevice(String name) throws InterruptedException {
@ -62,5 +61,4 @@ public class ConnectedCupDeviceTypeViewPage {
return driver.findElement(By.xpath( return driver.findElement(By.xpath(
uiElementMapper.getElement("iot.sample.connectedcup.page.title"))).getText().contains("Connected Cup"); uiElementMapper.getElement("iot.sample.connectedcup.page.title"))).getText().contains("Connected Cup");
} }
} }

@ -17,37 +17,108 @@
*/ */
package org.wso2.iot.integration.ui.pages.samples; 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.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.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIConstants; 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 org.wso2.iot.integration.ui.pages.graphs.Graph;
import org.wso2.iot.integration.ui.pages.graphs.GraphHandler;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
public class ConnectedCupDeviceViewPage { public class ConnectedCupDeviceViewPage {
private WebDriver driver; private HashMap<String, Graph> graphMap = new HashMap<>();
private Log log = LogFactory.getLog(ConnectedCupDeviceViewPage.class);
private WebDriver driverServer;
private WebDriver driverDevice;
private UIElementMapper uiElementMapper; private UIElementMapper uiElementMapper;
private GraphHandler handler;
public ConnectedCupDeviceViewPage(WebDriver driver, String name) throws IOException { public ConnectedCupDeviceViewPage(WebDriver driver, String name) throws IOException {
this.driver = driver; this.driverServer = driver;
this.driverDevice = driver;
this.uiElementMapper = UIElementMapper.getInstance(); this.uiElementMapper = UIElementMapper.getInstance();
this.handler = new GraphHandler(driverServer);
if (!driver.findElement(By.xpath( if (!driver.findElement(By.xpath(
uiElementMapper.getElement("iot.sample.connectedcup.view.page.title"))).getText(). uiElementMapper.getElement("iot.sample.connectedcup.view.page.title"))).getText().
contains(name)) { contains(name)) {
throw new IllegalStateException("This is not the Connected cup device type view page"); throw new IllegalStateException("This is not the Connected cup device type view page");
} }
handler = new GraphHandler(driverServer);
graphMap = handler.getGraphMap();
} }
public VirtualSampleViewPage gotoDevice() throws IOException { public VirtualSampleViewPage gotoDevice() throws IOException {
WebDriverWait wait = new WebDriverWait(driver, UIConstants.webDriverTime); WebDriverWait wait = new WebDriverWait(driverServer, UIConstants.webDriverTime);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath"))));
String link = driverServer.findElement(By.xpath(
uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath"))).getAttribute("href");
driverDevice.get(link);
return new VirtualSampleViewPage(driverDevice);
}
public String getDeviceLink() {
WebDriverWait wait = new WebDriverWait(driverServer, UIConstants.webDriverTime);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath")))); uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath"))));
driver.findElement(By.xpath(uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath"))).click(); return driverServer.findElement(By.xpath(
return new VirtualSampleViewPage(driver); uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath"))).getAttribute("href");
} }
public boolean isGraphsAvailable(int count) throws IOException {
return handler.getGraphCount() == count;
}
public boolean graphAxisName(String axis, String graphId, String axisName) throws IOException {
log.info(graphMap.toString());
if (graphMap.size() != 0) {
if (axis.toLowerCase().contains("x")) {
return graphMap.get(graphId).getxAxis().contains(axisName);
} else {
return graphMap.get(graphId).getyAxis().contains(axisName);
}
}
return false;
}
public boolean graphLegendName(String graphId, String legend) throws IOException {
log.info(graphMap.toString());
if (graphMap.size() != 0) {
try {
return graphMap.get(graphId).getLegend().contains(legend);
} catch (NullPointerException e) {
log.info("Null Pointer" + e.getMessage());
}
}
return false;
}
public boolean checkGraphPath(String graphId) {
WebElement graph = handler.getGraphById(graphId);
if (graph != null) {
return handler.isPathAvailable(graph);
} else {
log.error(String.format("Graph for Id %s is not present......", graphId));
return false;
}
}
public boolean checkGraphValues(String graphId, String value) {
WebElement graph = handler.getGraphById(graphId);
if (graph != null) {
return handler.isPathGetValues(graph, value);
} else {
log.error(String.format("Graph for Id %s is not present......", graphId));
return false;
}
}
} }

@ -0,0 +1,7 @@
package org.wso2.iot.integration.ui.pages.samples;
/**
* Created by menaka on 3/4/16.
*/
public class SampleAnalyticsPage {
}

@ -22,15 +22,18 @@ import org.apache.commons.logging.LogFactory;
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.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIConstants; 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;
import java.util.concurrent.TimeUnit;
public class VirtualSampleViewPage { public class VirtualSampleViewPage {
Log log = LogFactory.getLog(VirtualSampleViewPage.class); private Log log = LogFactory.getLog(VirtualSampleViewPage.class);
private WebDriver driver; private WebDriver driver;
private UIElementMapper uiElementMapper; private UIElementMapper uiElementMapper;
@ -54,13 +57,12 @@ public class VirtualSampleViewPage {
return false; return false;
} }
public boolean changeTemperature(String val) { public boolean changeTemperature(String temp) {
if (UIConstants.isElementPresent(log, driver, By.xpath( if (UIConstants.isElementPresent(log, driver, By.xpath(
uiElementMapper.getElement("iot.sample.temperature.xpath")))) { uiElementMapper.getElement("iot.sample.temperature.xpath")))) {
WebElement tempSlider = driver.findElement(By.xpath( WebElement tempSlider = driver.findElement(By.xpath(
uiElementMapper.getElement("iot.sample.temperature.xpath"))); uiElementMapper.getElement("iot.sample.temperature.xpath")));
tempSlider.clear(); moveSlider(tempSlider, Integer.parseInt(temp));
tempSlider.sendKeys(val);
return true; return true;
} }
return false; return false;
@ -69,12 +71,19 @@ public class VirtualSampleViewPage {
public boolean changeCoffeeLevel(String level) { public boolean changeCoffeeLevel(String level) {
if (UIConstants.isElementPresent(log, driver, By.xpath( if (UIConstants.isElementPresent(log, driver, By.xpath(
uiElementMapper.getElement("iot.sample.coffee.level.xpath")))) { uiElementMapper.getElement("iot.sample.coffee.level.xpath")))) {
WebElement tempSlider = driver.findElement(By.xpath( WebElement lvlSlider = driver.findElement(By.xpath(
uiElementMapper.getElement("iot.sample.coffee.level.xpath"))); uiElementMapper.getElement("iot.sample.coffee.level.xpath")));
tempSlider.clear(); moveSlider(lvlSlider, Integer.parseInt(level));
tempSlider.sendKeys(level); driver.manage().timeouts().implicitlyWait(UIConstants.webDriverTime, TimeUnit.SECONDS);
return true; return true;
} }
return false; return false;
} }
private void moveSlider(WebElement slider, int val) {
Actions move = new Actions(driver);
Action action = move.dragAndDropBy(slider, 0, val).build();
action.perform();
}
} }

@ -38,6 +38,7 @@ public class SampleEnrolmentVerificationTest extends IOTIntegrationUIBaseTestCas
private WebDriver webDriver; private WebDriver webDriver;
private DevicesPage devicesPage; private DevicesPage devicesPage;
private ConnectedCupDeviceViewPage connectedCupDeviceViewPage; private ConnectedCupDeviceViewPage connectedCupDeviceViewPage;
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void setUp() throws XPathExpressionException, XMLStreamException, IOException { public void setUp() throws XPathExpressionException, XMLStreamException, IOException {
super.init(); super.init();
@ -47,19 +48,23 @@ public class SampleEnrolmentVerificationTest extends IOTIntegrationUIBaseTestCas
devicesPage = new DevicesPage(webDriver); devicesPage = new DevicesPage(webDriver);
} }
@Test(description = "Verify enrolment of the sample device", groups = {"iot.enroll.verify"}, dependsOnGroups = "iot.enroll") @Test(description = "Verify enrolment of the sample device",
groups = {"iot.enroll.verify"},
dependsOnGroups = "iot.enroll")
public void verifyEnrollmentTest() { public void verifyEnrollmentTest() {
Assert.assertTrue(devicesPage.isDeviceEnrolled(Constants.IOT_CONNECTED_CUP_NAME)); Assert.assertTrue(devicesPage.isDeviceEnrolled(Constants.IOT_CONNECTED_CUP_NAME));
} }
@Test(description = "Verify navigation to device view", dependsOnMethods = "verifyEnrollmentTest", @Test(description = "Verify navigation to device view",
dependsOnMethods = "verifyEnrollmentTest",
groups = {"iot.enroll.verify"}) groups = {"iot.enroll.verify"})
public void verifyNavigationTest() throws IOException { public void verifyNavigationTest() throws IOException {
connectedCupDeviceViewPage = devicesPage.viewDevice(Constants.IOT_CONNECTED_CUP_NAME); connectedCupDeviceViewPage = devicesPage.viewDevice(Constants.IOT_CONNECTED_CUP_NAME);
Assert.assertNotNull(connectedCupDeviceViewPage); Assert.assertNotNull(connectedCupDeviceViewPage);
} }
@Test(description = "Verify sample functions", dependsOnMethods = {"verifyNavigationTest"}) @Test(description = "Verify sample functions",
dependsOnMethods = {"verifyNavigationTest"})
public void sampleStartUpTest() throws IOException { public void sampleStartUpTest() throws IOException {
VirtualSampleViewPage sampleViewPage = connectedCupDeviceViewPage.gotoDevice(); VirtualSampleViewPage sampleViewPage = connectedCupDeviceViewPage.gotoDevice();
Assert.assertNotNull(sampleViewPage); Assert.assertNotNull(sampleViewPage);
@ -69,5 +74,4 @@ public class SampleEnrolmentVerificationTest extends IOTIntegrationUIBaseTestCas
public void tearDown() { public void tearDown() {
webDriver.quit(); webDriver.quit();
} }
} }

@ -0,0 +1,184 @@
/*
* 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;
import java.util.concurrent.TimeUnit;
/**
* Test cases for test the functionality of the connected cup sample.
* In these test cases following features are tested.
* 1. Setting temperature and Coffee level
* 2. Order coffee
* 3. Test the stat graphs
*/
public class SampleFunctionalityTest extends IOTIntegrationUIBaseTestCase {
private WebDriver driverDevice;
private WebDriver driverServer;
private VirtualSampleViewPage sampleViewPage;
private ConnectedCupDeviceViewPage connectedCupDeviceViewPage;
@BeforeClass(alwaysRun = true)
public void setUp() throws XPathExpressionException, XMLStreamException, IOException {
super.init();
driverDevice = BrowserManager.getWebDriver();
driverServer = BrowserManager.getWebDriver();
LoginUtils.login(driverServer, automationContext, getWebAppURL());
driverServer.get(getWebAppURL() + Constants.IOT_DEVICES_URL);
DevicesPage devicesPage = new DevicesPage(driverServer);
connectedCupDeviceViewPage = devicesPage.viewDevice(Constants.IOT_CONNECTED_CUP_NAME);
driverDevice.get(connectedCupDeviceViewPage.getDeviceLink());
sampleViewPage = new VirtualSampleViewPage(driverDevice);
}
@Test(description = "Set the temperature level.",
groups = {"iot.sample.verify"},
dependsOnGroups = "iot.enroll.verify")
public void setTemperatureTest() {
Assert.assertTrue(sampleViewPage.changeTemperature(Constants.IOT_CONNECTED_CUP_TEMPERATURE));
}
@Test(description = "Set the coffee level.",
groups = {"iot.sample.verify"},
dependsOnGroups = "iot.enroll.verify")
public void setCoffeeLevelTest() throws IOException {
Assert.assertTrue(sampleViewPage.changeCoffeeLevel(Constants.IOT_CONNECTED_CUP_LEVEl));
}
@Test(description = "Verify order coffee function.",
groups = {"iot.sample.verify"},
dependsOnGroups = "iot.enroll.verify")
public void orderCoffeeTest() throws IOException, InterruptedException {
Assert.assertTrue(sampleViewPage.orderCoffee());
}
@Test(description = "Test the graphs are present in device view.",
groups = {"iot.sample.verify"},
dependsOnMethods = {"setTemperatureTest", "setCoffeeLevelTest", "orderCoffeeTest"})
public void verifyGraphs() throws IOException {
Assert.assertTrue(connectedCupDeviceViewPage.isGraphsAvailable(2));
}
@Test(description = "Test the Y axis name of Temperature graph.",
groups = {"iot.sample.verify", "sample.temp"},
dependsOnGroups = {"iot.enroll.verify"},
dependsOnMethods = {"verifyGraphs"})
public void temperatureGraphYAxisNameTest() throws IOException {
Assert.assertTrue(connectedCupDeviceViewPage.graphAxisName(Constants.IOT_GRAPH_Y_AXIS,
Constants.IOT_CONNECTED_CUP_TEMPERATURE_ID,
Constants.IOT_CONNECTED_CUP_TEMPERATURE_Y_AXIS));
}
@Test(description = "Test the X axis name of Temperature graph.",
groups = {"iot.sample.verify", "sample.temp"},
dependsOnGroups = {"iot.enroll.verify"},
dependsOnMethods = {"verifyGraphs"})
public void temperatureGraphXAxisNameTest() throws IOException {
Assert.assertTrue(connectedCupDeviceViewPage.graphAxisName(Constants.IOT_GRAPH_X_AXIS,
Constants.IOT_CONNECTED_CUP_TEMPERATURE_ID,
Constants.IOT_CONNECTED_CUP_TEMPERATURE_X_AXIS));
}
@Test(description = "Test the whether the Coffee Level graph legend is present.",
groups = {"iot.sample.verify", "sample.temp"},
dependsOnGroups = {"iot.enroll.verify"},
dependsOnMethods = {"verifyGraphs"})
public void temperatureGraphLegendTest() throws IOException {
Assert.assertTrue(connectedCupDeviceViewPage.graphLegendName(Constants.IOT_CONNECTED_CUP_TEMPERATURE_ID,
Constants.IOT_CONNECTED_CUP_TEMPERATURE_LEGEND));
}
@Test(description = "Test the whether the Temperature graph path is visible.",
groups = {"iot.sample.verify", "sample.temp"},
dependsOnGroups = {"iot.enroll.verify"},
dependsOnMethods = {"verifyGraphs"})
public void temperatureGraphPathTest() {
Assert.assertTrue(connectedCupDeviceViewPage.checkGraphPath(Constants.IOT_CONNECTED_CUP_TEMPERATURE_GRAPH_ID));
}
@Test(description = "Test the whether the Temperature graph gets values.",
groups = {"iot.sample.verify", "sample.temp"},
dependsOnGroups = {"iot.enroll.verify"},
dependsOnMethods = {"verifyGraphs"})
public void temperatureGraphDataPublisherTest() {
Assert.assertTrue(connectedCupDeviceViewPage.checkGraphValues(Constants.IOT_CONNECTED_CUP_TEMPERATURE_GRAPH_ID,
Constants.IOT_CONNECTED_CUP_TEMPERATURE));
}
@Test(description = "Test the Y axis name of Coffee Level graph.",
groups = {"iot.sample.coffee"},
dependsOnGroups = {"sample.temp"})
public void coffeeLevelGraphYAxisNameTest() throws IOException {
Assert.assertTrue(connectedCupDeviceViewPage.graphAxisName(Constants.IOT_GRAPH_Y_AXIS,
Constants.IOT_CONNECTED_CUP_COFFEE_LEVEL_ID,
Constants.IOT_CONNECTED_CUP_COFFEE_LEVEL_Y_AXIS));
}
@Test(description = "Test the X axis name of Coffee Level graph.",
groups = {"iot.sample.coffee"},
dependsOnGroups = {"iot.enroll.verify", "sample.temp"})
public void coffeeLevelGraphXAxisNameTest() throws IOException {
Assert.assertTrue(connectedCupDeviceViewPage.graphAxisName(Constants.IOT_GRAPH_X_AXIS,
Constants.IOT_CONNECTED_CUP_COFFEE_LEVEL_ID,
Constants.IOT_CONNECTED_CUP_COFFEE_LEVEL_X_AXIS));
}
@Test(description = "Test the whether the Coffee Level graph legend is present.",
groups = {"iot.sample.coffee"},
dependsOnGroups = {"sample.temp"})
public void coffeeLevelGraphLegendTest() throws IOException {
Assert.assertTrue(connectedCupDeviceViewPage.graphLegendName(Constants.IOT_CONNECTED_CUP_COFFEE_LEVEL_ID,
Constants.IOT_CONNECTED_CUP_COFFEE_LEVEL_LEGEND));
}
@Test(description = "Test the whether the Coffee Level graph path is visible.",
groups = {"iot.sample.coffee"},
dependsOnGroups = {"sample.temp"})
public void coffeeLevelGraphPathTest() {
Assert.assertTrue(connectedCupDeviceViewPage.checkGraphPath(Constants.IOT_CONNECTED_CUP_COFFEE_LEVEL_GRAPH_ID));
}
@Test(description = "Test the whether the Coffee Level graph gets values.",
groups = {"iot.sample.coffee"},
dependsOnGroups = {"sample.temp"})
public void coffeeLevelGraphDataPublisherTest() {
Assert.assertTrue(connectedCupDeviceViewPage.checkGraphValues(Constants.IOT_CONNECTED_CUP_COFFEE_LEVEL_GRAPH_ID,
Constants.IOT_CONNECTED_CUP_LEVEl));
}
@AfterClass(alwaysRun = true)
public void tearDown() {
driverServer.quit();
driverDevice.quit();
}
}

@ -20,8 +20,6 @@ package org.wso2.carbon.iot.integration.web.ui.test.samples;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.testng.Assert; import org.testng.Assert;
import org.wso2.carbon.logging.view.stub.LogViewerLogViewerException;
import org.wso2.carbon.logging.view.stub.types.carbon.LogEvent;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -30,6 +28,9 @@ import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException
import org.wso2.carbon.integration.common.admin.client.LogViewerClient; import org.wso2.carbon.integration.common.admin.client.LogViewerClient;
import org.wso2.carbon.integration.common.utils.exceptions.AutomationUtilException; import org.wso2.carbon.integration.common.utils.exceptions.AutomationUtilException;
import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager; import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager;
import org.wso2.carbon.iot.integration.web.ui.test.Constants;
import org.wso2.carbon.logging.view.stub.LogViewerLogViewerException;
import org.wso2.carbon.logging.view.stub.types.carbon.LogEvent;
import org.wso2.iot.integration.ui.pages.IOTIntegrationUIBaseTestCase; import org.wso2.iot.integration.ui.pages.IOTIntegrationUIBaseTestCase;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
@ -42,7 +43,12 @@ import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/** /**
* Test cases for building and installation of sample device types. * Test cases for building and installation of sample device types.
@ -55,7 +61,7 @@ import java.util.Properties;
* In this test case, the build process of a new device type and installation to the server is tested. * In this test case, the build process of a new device type and installation to the server is tested.
*/ */
public class SampleInstallationTest extends IOTIntegrationUIBaseTestCase { public class SampleInstallationTest extends IOTIntegrationUIBaseTestCase {
Log log = LogFactory.getLog(SampleInstallationTest.class); private Log log = LogFactory.getLog(SampleInstallationTest.class);
private Process tempProcess = null; private Process tempProcess = null;
private Properties properties = System.getProperties(); private Properties properties = System.getProperties();
private String carbonHome = properties.getProperty("carbon.home"); private String carbonHome = properties.getProperty("carbon.home");
@ -122,14 +128,12 @@ public class SampleInstallationTest extends IOTIntegrationUIBaseTestCase {
{"sampleInstallationTest"}) {"sampleInstallationTest"})
public void serverRestartTest() { public void serverRestartTest() {
ServerConfigurationManager serverManager; ServerConfigurationManager serverManager;
LogEvent[] events;
String msg = "Mgt Console URL : https://10.100.4.7:9443/carbon/";
try { try {
serverManager = new ServerConfigurationManager(automationContext); serverManager = new ServerConfigurationManager(automationContext);
log.info("Restart Triggered -------------------------------------------------------------------");
serverManager.restartGracefully(); serverManager.restartGracefully();
logViewerClient.getAllRemoteSystemLogs();
events = logViewerClient.getAllRemoteSystemLogs(); waitForRestart();
Assert.assertTrue(waitForRestart(events, msg));
} catch (AutomationUtilException | XPathExpressionException | MalformedURLException e) { } catch (AutomationUtilException | XPathExpressionException | MalformedURLException e) {
log.error("Restart failed due to : " + e.getLocalizedMessage()); log.error("Restart failed due to : " + e.getLocalizedMessage());
} catch (RemoteException | LogViewerLogViewerException e) { } catch (RemoteException | LogViewerLogViewerException e) {
@ -157,11 +161,45 @@ public class SampleInstallationTest extends IOTIntegrationUIBaseTestCase {
return status; return status;
} }
private boolean waitForRestart(LogEvent[] events, String msg) { private void waitForRestart() {
for (LogEvent event : events) { ExecutorService service = Executors.newSingleThreadExecutor();
if (event.getMessage().contains(msg)) try {
return true; Runnable r = new Runnable() {
@Override
public void run() {
try {
LogEvent[] logEvents = logViewerClient.getAllRemoteSystemLogs();
for (LogEvent event : logEvents) {
log.info(event.getMessage() + " @ " + event.getLogTime());
if (event.getMessage().contains("Mgt Console URL : " )){
log.info("Server restarted successfully");
Assert.assertTrue(true);
}
}
} catch (RemoteException | LogViewerLogViewerException e) {
e.printStackTrace();
}
}
};
Future<?> f = service.submit(r);
f.get(Constants.IOT_RESTART_THREAD_TIMEOUT, TimeUnit.MINUTES);
}
catch (final InterruptedException e) {
log.error("Interrupted "+e.getMessage());
Assert.assertTrue(false);
}
catch (final TimeoutException e) {
log.error("Timeout " + e.getMessage());
Assert.assertTrue(false);
}
catch (final ExecutionException e) {
log.error("Execution failed " + e.getMessage());
Assert.assertTrue(false);
}
finally {
service.shutdown();
} }
return false;
} }
} }

Loading…
Cancel
Save