Skip to content

Commit

Permalink
Add selenium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michiel de Jong committed Feb 5, 2016
1 parent c735fba commit e41029a
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 17 deletions.
16 changes: 8 additions & 8 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
<body>
<h1>Welcome to your FoxBox!</h1>
<p>
<label for="pwd1">Please choose an admin password (8 characters minimal):</label>
<input type="password" id="pwd1">
<label for="pwd1-input">Please choose an admin password (8 characters minimal):</label>
<input type="password" id="pwd1-input">
</p>
<p>
<label for="pwd1">Please repeat your admin password:</label>
<input type="password" id="pwd2">
<label for="pwd2-input">Please repeat your admin password:</label>
<input type="password" id="pwd2-input">
</p>
<p>
<input type="submit" value="Set" onclick="setPassword();">
<input id="set-button" type="submit" value="Set" onclick="setPassword();">
</p>
</body>
<script>
function success() {
document.body.innerHTML =
'<h1>Thank you!</h1>' +
'<h1 id="thank-you">Thank you!</h1>' +
'<p>Now please us an app like <a href="http://example.com/">http://example.com/</a> to connect your IoT '+
'devices and set everything up. Please write down the following information:</p>' +
'<ul><li>FoxBox location (\'' +
Expand All @@ -31,8 +31,8 @@ <h1>Welcome to your FoxBox!</h1>
'<li>Your password (the one you just created).</li></ul></p>';
}
function setPassword() {
var pwd = document.getElementById('pwd1').value;
if (document.getElementById('pwd2').value != pwd) {
var pwd = document.getElementById('pwd1-input').value;
if (document.getElementById('pwd2-input').value != pwd) {
window.alert('Passwords don\'t match! Please try again.');
return;
}
Expand Down
100 changes: 91 additions & 9 deletions test/selenium/ftu_test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,100 @@
var assert = require('assert'),
test = require('selenium-webdriver/testing'),
webdriver = require('selenium-webdriver'),
driver = new webdriver.Builder().
forBrowser('firefox').
build();
webdriver = require('selenium-webdriver');

test.describe('setup page', function() {
var driver;
this.timeout(8000);
test.it('should be titled FoxBox', function (done) {
before(function() {
driver = new webdriver.Builder().
forBrowser('firefox').
build();
});
beforeEach(function() {
driver.get('http://foxbox.local:3000/');
driver.wait(webdriver.until.titleIs('FoxBox'), 5000).then(function(value) {
assert.equal(value, true);
done();
}, done);
});
after(function() {
driver.quit();
});

test.it('should be titled FoxBox', function () {
return driver.wait(webdriver.until.titleIs('FoxBox'), 5000).then(function(value) {
assert.equal(value, true);
});
});
describe('UI to set admin password', function() {
var elts;
beforeEach(function() {
elts = {
pwd1: driver.findElement(webdriver.By.id('pwd1-input')),
pwd2: driver.findElement(webdriver.By.id('pwd2-input')),
set: driver.findElement(webdriver.By.id('set-button'))
};
});
test.it('should have the right fields', function () {
var types = {
pwd1: 'password',
pwd2: 'password',
set: 'submit'
}
var promises = Object.keys(elts).map(function(key) {
return elts[key].getAttribute('type').then(function(value) {
assert.equal(value, types[key]);
});
});
return Promise.all(promises);
});

test.it('should reject non-matching passwords', function () {
return elts.pwd1.sendKeys('asdfasdf').then(function() {
return elts.pwd2.sendKeys('qwerqwer');
}).then(function() {
return elts.set.click();
}).then(function() {
return driver.wait(webdriver.until.alertIsPresent(), 5000);
}).then(function() {
return driver.switchTo().alert();
}).then(function(alert) {
return alert.getText().then(function(text) {
assert.equal(text, 'Passwords don\'t match! Please try again.');
}).then(function() {
alert.dismiss();
});
});
});

test.it('should reject short passwords', function () {
return elts.pwd1.sendKeys('asdf').then(function() {
return elts.pwd2.sendKeys('asdf');
}).then(function() {
return elts.set.click();
}).then(function() {
return driver.wait(webdriver.until.alertIsPresent(), 5000);
}).then(function() {
return driver.switchTo().alert();
}).then(function(alert) {
return alert.getText().then(function(text) {
assert.equal(text, 'Please use a password of at least 8 characters.');
}).then(function() {
alert.dismiss();
});
});
});

test.it('should accept matching, long-enough passwords', function () {
return elts.pwd1.sendKeys('asdfasdf').then(function() {
return elts.pwd2.sendKeys('asdfasdf');
}).then(function() {
return elts.set.click();
}).then(function() {
return driver.findElement(webdriver.By.id('thank-you'));
}).then(function(elt) {
return driver.wait(webdriver.until.elementIsVisible(elt), 5000).then(function() {
return elt.getAttribute('innerHTML');
}).then(function(value) {
assert.equal(value, 'Thank you!');
});
});
});
});
});

0 comments on commit e41029a

Please sign in to comment.