Comments (7)
(I didn't try it... but...) did you try to create a top-level before(function() {...})
that contains your snippet (with this.browser
instead of self.browser?
from grunt-mocha-webdriver.
I have over 50 test files here and I do not want to add that before
block on the top of every test file.
What I really fancy is having a reference to the browser
variable inside the require
option (https://github.com/jmreidy/grunt-mocha-webdriver#require)
Also, I want to add plenty of custom chain method for all these tests files. How can I do that the most elegant way from one central place?
from grunt-mocha-webdriver.
You don't need to add it on top of every test file. Only in one file. from mochajs website:
" Note that you may also pick any file and add "root" level hooks, for example add beforeEach() outside of describe()s then the callback will run before any test-case regardless of the file its in. This is because Mocha has a root Suite with no name."
To your second question (where should you add your chain methods), personally I do it in files (grouped by types) that are loaded by that same file that contain that top-level before().
In my grunt config, I have: mochaWebdriver: {oneTarget: {src: ['before.js', ...]}}
And in before.js, I have:
...
before(function() {
// note that this before is not in a context() or describe()
// you can put your .on bindings here
require('helpers/chainMethodsGroup1')(this.wd);
require('helpers/chainMethodsGroup2')(this.wd);
})
helpers/chainMethodsGroup1:
function func1() {
}
module.exports = (function(wd) {
wd.addPromiseMethod('func1', func1);
});
from grunt-mocha-webdriver.
Interesting! And where do you put the global stuff, i.E.
var chai = require('chai');
global.expect = chai.expect;
??? In before.js
too or in a file defined with require
?
PS: I would love to see a complete working example of your code. Do you think you could do a Gist?
from grunt-mocha-webdriver.
I put that in my "require" file:
My require file looks like this (everything is here):
/*jshint node:true*/
// Chai
var chai = require('chai');
chai.use(
global.chaiAsPromised = require('chai-as-promised')
);
chai.should();
from grunt-mocha-webdriver.
@binarykitchen here is a gist (does not include the spec files though): https://gist.github.com/saadtazi/11070632
from grunt-mocha-webdriver.
Wonderful @saadtazi thanks so much!!
from grunt-mocha-webdriver.
Related Issues (20)
- upload
- ECONNREFUSED on file upload HOT 11
- Grunt task hangs on ECONNREFUSED HOT 1
- Release patch version to npm HOT 2
- [feature] See a progress bar HOT 2
- kill() does not fire close event HOT 3
- Move Release History from README.md to History.md HOT 5
- Automatically restart Sauce Connect
- Switch out wd.js for leadfoot HOT 4
- Spawn mocha as a child process HOT 3
- How can I configure the retryDelay parameter? HOT 3
- .setWindowSize no effect on latest PhantomJS HOT 1
- selenium launcher dependency causes failures when behind a firewall that blocks git protocol HOT 1
- Use SauceLabs without Sauce Connect tunnel? HOT 4
- Mocha failures do not cause grunt build to fail
- Use mocha 2
- Custom host server Question
- Implement concept of Adapters HOT 1
- Docs - code example required
- [Question] selenium-webdriver instance instead of wd.js HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-mocha-webdriver.