Comments (4)
Hi Umar,
I came up with two use cases for the shared context.
The more useful is when you pass the context object as follows
Yadda(library).yadda(steps, ctx)
Here you can share state between steps....
Given Carol is a female cardiovascular patient
When she is admitted to the elderly care wing
Then she is flagged as off template
So in my given step I would assign ctx.she = new Patient(name, gender,
speciality), then refer to this in the When step.
The second use case is to pass some shared variable to all steps. e.g. a
testing library. This isn't so useful (especially in node where requiring
is easy).
I think it would be bad practice for steps to make changes to the context
object in this case.
Does this answer your question?
On 23 September 2013 11:41, Umar Hansa [email protected] wrote:
Creating a new yadda instance (var yadda = new Yadda(library, context))
allows you to pass some sort of object which each step def can access via
the this keyword. Is there any technique you can think of utilising which
would allow a change to the state object to be applied to all other step
defs?library.given("I do something", function(next) {
this.foo; //bar
this.foo = 'hello';
next();
});The issue here is: in a new step def, this.foo will still be equal to barwhen we actually wanted it to be equal to
hello.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/22
.
from yadda.
Hi Stephen
Thanks for explaining that. It's good to know that steps within a scenario can all share the same stateful context. To describe our use case: Assume Yadda is being used with webdriver. Each step definition within a test suite needs to share a browser
object. In the past, the browser
object was never modified, it was only the case that methods were called against it like browser.findElement
. Then the use case came up where a step def needed to modify the browser object completely because it had to shut down and startup a different browser e.g.
library.given("I am on a Firefox browser", function(next) {
this.browser = FireFox;
});
Looking back, we realised this probably isn't the best way to go about it which is what prompted me to create #21.
The reason I created this issue was to find out how to go about this if I wanted to (figured it's still useful to know). As for the actual syntax, the Yadda(library).yadda(steps, ctx)
you mentioned - does this play nicely when using Yadda with Mocha? E.g. are the method signatures different at all? Right now we're doing something like:
var yadda = new Yadda(library, context);
//testfiles are a suite of feature files
testFiles.forEach(function(path) {
yadda.mocha('A test', path);
});
It looks like yadda.yadda and yadda.mocha work differently?
Near the end of your comment, you gave a use case of sharing a context to all steps. Considering our use case as an example, do you think that would still be considered a bad practice (e.g. modifying a webdriver object so any step def can change the browser)? I'd still be interested to know how one could achieve this, I guess it'd be similar to yadda = new Yadda(library, context)
?
Hope these questions make sense, our testing framework is something that's still being developed upon and it's great to have your some of your help, it's much appreciated!
from yadda.
It looks like yadda.yadda and yadda.mocha work differently?
That's a bug with the mocha plugin. I've created an issue for it (here)[https://github.com//issues/23]. Thanks for pointing this out. I'll try and fix it quickly. The workaround is what you suggested...
yadda = new Yadda(library, context)
The reason I said this would be bad practice is you would have to be careful to ensure your scenarios didn't come to depend on run order. It's probably best to reset the context at the start of each scenario using a given step.
Hope these questions make sense, our testing framework is something that's still being developed upon and it's great to have your some of your help, it's much appreciated!
Yes they do make sense and are very helpful! Yadda is also still being developed and your feedback is very useful
from yadda.
Fixed in 0.6
from yadda.
Related Issues (20)
- Steps that throw an error are not marked FAILED HOT 3
- Async steps with mocha & webdriver HOT 7
- Any suggestions for implementing factories? HOT 3
- Add Ava Example HOT 3
- ya-done HOT 3
- Can not support the back reference of the regular expression in the dictionary definition. HOT 5
- Request: auto retry support HOT 1
- ya-done-appium HOT 3
- Error in a promise step is not reported to QUnit, test hangs HOT 2
- Composing steps? HOT 6
- promise didn't work with nodeJS HOT 14
- Mark step as pending programmatically? HOT 10
- Is it possible yadda with electron-spectrum? HOT 3
- How to run features in parallel? HOT 2
- Skip/Ignore step HOT 2
- Incorrect step implementation is selected HOT 31
- Unable to AddContext in mochawesome reporter. HOT 4
- Add Support for Rule keyword HOT 5
- Bug: the [] empty array literal replaced with empy string when an examples table is used. Escaping examples table placeholders? HOT 3
- Parallelization HOT 2
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 yadda.