refactor app directory structure and add tests

This commit is contained in:
s2
2016-11-10 16:27:26 +01:00
parent 204834ce28
commit dd88218c0e
1844 changed files with 263520 additions and 0 deletions

2
tests/node_modules/nightwatch/examples/.npmignore generated vendored Normal file
View File

@@ -0,0 +1,2 @@
reports
screens

View File

@@ -0,0 +1,18 @@
/**
* Simple example of custom command. This command will
* check if there's a onbeforeunload handler in the target web page
* and return the result
*/
/* global window */
module.exports.command = function(callback) {
var self = this;
this.execute(function() {
return window && typeof window.onbeforeunload === 'function';
}, [], function(result) {
callback.call(self, result.value);
});
return this;
};

8
tests/node_modules/nightwatch/examples/globals.json generated vendored Normal file
View File

@@ -0,0 +1,8 @@
{
"default" : {
"myGlobal" : 1
},
"test_env" : {
"myGlobal" : 2
}
}

View File

@@ -0,0 +1,55 @@
module.exports = {
// this controls whether to abort the test execution when an assertion failed and skip the rest
// it's being used in waitFor commands and expect assertions
abortOnAssertionFailure : true,
// this will overwrite the default polling interval (currently 500ms) for waitFor commands
// and expect assertions that use retry
waitForConditionPollInterval : 300,
// default timeout value in milliseconds for waitFor commands and implicit waitFor value for
// expect assertions
waitForConditionTimeout : 5000,
// this will cause waitFor commands on elements to throw an error if multiple
// elements are found using the given locate strategy and selector
throwOnMultipleElementsReturned : true,
// controls the timeout time for async hooks. Expects the done() callback to be invoked within this time
// or an error is thrown
asyncHookTimeout : 10000,
'default' : {
myGlobal : function() {
return 'I\'m a method';
}
},
'test_env' : {
myGlobal: 'test_global',
beforeEach : function() {
}
},
before : function(cb) {
cb();
},
beforeEach : function(browser, cb) {
cb();
},
after : function(cb) {
cb();
},
afterEach : function(browser, cb) {
cb();
},
reporter : function(results, cb) {
//console.log(results);
cb();
}
};

24
tests/node_modules/nightwatch/examples/mocha/github.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
describe('Github', function() {
it('Demo test GitHub', function (client) {
client
.url('https://github.com/nightwatchjs/nightwatch')
.waitForElementVisible('body', 1000)
.assert.title('nightwatchjs/nightwatch · GitHub')
.assert.visible('.container h1 strong a')
.assert.containsText('.container h1 strong a', 'nightwatch', 'Checking project title is set to nightwatch');
});
after(function(client, done) {
if (client.sessionId) {
client.end(function() {
done();
});
} else {
done();
}
});
});

View File

@@ -0,0 +1,38 @@
describe('Google demo test for Mocha', function() {
describe('for demo purposes', function() {
before(function(client, done) {
done();
});
after(function(client, done) {
if (client.sessionId) {
client.end(function() {
done();
});
} else {
done();
}
});
afterEach(function(client, done) {
done();
});
beforeEach(function(client, done) {
done();
});
it('uses BDD to run the Google simple test', function(client) {
client
.url('http://google.com')
.expect.element('body').to.be.present.before(1000);
client.setValue('input[type=text]', ['nightwatch', client.Keys.ENTER])
.pause(1000)
.assert.containsText('#main', 'Night Watch');
});
});
});

17
tests/node_modules/nightwatch/examples/pages/home.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
var searchCommands = {
submit: function() {
this.waitForElementVisible('@submitButton', 3000)
.click('@submitButton')
.api.pause(1000);
return this; // Return page object for chaining
}
};
module.exports = {
url: 'http://google.com',
commands: [searchCommands],
elements: {
searchBar: { selector: 'input[name=q]' },
submitButton: { selector: '[type=submit]' }
}
};

View File

@@ -0,0 +1,31 @@
var util = require('util');
var menuXpath = '//div[contains(@class, "hdtb-mitem")][contains(., %s)]';
var menuCommands = {
productIsSelected: function(product, callback) {
var self = this;
return this.getAttribute(product, 'class', function(result) {
var isSelected = result.value.indexOf('hdtb-msel') > -1;
callback.call(self, isSelected);
});
}
};
module.exports = {
elements: {
results: { selector: '#ires' }
},
sections: {
menu: {
selector: '#hdtb-msb',
commands: [menuCommands],
elements: {
web: { selector: util.format(menuXpath, 'Web'), locateStrategy: 'xpath' },
video: { selector: util.format(menuXpath, 'Video'), locateStrategy: 'xpath' },
images: { selector: util.format(menuXpath, 'Images'), locateStrategy: 'xpath' },
shopping: { selector: util.format(menuXpath, 'Shopping'), locateStrategy: 'xpath' }
}
}
}
};

