Skip to content

add selenium tests #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
´´´
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
110 changes: 110 additions & 0 deletions tests/selenium_tests/test_SearchLocationWithSensor.js
Original file line number Diff line number Diff line change
@@ -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();
});
76 changes: 76 additions & 0 deletions tests/selenium_tests/test_SensorwebMainViews.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});