forked from community/product-iots
parent
b99001ae8d
commit
adfa5762c9
@ -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<WebElement> 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<WebElement> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue