How can I access a variable inside a multi-step step definition?2019 Community Moderator ElectionIntelliJ with cucumber (java) and step definition locationRuby Watir and Cucumber in Netbeans - scenario undefinedWhat object is in play for instance variables (i.e. what is self) in Cucumber step definitions?How do I reconnect to an orphaned Watir browserHow can I access a Cucumber step name in the step definition?How can I define and call cucumber steps/scenarios outside of the cucumber cli?Java-Cucumber : Feature file is not calling step definition fileCucumber Ruby - Cucumber ExpressionsMultiple steps for same cucumber step definitionJava and Cucumber: Strange ambiguous step definition exception
Are ETF trackers fundamentally better than individual stocks?
If curse and magic is two sides of the same coin, why the former is forbidden?
How to explain that I do not want to visit a country due to personal safety concern?
Instead of Universal Basic Income, why not Universal Basic NEEDS?
What's the meaning of “spike” in the context of “adrenaline spike”?
What is the significance behind "40 days" that often appears in the Bible?
A limit with limit zero everywhere must be zero somewhere
Could the Saturn V actually have launched astronauts around Venus?
Unexpected result from ArcLength
A link redirect to http instead of https: how critical is it?
Professor being mistaken for a grad student
Does Mathematica reuse previous computations?
How could a scammer know the apps on my phone / iTunes account?
In a future war, an old lady is trying to raise a boy but one of the weapons has made everyone deaf
Why is the President allowed to veto a cancellation of emergency powers?
What approach do we need to follow for projects without a test environment?
Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?
Are all passive ability checks floors for active ability checks?
Gravity magic - How does it work?
How to use of "the" before known matrices
Employee lack of ownership
What exactly is this small puffer fish doing and how did it manage to accomplish such a feat?
PTIJ: Who should I vote for? (21st Knesset Edition)
Time travel from stationary position?
How can I access a variable inside a multi-step step definition?
2019 Community Moderator ElectionIntelliJ with cucumber (java) and step definition locationRuby Watir and Cucumber in Netbeans - scenario undefinedWhat object is in play for instance variables (i.e. what is self) in Cucumber step definitions?How do I reconnect to an orphaned Watir browserHow can I access a Cucumber step name in the step definition?How can I define and call cucumber steps/scenarios outside of the cucumber cli?Java-Cucumber : Feature file is not calling step definition fileCucumber Ruby - Cucumber ExpressionsMultiple steps for same cucumber step definitionJava and Cucumber: Strange ambiguous step definition exception
I am currently trying to define a multi-step step definition in Cucumber (for Ruby) but I'm having trouble using a variable in one of the sub-steps. Below I am trying to use the "policy_name" variable in the last sub step but can not get Cucumber to recognize it for its variable value, instead it keeps using it as a string.
Given("I should NOT be able to go back using the browser back button
after doing something string") do |policy|
step 'I click on "something"'
step 'I "do this" via computer'
step 'I click on the browser back button'
policy_name = case policy
when "policy1" then "something1"
when "policy2" then "something2"
end
step 'I should be on the "Specified" page
for #policy_name'
end
ruby selenium cucumber
add a comment |
I am currently trying to define a multi-step step definition in Cucumber (for Ruby) but I'm having trouble using a variable in one of the sub-steps. Below I am trying to use the "policy_name" variable in the last sub step but can not get Cucumber to recognize it for its variable value, instead it keeps using it as a string.
Given("I should NOT be able to go back using the browser back button
after doing something string") do |policy|
step 'I click on "something"'
step 'I "do this" via computer'
step 'I click on the browser back button'
policy_name = case policy
when "policy1" then "something1"
when "policy2" then "something2"
end
step 'I should be on the "Specified" page
for #policy_name'
end
ruby selenium cucumber
1
I should have mentioned this is using Cucumber for Ruby.
– Syed Zaidi
Mar 6 at 20:08
add a comment |
I am currently trying to define a multi-step step definition in Cucumber (for Ruby) but I'm having trouble using a variable in one of the sub-steps. Below I am trying to use the "policy_name" variable in the last sub step but can not get Cucumber to recognize it for its variable value, instead it keeps using it as a string.
Given("I should NOT be able to go back using the browser back button
after doing something string") do |policy|
step 'I click on "something"'
step 'I "do this" via computer'
step 'I click on the browser back button'
policy_name = case policy
when "policy1" then "something1"
when "policy2" then "something2"
end
step 'I should be on the "Specified" page
for #policy_name'
end
ruby selenium cucumber
I am currently trying to define a multi-step step definition in Cucumber (for Ruby) but I'm having trouble using a variable in one of the sub-steps. Below I am trying to use the "policy_name" variable in the last sub step but can not get Cucumber to recognize it for its variable value, instead it keeps using it as a string.
Given("I should NOT be able to go back using the browser back button
after doing something string") do |policy|
step 'I click on "something"'
step 'I "do this" via computer'
step 'I click on the browser back button'
policy_name = case policy
when "policy1" then "something1"
when "policy2" then "something2"
end
step 'I should be on the "Specified" page
for #policy_name'
end
ruby selenium cucumber
ruby selenium cucumber
edited Mar 6 at 21:16
Syed Zaidi
asked Mar 6 at 19:56
Syed ZaidiSyed Zaidi
11
11
1
I should have mentioned this is using Cucumber for Ruby.
– Syed Zaidi
Mar 6 at 20:08
add a comment |
1
I should have mentioned this is using Cucumber for Ruby.
– Syed Zaidi
Mar 6 at 20:08
1
1
I should have mentioned this is using Cucumber for Ruby.
– Syed Zaidi
Mar 6 at 20:08
I should have mentioned this is using Cucumber for Ruby.
– Syed Zaidi
Mar 6 at 20:08
add a comment |
2 Answers
2
active
oldest
votes
Are you using single quote or double quotes? Double quotes allow for interpolation while single quotes will just use the contents without translating any variables. "#policy_name"
should work, while '#any_variable'
should not work.
add a comment |
Don't write steps like this and don't nest steps, you will just get into a mess. Also Given's are for setting up state, not for doing something.
If you have a complex step like this you have two better options than nesting steps
- Break the step into simpler steps
- Push the complexity down out of the step definitions and into helper methods
Having steps like "When I click something" is counter productive. That step is all about HOW something is done. Scenarios should be about WHAT you are doing and WHY its important. Features and scenarios are not for programming, they are for describing behaviour and should be very simple. So you should be writing something like
Scenario: When I foo then the back button is disabled
Given ...
When I foo
Then the back button should be disabled
an example for my bank would be
Scenario: Smile login disables back button
Given I am logged into smile banking
When I try and use the back button
Then I should see the back button disabled warning
Finally each step definition should just be a call to a helper method. e.g.
Given 'I am logged into smile banking' do
# NOTE: both params are also helper methods
login(site: smile_banking, user: create_user)
end
this allows you to push all the complexity out of cucumber and into code. Code can handle complexity, Cucumber cannot.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031242%2fhow-can-i-access-a-variable-inside-a-multi-step-step-definition%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Are you using single quote or double quotes? Double quotes allow for interpolation while single quotes will just use the contents without translating any variables. "#policy_name"
should work, while '#any_variable'
should not work.
add a comment |
Are you using single quote or double quotes? Double quotes allow for interpolation while single quotes will just use the contents without translating any variables. "#policy_name"
should work, while '#any_variable'
should not work.
add a comment |
Are you using single quote or double quotes? Double quotes allow for interpolation while single quotes will just use the contents without translating any variables. "#policy_name"
should work, while '#any_variable'
should not work.
Are you using single quote or double quotes? Double quotes allow for interpolation while single quotes will just use the contents without translating any variables. "#policy_name"
should work, while '#any_variable'
should not work.
answered Mar 6 at 22:28
Danilo CabelloDanilo Cabello
1,4801221
1,4801221
add a comment |
add a comment |
Don't write steps like this and don't nest steps, you will just get into a mess. Also Given's are for setting up state, not for doing something.
If you have a complex step like this you have two better options than nesting steps
- Break the step into simpler steps
- Push the complexity down out of the step definitions and into helper methods
Having steps like "When I click something" is counter productive. That step is all about HOW something is done. Scenarios should be about WHAT you are doing and WHY its important. Features and scenarios are not for programming, they are for describing behaviour and should be very simple. So you should be writing something like
Scenario: When I foo then the back button is disabled
Given ...
When I foo
Then the back button should be disabled
an example for my bank would be
Scenario: Smile login disables back button
Given I am logged into smile banking
When I try and use the back button
Then I should see the back button disabled warning
Finally each step definition should just be a call to a helper method. e.g.
Given 'I am logged into smile banking' do
# NOTE: both params are also helper methods
login(site: smile_banking, user: create_user)
end
this allows you to push all the complexity out of cucumber and into code. Code can handle complexity, Cucumber cannot.
add a comment |
Don't write steps like this and don't nest steps, you will just get into a mess. Also Given's are for setting up state, not for doing something.
If you have a complex step like this you have two better options than nesting steps
- Break the step into simpler steps
- Push the complexity down out of the step definitions and into helper methods
Having steps like "When I click something" is counter productive. That step is all about HOW something is done. Scenarios should be about WHAT you are doing and WHY its important. Features and scenarios are not for programming, they are for describing behaviour and should be very simple. So you should be writing something like
Scenario: When I foo then the back button is disabled
Given ...
When I foo
Then the back button should be disabled
an example for my bank would be
Scenario: Smile login disables back button
Given I am logged into smile banking
When I try and use the back button
Then I should see the back button disabled warning
Finally each step definition should just be a call to a helper method. e.g.
Given 'I am logged into smile banking' do
# NOTE: both params are also helper methods
login(site: smile_banking, user: create_user)
end
this allows you to push all the complexity out of cucumber and into code. Code can handle complexity, Cucumber cannot.
add a comment |
Don't write steps like this and don't nest steps, you will just get into a mess. Also Given's are for setting up state, not for doing something.
If you have a complex step like this you have two better options than nesting steps
- Break the step into simpler steps
- Push the complexity down out of the step definitions and into helper methods
Having steps like "When I click something" is counter productive. That step is all about HOW something is done. Scenarios should be about WHAT you are doing and WHY its important. Features and scenarios are not for programming, they are for describing behaviour and should be very simple. So you should be writing something like
Scenario: When I foo then the back button is disabled
Given ...
When I foo
Then the back button should be disabled
an example for my bank would be
Scenario: Smile login disables back button
Given I am logged into smile banking
When I try and use the back button
Then I should see the back button disabled warning
Finally each step definition should just be a call to a helper method. e.g.
Given 'I am logged into smile banking' do
# NOTE: both params are also helper methods
login(site: smile_banking, user: create_user)
end
this allows you to push all the complexity out of cucumber and into code. Code can handle complexity, Cucumber cannot.
Don't write steps like this and don't nest steps, you will just get into a mess. Also Given's are for setting up state, not for doing something.
If you have a complex step like this you have two better options than nesting steps
- Break the step into simpler steps
- Push the complexity down out of the step definitions and into helper methods
Having steps like "When I click something" is counter productive. That step is all about HOW something is done. Scenarios should be about WHAT you are doing and WHY its important. Features and scenarios are not for programming, they are for describing behaviour and should be very simple. So you should be writing something like
Scenario: When I foo then the back button is disabled
Given ...
When I foo
Then the back button should be disabled
an example for my bank would be
Scenario: Smile login disables back button
Given I am logged into smile banking
When I try and use the back button
Then I should see the back button disabled warning
Finally each step definition should just be a call to a helper method. e.g.
Given 'I am logged into smile banking' do
# NOTE: both params are also helper methods
login(site: smile_banking, user: create_user)
end
this allows you to push all the complexity out of cucumber and into code. Code can handle complexity, Cucumber cannot.
answered Mar 7 at 23:55
diabolistdiabolist
2,2511712
2,2511712
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031242%2fhow-can-i-access-a-variable-inside-a-multi-step-step-definition%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I should have mentioned this is using Cucumber for Ruby.
– Syed Zaidi
Mar 6 at 20:08