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










0















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









share|improve this question



















  • 1





    I should have mentioned this is using Cucumber for Ruby.

    – Syed Zaidi
    Mar 6 at 20:08















0















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









share|improve this question



















  • 1





    I should have mentioned this is using Cucumber for Ruby.

    – Syed Zaidi
    Mar 6 at 20:08













0












0








0








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












2 Answers
2






active

oldest

votes


















0














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.






share|improve this answer






























    0














    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



    1. Break the step into simpler steps

    2. 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.






    share|improve this answer






















      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
      );



      );













      draft saved

      draft discarded


















      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









      0














      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.






      share|improve this answer



























        0














        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.






        share|improve this answer

























          0












          0








          0







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 6 at 22:28









          Danilo CabelloDanilo Cabello

          1,4801221




          1,4801221























              0














              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



              1. Break the step into simpler steps

              2. 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.






              share|improve this answer



























                0














                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



                1. Break the step into simpler steps

                2. 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.






                share|improve this answer

























                  0












                  0








                  0







                  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



                  1. Break the step into simpler steps

                  2. 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.






                  share|improve this answer













                  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



                  1. Break the step into simpler steps

                  2. 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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 7 at 23:55









                  diabolistdiabolist

                  2,2511712




                  2,2511712



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                      Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                      Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved