Reputation: 11
I am creating an automation framework using Ruby, Selenium webdriver and cucumber (Gherkin), so looking to share the data between steps like Scenario Context in specflow (c#) and cucumber (java)?
Any other suggestions will appreciated
Upvotes: 1
Views: 477
Reputation: 4099
Following has lots of ruby pseudocode
There are several ways to share state between steps.
Given a user Fred
When Fred does Foo
Given 'a user Fred'
User.create(name: Fred)
end
When `Fred does Foo` do
fred = User.find_by_name('Fred')
foo_with(fred)
end
Given a user
When the user does foo
Given 'a user'
User.create
end
When 'the user does foo' do
user = User.last
foo_with(user)
end
Given a user Fred
When Fred does foo
Given 'a user Fred' do
@fred = User.create(name: Fred)
end
When 'Fred does foo' do
foo_with(@fred)
end
Using a global is the easiest, and the most dangerous. If you apply great discipline then it can work really well. This is what I use exclusively now.
Upvotes: 0