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;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.wso2.iot.integration.ui.pages.samples;
|
||||
|
||||
/**
|
||||
* Created by menaka on 3/4/16.
|
||||
*/
|
||||
public class SampleAnalyticsPage {
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue