Skip to content

Commit

Permalink
Add end to end tests with mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatic committed Aug 21, 2016
1 parent 8b4b5fc commit 18d6197
Show file tree
Hide file tree
Showing 9 changed files with 1,241 additions and 7 deletions.
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
language: node_js
node_js:
- "0.10"

- '4'
before_script:
- /bin/env
- /bin/ps auxf
- env
- ps auxf
- hostname
- uname -a
- npm install -g protractor
script: e2e/run.sh
addons:
sauce_connect:
username: "fanatic"
access_key:
secure: Yhe4v48+JYDcaByL3/ZZf2qUbCYx9p1WjNa6nR6lW3Q7BJbLFERzyvTMoLyGfDRHNlnLE3cRfZM6NHNmAb8s8idtzilnC+RYEGLLi2KlGz2p6Xp9fKg0rkhIMGbuwQ4Z0pQMHeuYYCEp69/HKocQcaqiYtCtiLz4UTft+Tq0VQI=
12 changes: 12 additions & 0 deletions e2e/mocks/get-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
request: {
path: '/users/1',
method: 'GET'
},
response: {
data: {
userName: 'pro-mock',
email: '[email protected]'
}
}
}
42 changes: 42 additions & 0 deletions e2e/protractor.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
exports.config = {
baseUrl: 'http://localhost:8888/',
//seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['specs/*.js'],

// Sauce Labs Setup
sauceUser: process.env.SAUCE_USERNAME,
sauceKey: process.env.SAUCE_ACCESS_KEY,

// restartBrowserBetweenTests: true,

onPrepare: function(){
var caps = browser.getCapabilities()
},

multiCapabilities: [{
browserName: 'firefox',
version: '32',
platform: 'OS X 10.10',
name: "firefox-tests",
shardTestFiles: true,
maxInstances: 2,
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER
}, {
browserName: 'chrome',
version: '41',
platform: 'Windows 7',
name: "chrome-tests",
shardTestFiles: true,
maxInstances: 2,
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER
}],

onComplete: function() {
var printSessionId = function(jobName){
browser.getSession().then(function(session) {
console.log('SauceOnDemandSessionID=' + session.getId() + ' job-name=' + jobName);
});
}
printSessionId("Insert Job Name Here");
}
};
17 changes: 17 additions & 0 deletions e2e/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

if [[ "$(basename `pwd`)" == "e2e" ]]; then
echo "Run from the root of the project instead"
echo "./e2e/run.sh"
exit 1
fi

python -m SimpleHTTPServer 8888 &
http_pid=$!

function finish {
kill -9 $http_pid
}
trap finish EXIT

protractor e2e/protractor.conf.js
46 changes: 46 additions & 0 deletions e2e/specs/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
describe('swift-ui homepage', function() {
beforeEach(function () {
browser.driver.get('http://localhost:8888/index.html');
});

it('should log in', function() {
//browser.pause();
// Allow page to load
browser.sleep(10000);

expect(browser.driver.getTitle()).toEqual('Swift UI');
browser.driver.findElement(by.id('loginButton')).click();

// Wait for login
browser.sleep(1000);

var loginText = browser.driver.findElement(by.css('#login-entry .navbar-text'));
expect(loginText.getText()).toEqual('Signed in as test:tester');
});

it('should list accounts and details', function() {
browser.sleep(10000);
browser.driver.findElement(by.id('loginButton')).click();

// Wait for login
browser.sleep(2000);

//browser.pause();

var account = browser.driver.findElement(by.css('#test[rel="account"] a'));
expect(account.getText()).toEqual(' test');
account.click();

// Wait for account details to laod
browser.sleep(1000);

var breadcrumb = browser.driver.findElement(by.css('.breadcrumb > li:first-child'));
expect(breadcrumb.getText()).toEqual('test');

var header = browser.driver.findElement(by.css('.page-header > h1 > small'));
expect(header.getText()).toEqual('Account');

var metadata = browser.driver.findElement(by.css('#Color.metadata'));
expect(metadata.getText()).toEqual('blue');
});
});
2 changes: 1 addition & 1 deletion js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var appConfig = {
"auth": {
"username": "test:tester",
"key": "testing",
"endpoint": "http://192.168.2.77:8080/auth/v1.0"
"endpoint": "http://example.com:8080/auth/v1.0"
}
};

Loading

0 comments on commit 18d6197

Please sign in to comment.