Commit 2d1516a8 authored by Colin Eberhardt's avatar Colin Eberhardt Committed by Sindre Sorhus

Close GH-840: The browser used to run the tests can be specified.

parent 398ddbb7
module.exports = function (grunt) { module.exports = function (grunt) {
'use strict'; 'use strict';
grunt.loadNpmTasks('grunt-simple-mocha'); grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.initConfig({ grunt.initConfig({
simplemocha: { simplemocha: {
...@@ -15,4 +16,5 @@ module.exports = function (grunt) { ...@@ -15,4 +16,5 @@ module.exports = function (grunt) {
// build tasks // build tasks
grunt.registerTask('test', ['simplemocha']); grunt.registerTask('test', ['simplemocha']);
grunt.registerTask('dev', ['jshint']);
}; };
...@@ -49,6 +49,16 @@ In order to run a specific test, using the mocha 'grep' function. For example: ...@@ -49,6 +49,16 @@ In order to run a specific test, using the mocha 'grep' function. For example:
1 passing (3s) 1 passing (3s)
###Specifying the browser
You can also specify the browser that will be used to execute the tests via the `---browser` argument. The tests default to using Chrome (see the instructions below for installing ChromeDriver). For example, to run against phantomjs, use the following:
mocha allTests.js --reporter spec --browser=phantomjs
You must install phantomjs first of course!
Valid browser names can be found within webdriver via the `webdriver.Browser` enumeration.
##Reporting against known issues ##Reporting against known issues
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
var testSuite = require('./test.js'); var testSuite = require('./test.js');
var fs = require('fs'); var fs = require('fs');
var argv = require('optimist').default('laxMode', false).argv; var argv = require('optimist').default('laxMode', false).default('browser', 'chrome').argv;
var rootUrl = 'http://localhost:8000/'; var rootUrl = 'http://localhost:8000/';
var frameworkNamePattern = /^[a-z-_]+$/; var frameworkNamePattern = /^[a-z-_]+$/;
var excludedFrameworks = [ var excludedFrameworks = [
// this implementation deviates from the specification to such an extent that they are // this implementation deviates from the specification to such an extent that they are
// not worth testing via a generic mecanism // not worth testing via a generic mechanism
'gwt', 'gwt',
// selenium webdriver cannot see the shadow dom // selenium webdriver cannot see the shadow dom
'polymer', 'polymer',
...@@ -21,7 +21,8 @@ var excludedFrameworks = [ ...@@ -21,7 +21,8 @@ var excludedFrameworks = [
// sammyjs fails intermittently, it would appear that its state is sometimes updated asynchronously? // sammyjs fails intermittently, it would appear that its state is sometimes updated asynchronously?
'sammyjs', 'sammyjs',
// these are examples that have been removed or are empty folders // these are examples that have been removed or are empty folders
'emberjs_require', 'dermis', 'react-backbone']; 'emberjs_require', 'dermis', 'react-backbone'
];
// collect together the framework names from each of the subfolders // collect together the framework names from each of the subfolders
var list = fs.readdirSync('../architecture-examples/') var list = fs.readdirSync('../architecture-examples/')
...@@ -74,7 +75,7 @@ if (argv.framework) { ...@@ -74,7 +75,7 @@ if (argv.framework) {
return framework.name === argv.framework; return framework.name === argv.framework;
}); });
if(list.length === 0) { if (list.length === 0) {
console.log('You have either requested an unknown or an un-supported framework'); console.log('You have either requested an unknown or an un-supported framework');
} }
} }
...@@ -84,6 +85,5 @@ list.forEach(function (framework) { ...@@ -84,6 +85,5 @@ list.forEach(function (framework) {
testSuite.todoMVCTest( testSuite.todoMVCTest(
framework.name, framework.name,
rootUrl + framework.path + '/index.html', argv.speedMode, rootUrl + framework.path + '/index.html', argv.speedMode,
argv.laxMode argv.laxMode, argv.browser);
);
}); });
...@@ -6,17 +6,17 @@ module.exports = function Page(browser) { ...@@ -6,17 +6,17 @@ module.exports = function Page(browser) {
// ----------------- utility methods // ----------------- utility methods
this.tryFindByXpath = function(xpath) { this.tryFindByXpath = function (xpath) {
return browser.findElements(webdriver.By.xpath(xpath)); return browser.findElements(webdriver.By.xpath(xpath));
} };
this.findByXpath = function(xpath) { this.findByXpath = function (xpath) {
return browser.findElement(webdriver.By.xpath(xpath)); return browser.findElement(webdriver.By.xpath(xpath));
} };
this.getTodoListXpath = function() { this.getTodoListXpath = function () {
return '//ul[@id="todo-list"]'; return '//ul[@id="todo-list"]';
} };
this.xPathForItemAtIndex = function (index) { this.xPathForItemAtIndex = function (index) {
// why is XPath the only language silly enough to be 1-indexed? // why is XPath the only language silly enough to be 1-indexed?
......
...@@ -15,9 +15,9 @@ module.exports = function PageLaxMode(browser) { ...@@ -15,9 +15,9 @@ module.exports = function PageLaxMode(browser) {
return this.tryFindByXpath('//section//footer'); return this.tryFindByXpath('//section//footer');
}; };
this.getTodoListXpath = function() { this.getTodoListXpath = function () {
return '(//section/ul | //section/div/ul | //ul[@id="todo-list"])'; return '(//section/ul | //section/div/ul | //ul[@id="todo-list"])';
} };
this.getMarkAllCompletedCheckBox = function () { this.getMarkAllCompletedCheckBox = function () {
var xpath = '(//section/input[@type="checkbox"] | //section/*/input[@type="checkbox"] | //input[@id="toggle-all"])'; var xpath = '(//section/input[@type="checkbox"] | //section/*/input[@type="checkbox"] | //input[@id="toggle-all"])';
......
...@@ -6,13 +6,11 @@ var Page = require('./page'); ...@@ -6,13 +6,11 @@ var Page = require('./page');
var PageLaxMode = require('./pageLaxMode'); var PageLaxMode = require('./pageLaxMode');
var TestOperations = require('./testOperations'); var TestOperations = require('./testOperations');
module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMode) { module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMode, browserName) {
test.describe('TodoMVC - ' + frameworkName, function () { test.describe('TodoMVC - ' + frameworkName, function () {
var otherUrl = 'http://localhost:8000/';
var TODO_ITEM_ONE = 'buy some cheese'; var TODO_ITEM_ONE = 'buy some cheese';
var TODO_ITEM_TWO = 'feed the cat'; var TODO_ITEM_TWO = 'feed the cat';
var TODO_ITEM_THREE = 'book a doctors appointment'; var TODO_ITEM_THREE = 'book a doctors appointment';
var browser, testOps, page; var browser, testOps, page;
// a number of tests use this set of ToDo items. // a number of tests use this set of ToDo items.
...@@ -24,7 +22,7 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -24,7 +22,7 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
function launchBrowser() { function launchBrowser() {
browser = new webdriver.Builder() browser = new webdriver.Builder()
.withCapabilities({browserName : 'chrome' }) .withCapabilities({browserName : browserName})
.build(); .build();
browser.get(baseUrl); browser.get(baseUrl);
......
'use strict'; 'use strict';
var assert = require('assert'), var assert = require('assert');
Q = require('q'); var Q = require('q');
function TestOperations(page) { function TestOperations(page) {
...@@ -111,7 +111,9 @@ function TestOperations(page) { ...@@ -111,7 +111,9 @@ function TestOperations(page) {
// create an array of promises which check the presence of the // create an array of promises which check the presence of the
// label text within the 'textArray' // label text within the 'textArray'
var tests = []; var tests = [];
for(var i=0;i<labels.length;i++) { for (var i = 0; i < labels.length; i++) {
// suppressing JSHint - the loop variable is not being used in the function.
/* jshint -W083 */
tests.push(labels[i].getText().then(function (text) { tests.push(labels[i].getText().then(function (text) {
var index = textArray.indexOf(text); var index = textArray.indexOf(text);
assert(index !== -1, 'A todo item with text \'' + text + '\' was not found'); assert(index !== -1, 'A todo item with text \'' + text + '\' was not found');
...@@ -134,7 +136,7 @@ function TestOperations(page) { ...@@ -134,7 +136,7 @@ function TestOperations(page) {
this.assertItemAtIndexIsCompleted = function (index) { this.assertItemAtIndexIsCompleted = function (index) {
page.getItemElements().then(function (toDoItems) { page.getItemElements().then(function (toDoItems) {
toDoItems[index].getAttribute('class').then(function (cssClass) { toDoItems[index].getAttribute('class').then(function (cssClass) {
assert(cssClass.indexOf('completed') !== -1, assert(cssClass.indexOf('completed') !== -1,
'the item at index ' + index + ' should have been marked as completed'); 'the item at index ' + index + ' should have been marked as completed');
}); });
}); });
...@@ -169,9 +171,9 @@ function TestOperations(page) { ...@@ -169,9 +171,9 @@ function TestOperations(page) {
})); }));
} }
for (var i=0; i<3;i++) { for (var i = 0; i < 3; i++) {
pushTest(i); pushTest(i);
}; }
// execute all the tests // execute all the tests
return Q.all(tests); return Q.all(tests);
......
...@@ -20,6 +20,7 @@ We think it's best for the project if the code you write looks like the code the ...@@ -20,6 +20,7 @@ We think it's best for the project if the code you write looks like the code the
## Submitting a New App ## Submitting a New App
- **Read the [App Specification](app-spec.md) thoroughly** - **Read the [App Specification](app-spec.md) thoroughly**
- Use the [automated browser tests](/browser-tests) to ensure that your app meets the app specification requirements. For bonus points add the test output to your pull request!
- Make sure it hasn't already been submitted or declined by searching the issue tracker - Make sure it hasn't already been submitted or declined by searching the issue tracker
- Looking at our most recent [reference app](https://github.com/tastejs/todomvc/tree/gh-pages/architecture-examples/backbone) - Looking at our most recent [reference app](https://github.com/tastejs/todomvc/tree/gh-pages/architecture-examples/backbone)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment