Created
April 19, 2014 01:18
-
-
Save saadtazi/11070632 to your computer and use it in GitHub Desktop.
grunt-mocha-webdriver bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jshint node:true*/ | |
//test/e2e/spec/before.js | |
// i put my spec files in the same folder as before.js | |
'use strict'; | |
before(function(done) { | |
// put the browser in global so we don't need 'self=this' | |
// using global vars is not ideal but I think it is acceptable for testing | |
global.browser = this.browser; | |
global.chaiAsPromised.transferPromiseness = this.wd.transferPromiseness; | |
// load some promise Methods | |
require('../helpers/some_async_methods')(this.wd); | |
require('../helpers/other_async_methods')(this.wd); | |
}); | |
after(function(done) { | |
this.browser.quit().then(done, done); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { | |
'use strict'; | |
// load all grunt tasks | |
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); | |
grunt.initConfig({ | |
// .... | |
mochaWebdriver: { | |
options: { | |
testName: 'my test suite', | |
timeout: 1000 * 60, | |
// only used by phantomjs | |
reporter: 'spec', | |
require: [ 'test/e2e/init.js' ], | |
usePromises: true | |
}, | |
phantom: { | |
src: ['test/e2e/spec/before.js', 'test/e2e/spec/*.spec.js'], | |
options: { | |
// phantomjs | |
usePhantom: true | |
} | |
}, | |
saucelabs: { | |
src: ['test/e2e/spec/before.js', 'test/e2e/spec/*.spec.js'], | |
options: { | |
// SAUCELABS | |
testName: 'my test suite - ' + Date(), | |
username: 'xxx', | |
key: 'yyy-zzzz-ttt-uuuu', | |
tunnelFlags: ['--direct-domains', 'www.google.com,facebook.com,api.mixpanel.com'], | |
browsers: [ | |
{ | |
browserName: 'firefox', | |
version: '24', | |
platform: 'Windows XP' | |
}, | |
{ | |
browserName: 'firefox', | |
version: '26', | |
platform: 'Windows 8.1' | |
} | |
] | |
} | |
} | |
// .... | |
} | |
}); | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jshint node:true*/ | |
// test/e2e/init.js | |
// in this file, I add some global requires | |
require('sugar'); | |
// Chai | |
var chai = require('chai'); | |
chai.use( | |
global.chaiAsPromised = require('chai-as-promised') | |
); | |
chai.should(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//test/e2e/helpers/some_async_methods.js | |
module.exports = function(wd) { | |
'use strict'; | |
function injectScript(url) { | |
// this assumes you have jquery in your tested app | |
return global.browser.execute('$.getScript("' + url + '");'); | |
} | |
wd.addPromiseMethod('injectScript', injectScript); | |
// ... add more | |
}; |
And shouldn't you call done()
somewhere along these lines?
https://gist.github.com/saadtazi/11070632#file-before-js-L16
I prefer expect over should. And I am getting an ReferenceError: before is not defined
in my case. Any ideas what else I should call? I think before()
exists only for should?
I prefer expect over should. And I am getting an ReferenceError: before is not defined in my case. Any ideas what else I should call? I think before() exists only for should?
Fixed, it was simply a question of the interface. I am using TDD, you BDD ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wonderful, many thanks!! Very helpful for me.
Can you explain me what the line https://gist.github.com/saadtazi/11070632#file-init-js-L12 is for? Never seen
chai.use()
before. I am using chai's expect here like this:But I do not like this somehow ...