Skip to content

ui tests #15

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ npm start
```

You browser should automatically open a tab at http://localhost:3000

## Running UI tests

```shell
mocha tests/selenium/*
```
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"url": "[email protected]:mozilla-sensorweb/sensorweb-admin-panel.git"
},
"devDependencies": {
"react-scripts": "0.4.1"
"react-scripts": "0.4.1",
"chai": "^3.5.0",
"chromedriver": "^2.27.2",
"mocha": "^2.5.3",
"selenium-webdriver": "^3.0.1",
"wd": "^0.4.0"
},
"dependencies": {
"classnames": "^2.2.5",
Expand Down
19 changes: 19 additions & 0 deletions tests/selenium/mainPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

var LoginView = require('./views/login/view.js');

function MainPage(driver) {
this.driver = driver;
}

MainPage.prototype = {
getLogInPage : function() {
return new LoginView(this.driver);
},

stop() {
return this.driver.quit();
},
};

module.exports = MainPage;
89 changes: 89 additions & 0 deletions tests/selenium/test_login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'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 service = new chrome.ServiceBuilder(path).build();
chrome.setDefaultService(service);

var HOST_URL = 'http://localhost:3000'

describe( 'Show main page', function(done) {

var mochaTimeOut = 30000; //ms
var driver;

var MainPage = require('./mainPage');
var mainPage;
var loginView;
var elements;


before(function() {
this.timeout(mochaTimeOut);
driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.build();
});

after(() => mainPage.stop());

beforeEach(function() {
driver.get(HOST_URL)
});

it('should be titled sensorweb', function () {
this.timeout(mochaTimeOut);
return driver.wait(webdriver.until.titleIs('SensorWeb'), 5000)
.then(function(value) {
return assert.equal(value, true);
});
});

describe('Sign In', function() {

beforeEach(function() {
elements = {
pwd: driver.findElement(webdriver.By.css('#app > div > div.jumbotron > div > div > form > div:nth-child(2) > input')),
signIn: driver.findElement(webdriver.By.css('button.btn.btn-primary.btn-lg'))
};
mainPage = new MainPage(driver);
loginView = mainPage.getLogInPage();
return loginView;
});

it('should have the rights fields', function() {
var types = {
pwd: 'password',
signIn: 'submit'
};
var promises = Object.keys(elements).map(function(key) {
return elements[key].getAttribute('type')
.then(function(value) {
assert.equal(value, types[key]);
});
});
return Promise.all(promises);
});

it('should error if wrong password', function () {
return loginView.incorrectLogin('a')
.then((text) => { assert.equal(text, 'Unauthorized')});
});

it('should error if empty password', function () {
return loginView.incorrectLogin('')
.then((text) => { assert.equal(text, 'Unauthorized')});
});

it('should login if password is correct', function () {
// The password should be the one used in server -> dev.json file
return loginView.correctPassword('PasswordSet')
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how we can set a default password for the tests. If it depends on the one created in dev.json, could we have that file by default? Or could there be another way?

});
});
17 changes: 17 additions & 0 deletions tests/selenium/views/accessors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const until = require('selenium-webdriver').until;


function Accessors(driver) {
this.driver = driver;
}

Accessors.prototype = {
waitForElement(locator) {
const element = this.driver.wait(until.elementLocated(locator));
return this.driver.wait(until.elementIsEnabled(element));
},
};

module.exports = Accessors;
27 changes: 27 additions & 0 deletions tests/selenium/views/login/accessors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const By = require('selenium-webdriver').By;
const Accessors = require('../accessors');


function LoginAccessors() {
Accessors.apply(this, arguments);
}

LoginAccessors.prototype = Object.assign({

get passwordField() {
return this.waitForElement(By.css('#app > div > div.jumbotron > div > div > form > div:nth-child(2) > input'));
},

get singInButton() {
return this.waitForElement(By.css('#app > div > div.jumbotron > div > div > form > div:nth-child(3) > button'));
},

get unauthorizedError() {
return this.waitForElement(By.css('#app > div > div.jumbotron > div > div > form > div.form-group.has-error > span'))
}

}, Accessors.prototype);

module.exports = LoginAccessors;
36 changes: 36 additions & 0 deletions tests/selenium/views/login/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const View = require('../view');
const LoginAccessors = require('./accessors');


function LoginView() {
[].push.call(arguments, LoginAccessors);
View.apply(this, arguments);

this.accessors.passwordField;
this.accessors.singInButton;
}

LoginView.prototype = Object.assign({

correctPassword(password) {
return this.accessors.passwordField.sendKeys(password)
.then(() => { this.accessors.singInButton.click()
.then(() => {
const SignedInView = require('../signed_in/view');
return new SignedInView(this.driver);
});
});
},

incorrectLogin(password) {
return this.accessors.passwordField.sendKeys(password)
.then(()=>{
return this.accessors.singInButton.click()
}).then(() => { return this.accessors.unauthorizedError.getText()})
}

}, View.prototype);

module.exports = LoginView;
17 changes: 17 additions & 0 deletions tests/selenium/views/signed_in/accessors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const By = require('selenium-webdriver').By;
const Accessors = require('../accessors');


function SignedInAccessors() {
Accessors.apply(this, arguments);
}

SignedInAccessors.prototype = Object.assign({

//TBD

}, Accessors.prototype);

module.exports = SignedInAccessors;
18 changes: 18 additions & 0 deletions tests/selenium/views/signed_in/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const View = require('../view');
const SignedInAccessors = require('./accessors');


function SignedInView() {
[].push.call(arguments, SignedInAccessors);
View.apply(this, arguments);
}

SignedInView.prototype = Object.assign({

// Functions for the SingedIn View TBD

}, View.prototype);

module.exports = SignedInView;
8 changes: 8 additions & 0 deletions tests/selenium/views/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

function View(driver, Accessors) {
this.driver = driver;
this.accessors = new Accessors(driver);
}

module.exports = View;