Skip to content

Context awareness (sketch)

Márton Mészáros edited this page Jul 26, 2013 · 2 revisions

This is just a braindump to start collecting what I should write.

Writing scripts:

Given Bob is interested in bikes
And Jill is also interested in bikes
When Bob searches for bikes on Bing
And Jill searches for bikes on Google
Then the first hit should be the same for Bob and Jill

Capturing conversations

Given Bob is interested in bikes
And Jill is also interested in bikes
When Bob searches for them on Bing
And Jill does the same on Google
Then the first hit should be the same for each

Introducing he/she

The actormanager now responds to he/she actors.

Given Bob is interested in bikes
When he searches for them on Bing

He can be used interchangeably with an actor label. The ActorManager will know that you're referring to the last used actor. Given this

Given Bob is interested in bikes
And Jill is also interested in bikes
When he searches for them on Bing

"He" will now translate to Jill. Yes, It's gender agnostic, and will probably stay that way, unless someone sends me a pull request to solve the problem it holds.

Introducing ScenarioContext

In a conversation there are many scopes. What step definition shared state usually tries to solve is the scenario context, and we lose that somewhat with minimizing state sharing. Recognizing that we use Actors to perform Actions on different Subjcets helped in coming up with this solution. The Subject of the conversation can change over time. Luckily we tend to be bad at following multiple references, so the stack is usually 1 level deep. For example if I say I'm talking about bikes, when I mention "them", you know that I'm referring to bikes. Luckily there's no such thing as them[2] in spoken languages.

So ScenarioContext is basically a 1 level deep stack of Subjects and Actions

A ScenarioContext lives as a shared member in the step definition files. Whenever you perform an action with a subject, you can call context.setSubject(subject)

A subject could be any object, the context does not care. For example you can do:

ScenarioContext sc = new DefaultScenarioContext();
SearchTerm term = new SearchTerm("bikes");

sc.setContext(term);

SearchTerm whatAreWeSearchingFor = sc.getContext();

You will get an error if you're trying to retrieve a different type to what is the current subject. That'd mean that your understanding of what the current topic is about is wrong.

You can set the last action the same way, and it's useful in situations like:

And Jill does the same on Google

This would end up being something like:

Actor actor = actorManager.getActor(actorLabel);
actor.execute(context.getLastAction());

This is how easy it can be to redo the last operation as someone else.

Cleaning up

I recommend calling context.empty() with a before/after hook to avoid mixups.

Clone this wiki locally