View File

@@ -0,0 +1 @@
fbcredentials.json

53
tests/node_modules/nightwatch/examples/tests/digg.js generated vendored Normal file
View File

@@ -0,0 +1,53 @@
/**
* =============================================================================
* Demo of Facebook Connect automated login with Nightwatch.js.
* The test navigates to digg.com and tries to perform a Facebook connect login.
*
* This test requires a fbcredentials.json file to be placed in the same
* folder, containing the facebook username and password in the form below:
* -----
* {
* "username" : "",
* "password" : ""
* }
* -----
* The test only works if you have the permissions ALREADY enabled for digg.com
* in your facebook account.
* =============================================================================
*/
module.exports = {
disabled : true,
'digg facebook login' : function (client) {
var fbcredentials;
try {
fbcredentials = require('./fbcredentials.json');
} catch (err) {
console.error('Couldn\'t load the facebook credentials file. Please ensure that ' +
'you have the fbcredentials.json in the same folder as the test.');
process.exit();
}
client
.url('http://digg.com')
.waitForElementVisible('body', 1000)
.click('#nav-signin')
.click('#btn-facebook-auth-topnav')
.windowHandles(function(result) {
client.assert.equal(result.value.length, 2, 'There should be two windows open.');
var fbWindowHandle = result.value[1];
client.switchWindow(fbWindowHandle);
})
.waitForElementVisible('#facebook body', 1000)
.setValue('input#email', fbcredentials.username)
.setValue('input#pass', fbcredentials.password)
.click('#loginbutton input')
.windowHandles(function(result) {
client.assert.equal(result.value.length, 1, 'There should be only one window open.');
client.switchWindow(result.value[0]);
})
.waitForElementVisible('#digg-header.authenticated', 3000)
.end();
}
};

View File

@@ -0,0 +1,14 @@
module.exports = {
tags: ['git'],
'Demo test GitHub' : function (client) {
client
.url('https://github.com/nightwatchjs/nightwatch')
.waitForElementVisible('body', 1000)
.assert.visible('.container h1 strong a')
.assert.containsText('.container h1 strong a', 'nightwatch', 'Checking project title is set to nightwatch');
},
after : function(client) {
client.end();
}
};

29
tests/node_modules/nightwatch/examples/tests/google.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
/* jshint expr: true */
module.exports = {
tags: ['google'],
'Demo test Google' : function (client) {
client
.url('http://google.no')
.pause(1000);
client.expect.element('body').to.be.present;
client.expect.element('#lst-ib').to.have.css('display');
client.expect.element('body').to.have.attribute('class').which.contains('vasq');
client.expect.element('body').to.have.attribute('class').which.matches(/vasq$/);
client.expect.element('body').to.have.attribute('class').before(1000);
client.expect.element('#lst-ib').to.be.enabled;
client.expect.element('#hplogo').text.to.match(/Norge/).before(1000);
client.setValue('#lst-ib', 'Norway').pause(500);
client.expect.element('#lst-ib').to.have.value.equal('Norway');
client.expect.element('#lst-ib').to.be.an('input');
client.expect.element('#lst-ib').to.be.not.selected;
client.expect.element('#lst-ib').to.be.visible;
client.end();
}
};

View File

@@ -0,0 +1,22 @@
/**
* Sample automated test scenario for Nightwatch.js
*
* > it navigates to google.com and searches for nightwatch,
* verifying if the term 'The Night Watch' exists in the search results
*/
module.exports = {
'demo test google' : function (client) {
client
.url('http://google.com')
.waitForElementPresent('body', 1000);
},
'part two' : function(client) {
client
.setValue('input[type=text]', ['nightwatch', client.Keys.ENTER])
.pause(1000)
.assert.containsText('#main', 'Night Watch')
.end();
}
};

View File

@@ -0,0 +1,29 @@
/* jshint expr: true */
module.exports = {
'Demo Google search test using page objects' : function (client) {
var homePage = client.page.home();
homePage.navigate();
homePage.expect.element('@searchBar').to.be.enabled;
homePage
.setValue('@searchBar', 'Nightwatch.js')
.submit();
var resultsPage = client.page.searchResults();
resultsPage.expect.element('@results').to.be.present.after(2000);
resultsPage.expect.element('@results').to.contain.text('Nightwatch.js');
resultsPage.expect.section('@menu').to.be.visible;
var menuSection = resultsPage.section.menu;
menuSection.expect.element('@web').to.be.visible;
menuSection.expect.element('@video').to.be.visible;
menuSection.expect.element('@images').to.be.visible;
menuSection.expect.element('@shopping').to.be.visible;
menuSection.productIsSelected('@web', function(result) {
this.assert.ok(result, 'Web results are shown by default on search results page');
});
client.end();
}
};

