Git Product home page Git Product logo

Comments (4)

cressie176 avatar cressie176 commented on September 13, 2024

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
.

http://peaceoneday.org/

from yadda.

umaar avatar umaar commented on September 13, 2024

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.

cressie176 avatar cressie176 commented on September 13, 2024

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.

cressie176 avatar cressie176 commented on September 13, 2024

Fixed in 0.6

from yadda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.