diff --git a/README.md b/README.md index 062de34..f93178a 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,10 @@ Assets (images, etc.) are included in the `src/assets` folder and referenced by Under the hood, Webpack copies that file to the output directory using an opaque name. Files which are not referenced are not included in the output; this avoids bundling unused files. +## Run Tests + +### Run Selenium Tests + +``` +mocha tests/selenium_tests/* +ยดยดยด diff --git a/package.json b/package.json index 8b85b93..6d81e92 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,11 @@ "typescript": "^2.1.4", "url-loader": "^0.5.7", "webpack": "^2.2.0-rc.3", - "webpack-dev-server": "^1.16.2" + "webpack-dev-server": "^1.16.2", + "chai": "^3.5.0", + "chromedriver": "^2.27.2", + "mocha": "^2.5.3", + "selenium-webdriver": "^3.0.1", + "wd": "^0.4.0" } } diff --git a/tests/selenium_tests/test_SearchLocationWithSensor.js b/tests/selenium_tests/test_SearchLocationWithSensor.js new file mode 100644 index 0000000..39ec25f --- /dev/null +++ b/tests/selenium_tests/test_SearchLocationWithSensor.js @@ -0,0 +1,110 @@ +'use strict'; + +var assert = require('assert'); +var webdriver = require('selenium-webdriver'); +var chrome = require('selenium-webdriver/chrome'); +var path = require('chromedriver').path; +var chai = require("chai"); +chai.should(); + +const By = require('selenium-webdriver').By; +const until = webdriver.until; + +var mochaTimeOut = 300000; //ms +var driver; + +var HOST = 'http://tiny.cc/sensorweb'; + +var service = new chrome.ServiceBuilder(path).build(); + chrome.setDefaultService(service); + +before(function() { + this.timeout(mochaTimeOut); + driver = new webdriver.Builder() + .withCapabilities(webdriver.Capabilities.chrome()) + .build(); + driver.get(HOST); +}); + +var elements; + +describe('Show main page', function() { + + it('should be titled sensorweb', function () { + this.timeout(mochaTimeOut); + return driver.wait(webdriver.until.titleIs('SensorWeb'), 5000) + .then((title) => { + return assert.equal(title, true); + }); + }); + + describe('SensorWeb Location with Sensor(s)', function() { + + beforeEach(function() { + elements = { + searchButton: driver.findElement(webdriver.By.xpath('/html/body/div/div/div/div[2]/div[3]/span'), 5000), + searchInputField: driver.findElement(webdriver.By.xpath('//*[@id="root"]/div/div/div[1]/div[3]/div/input')) + }; + }); + + it('should search for a location with sensor(s)', function () { + this.timeout(mochaTimeOut); + return elements.searchButton.click() + .then(() => { + return driver.wait(webdriver.until.elementIsVisible(elements.searchInputField),5000) + .then(() => { + return elements.searchInputField.sendKeys('San Francisco' + '\n') + }); + }); + }); + + it('should see sensor sensor details', function(){ + //Not the best solution, but need to wait till the view is loaded. Need to find a better solution + driver.sleep(1000) + this.timeout(mochaTimeOut); + return driver.wait(webdriver.until.elementIsVisible(driver.findElement(webdriver.By.css('div.sensorName'),5000))) + .getText() + .then((text) => { + assert.equal(text, 'Sensor') + }); + }); + + it('should get sensor measurement', function(){ + this.timeout(mochaTimeOut); + return driver.wait(webdriver.until.elementIsVisible(driver.findElement(webdriver.By.xpath('//*[@id="root"]/div/div/div[1]/div[2]/div/div[2]/div[1]/div[4]/div/div/span'),5000))) + .getText() + .then((value) => { + chai.assert.isAbove(parseInt(value), '0', 'Sensor value is equal or below 0') + chai.assert.isBelow(parseInt(value), '100', 'Sensor value is higher than 100') + }); + }); + + it('should be able to tap on start to favorite a sensor', function(){ + this.timeout(mochaTimeOut); + return driver.wait(webdriver.until.elementIsVisible(driver.findElement(webdriver.By.xpath('//*[@id="root"]/div/div/div[1]/div[2]/div/div[3]/div[2]/img[2]'),5000))) + .click() + .then(() => { + return driver.wait(webdriver.until.elementIsVisible(driver.findElement(webdriver.By.xpath('//*[@id="root"]/div/div[1]/div/div[1]/h1'),5000))) + .getText() + .then((text) => { + assert.equal(text, 'Favorite Sensor') + }) + }) + }); + + it('should be able to name a sensor', function(){ + this.timeout(mochaTimeOut); + return driver.wait(webdriver.until.elementIsVisible(driver.findElement(webdriver.By.css('#root > div > div.jdnNXn.loaded > div > div.hjxrdF > p:nth-child(2) > input[type="text"]'),5000))) + .sendKeys('name') + .then(() => { + return driver.wait(webdriver.until.elementIsVisible(driver.findElement(webdriver.By.css('#root > div > div.jdnNXn.loaded > div > div.hjxrdF > p:nth-child(3) > button'),5000))) + .click() + //To be checked the correct view + }) + }); + }); +}); + +after(function() { + driver.close(); +}); diff --git a/tests/selenium_tests/test_SensorwebMainViews.js b/tests/selenium_tests/test_SensorwebMainViews.js new file mode 100644 index 0000000..af7c5b2 --- /dev/null +++ b/tests/selenium_tests/test_SensorwebMainViews.js @@ -0,0 +1,76 @@ +'use strict'; + +var assert = require('assert'); +var webdriver = require('selenium-webdriver'); +var chrome = require('selenium-webdriver/chrome'); +var path = require('chromedriver').path; + +const By = require('selenium-webdriver').By; +const until = webdriver.until; + +var mochaTimeOut = 300000; //ms +var driver; + +var HOST = 'http://tiny.cc/sensorweb'; + +var service = new chrome.ServiceBuilder(path).build(); + chrome.setDefaultService(service); + +before(function() { + this.timeout(mochaTimeOut); + driver = new webdriver.Builder() + .withCapabilities(webdriver.Capabilities.chrome()) + .build(); + driver.get(HOST); +}); + +after(function() { + driver.quit(); +}); + +var elements; + +describe('Show main page', function() { + + it('should be titled sensorweb', function () { + this.timeout(mochaTimeOut); + return driver.wait(webdriver.until.titleIs('SensorWeb'), 5000) + .then(function(title) { + return assert.equal(title, true); + }); + }); + + describe('SensorWeb views', function() { + + beforeEach(function() { + elements = { + searchButton: driver.findElement(webdriver.By.xpath('/html/body/div/div/div/div[2]/div[3]/span'), 5000), + favoritesButton: driver.findElement(webdriver.By.xpath('//*[@id="root"]/div/div/div[2]/div[1]/span'), 5000), + favoritesString: driver.findElement(webdriver.By.xpath('//*[@id="root"]/div/div/div[1]/div[1]/div/h1')), + searchInputField: driver.findElement(webdriver.By.xpath('//*[@id="root"]/div/div/div[1]/div[3]/div/input')), + mapLocator: driver.findElement(webdriver.By.xpath('//*[@id="root"]/div/div/div[1]/div[2]/div/div[2]/div[2]/div[2]/div[2]')) + }; + }); + + it('should see Map View', function () { + this.timeout(mochaTimeOut); + return driver.wait(webdriver.until.elementIsVisible(elements.mapLocator),5000); + }); + + it('should click on Search', function () { + this.timeout(mochaTimeOut); + return elements.searchButton.click() + .then(function() { + return driver.wait(webdriver.until.elementIsVisible(elements.searchInputField),5000); + }); + }); + + it('should click on Favorites', function () { + this.timeout(mochaTimeOut); + return elements.favoritesButton.click() + .then(function() { + return driver.wait(webdriver.until.elementIsVisible(elements.favoritesString),5000); + }); + }); + }); +});