Hi Hans,
As I mentioned we had the same problem (generating some data dynamically that
Step1 uses and then Step2 needs for verification) and I was simply sharing how
we solved it in case you find it useful
Again we have a static map inside a static class. We call it ThreadLocalUtils
the map is ThreadSafe and it lives for the duration of the execution of all
stories. Here we store the value w a predefined key (scenarioID + "someString")
on Step1. We later retrieve the value when we need it in Step2
Here is the declaration of the collection
private static final ThreadLocal<Map<Object, Object>> threadLocal = new
ThreadLocal<Map<Object, Object>>() {
@Override
protected java.util.Map<Object,Object>
initialValue() {
logger.info("[ThreadLocalUtil]
Creating the thread local map for the first time for thread [{}].",
Thread.currentThread().getName());
return new HashMap<Object,
Object>();
};
};
I also said that I liked the idea of adding a variable in the pageObject that
stores it (we have implemented it and it also works). For instance on the
CheckingAccount pageObject you can have a variable "latestDeposit". Here we
would save the deposit amount generated on Step1 and then simple retrieve it on
Step2 when we need it. Hope this helps.
Thanks,
Enrique
From: Hans Schwäbli [mailto:[email protected]]
Sent: Tuesday, November 05, 2013 7:15 AM
To: [email protected]
Subject: Re: [jbehave-user] Support for dynamic variables?
Enrique, I was asking for information not demanding a feature.
Can you guarantee that that page object implementation works for everyone or
works at all?
What if JBehave instantiates new Steps from time to time? The dynamic variables
would be gone. When implementing dynamic variables JBehave framework has to be
considered since it runs the steps in its own way and you have not much control
over it, whether it instantiates new Steps or uses the same. Is there a
contract for this? If not, what if JBehave implementation is changed and this
solution does not work anymore? I think it is worth thinking a bit about the
consequences.
And what if you run parallel stories. Is it guaranteed that each run will have
its own step objects or will they be shared?
What about life cycle issues? What if you want to clean all dynamic variables
after each story has run for instance? That would require some design and being
embedded in the story run machine.
And is it such a far fetched thing to suppose that JBehave might support
dynamic variables for the runtime if it already supports variables which are
set at "compile" time?
As I said, I am not demanding anything, but I think a few thoughts about this
(or questions how others have done it) are no bad idea before implementing
dynamic variables.
2013/10/31 Jorge Pombar
<[email protected]<mailto:[email protected]>>
We also have several scenarios where the input for the scenarios are determined
at runtime.
I think Paul offered a good solution, create a variable in the pageObject and
set it (by the When step) then you can get it (on the Then step) for
verification (I think we'll give this approach a chance)
Another solution is to have a static map where you set it and then retrieve it
when needed. This is what we have implemented and it works for us.
Thanks,
Enrique
From: Hans Schwäbli
[mailto:[email protected]<mailto:[email protected]>]
Sent: Thursday, October 31, 2013 8:24 AM
To: [email protected]<mailto:[email protected]>
Subject: Re: [jbehave-user] Support for dynamic variables?
I see. So there is no use looking for a existing JBehave feature for this.
I meant dynamic variables which are set and used at runtime. There are cases
where one has to automate tests on non-deterministic test data (I mean the data
of the application under test).
A "life cycle" of these variables might be an issue in future. Currently I
cannot tell you a real world use case for it. But I think there might be the
need to configure the scope of such dynamic variables to be existing per
stories, per story or per scenario. This would require a close integration into
JBehave execution procedure.
The easiest could be to store the variables for the whole execution and to
clear them if needed in steps annotated with @BeforeStory for instance.
I have to think a bit on how I could solve this in a suitable and good way.
2013/10/31 Mauro Talevi
<[email protected]<mailto:[email protected]>>
Typically you would define an API to access these variables. This is
something that you cannot really generalise.
If on the other hand you know these variable at execution time, you could pass
them as system properties in the jbehave maven goal or ant task.
On 31 Oct 2013, at 11:12, Hans Schwäbli
<[email protected]<mailto:[email protected]>> wrote:
> For some stories and scenarios I need dynamic variables which are determined
> at runtime.
>
> Example: I want to store the balance of an account, do some transactions and
> then expect that the balance is increased by 1000 for instance. If your test
> data are not deterministic you need such approaches.
>
> Is there a JBehave feature for this, storing such dynamic variables at
> runtime and accessing them at runtime across scenarios and stories?
>
> Or do I have to implement that myself in my steps?
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email