View File

@@ -0,0 +1,18 @@
module.exports = {
disabled : true,
'Demo test NightwatchJS.org' : function (client) {
client
.url('http://nightwatchjs.org')
.waitForElementVisible('body', 1000)
.elements('css selector', '#index-container ul.features li', function (result) {
for (var i = 0; i < result.value.length; i++) {
var element = result.value[i];
var selector = '#index-container ul.features li:nth-child(' + (element.ELEMENT ) +') em';
client.verify.cssClassPresent(selector, 'glyphicon');
}
})
.end();
}
};

View File

@@ -0,0 +1,39 @@
/**
* Sample automated test scenario for Nightwatch.js
*
* > it navigates to page that has onbeforeunload handler
*/
module.exports = {
'go to page with unload handler': function(client) {
client
.url('http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm')
.waitForElementVisible('body', 1000);
},
'navigate away from page WITH unload handler': function(client) {
var hasDialog = false;
client
.hasOnBeforeUnload(function(result) {
this.verify.equal(result, true, 'The page should have an onbeforeunload handler');
hasDialog = result;
})
.url('http://google.com', function() {
if (hasDialog) {
this.acceptAlert();
}
})
.waitForElementVisible('body', 1000);
},
'go to nightwatch' : function(c) {
c.url('http://nightwatchjs.org')
.waitForElementVisible('body', 1000);
},
after : function(c) {
c.end();
}
};

View File

@@ -0,0 +1,14 @@
module.exports = {
tags: ['git'],
'Demo test GitHub' : function (client) {
client
.url('https://github.com/nightwatchjs/nightwatch')
.waitForElementVisible('body', 1000)
.assert.visible('.container h1 strong a')
.assert.containsText('.container h1 strong a', 'nightwatch', 'Checking project title is set to nightwatch');
},
after : function(client) {
client.end();
}
};

View File

@@ -0,0 +1,9 @@
module.exports = {
'demo UnitTest' : function (client, done) {
client.assert.ok('TEST');
setTimeout(function() {
done();
}, 500);
}
};

View File

@@ -0,0 +1,41 @@
var Utils = require('../../lib/util/utils.js');
module.exports = {
testFormatElapsedTime : function(client) {
var test = client.assert;
var resultMs = Utils.formatElapsedTime(999);
test.equal(resultMs, '999ms');
var resultSec = Utils.formatElapsedTime(1999);
test.equal(resultSec, '1.999s');
var resultMin = Utils.formatElapsedTime(122299, true);
test.equal(resultMin, '2m 2s / 122299ms');
},
testMakeFnAsync : function(client) {
function asynFn(done) {
done();
}
function syncFn() {}
var test = client.assert;
test.equal(Utils.makeFnAsync(1, asynFn), asynFn);
var convertedFn = Utils.makeFnAsync(1, syncFn);
convertedFn(function() {
test.ok('converted fn called');
});
},
testGetTestSuiteName : function(client) {
var test = client.assert;
test.equal(Utils.getTestSuiteName('test-case-one'), 'Test Case One');
test.equal(Utils.getTestSuiteName('test_case_two'), 'Test Case Two');
test.equal(Utils.getTestSuiteName('test.case.one'), 'Test Case One');
test.equal(Utils.getTestSuiteName('testCaseOne'), 'Test Case One');
}
};

View File

@@ -0,0 +1,29 @@
var Utils = require('../../lib/util/utils.js');
var expect = require('chai').expect;
module.exports = {
testFormatElapsedTime : function(client) {
var resultMs = Utils.formatElapsedTime(999);
var resultSec = Utils.formatElapsedTime(1999);
var resultMin = Utils.formatElapsedTime(122299, true);
expect(resultMs).to.equal('999ms');
expect(resultSec).to.equal('1.999s');
expect(resultMin).to.equal('2m 2s / 122299ms');
},
testFormatElapsedTimeMore : function(client) {
var resultMs = Utils.formatElapsedTime(999);
expect(resultMs).to.equal('999ms');
},
testMakeFnAsync : function(client) {
function asynFn(done) {
done();
}
function syncFn() {}
expect(Utils.makeFnAsync(1, asynFn)).to.equal(asynFn);
}
};