{"id":13527,"date":"2017-03-09T00:00:00","date_gmt":"2017-03-09T06:00:00","guid":{"rendered":"https:\/\/centricconsulting.com\/post\/creating-cucumber-step-definitions_sqat-columbus\/"},"modified":"2021-12-15T00:13:53","modified_gmt":"2021-12-15T05:13:53","slug":"creating-cucumber-step-definitions_sqat-columbus","status":"publish","type":"post","link":"https:\/\/centricconsulting.com\/blog\/creating-cucumber-step-definitions_sqat-columbus\/","title":{"rendered":"Creating Cucumber Step Definitions"},"content":{"rendered":"

Read about Step Definitions in of our\u00a0How-To-Guide on applying Cucumber\u00a0to lead your agile testing team\u00a0down the path to\u00a0automation.<\/h2>\n

Blog five of a series<\/a>.<\/em><\/p>\n

You have decided to use Cucumber as your BDD automation tool, built a skeleton framework, and created your first Scenario. <\/span><\/p>\n

But, while looking at your BDD Gherkin script, you are probably wondering: why is it highlighted in yellow?<\/span><\/p>\n

\"WebDriver\"<\/p>\n

\"WebDriver\"<\/p>\n

If you place the cursor over one of the highlighted lines, Cucumber will answer your question: Because Cucumber cannot find a corresponding step definition for the step. This is a good sign, however, because it is one more assurance that everything is wired up properly. <\/span><\/p>\n

So our next step is to create the step definitions needed to execute this BDD Gherkin script.\u00a0<\/span>There are many ways to create the step definitions. In this blog, we will discuss two of them.<\/span><\/p>\n

Creating Step Definitions<\/h2>\n

Since we do not yet have a step definitions file, we are going to let Cucumber create it for us in our step_definitions directory. Put the cursor on the Given line in the highlighted text. You should see a lightbulb appear to the left of the Scenario. <\/span><\/p>\n

Click on it and select \u201cCreate Step Definition.\u201d You should get a pop-up box. Change the file_name to whatever you would like, but keep the \u201c_steps\u201d at the end.<\/span><\/p>\n

\"WebDriver\"<\/a><\/p>\n

Hit OK and your step definition file will be created with the step definition! Hit ENTER a couple of times and you end up with the following:<\/span><\/p>\n

\"WebDriver\"<\/a><\/p>\n

In a future blog, I will discuss what pending means. For now, just put a # in front of the word pending. This will turn the line into a comment line – and continue on to the next step. <\/span><\/p>\n

Now that we have a step definition file to put our steps in, we can try the second<\/span>\u00a0step creation technique: let Cucumber create them. <\/span><\/p>\n

You can accomplish this by running our .feature file. Right-click the .feature file and select the \u201cRun BlogTest.feature\u201d option. <\/span><\/p>\n

At the bottom of RubyMine you will see the Run pane appear (if it hasn\u2019t already). While most of your script either failed or was skipped, three were undefined with Cucumber giving us this output:<\/span><\/p>\n

\"WebDriver\"<\/a><\/p>\n

Copy and paste all four snippets into your step definition file (don\u2019t forget to remove the \u201cYou can implement\u201d lines). <\/span><\/p>\n

RubyMine tip: hit Ctrl+Alt+L to\u00a0align your text.<\/span><\/p>\n

\"Agile<\/a><\/p>\n

If everything was copy and pasted properly, your Gherkin script should no longer have highlighted text:<\/span><\/p>\n

\"Agile<\/a><\/p>\n

As we did before, put a # in front of each pending line to comment out each line. Run the .feature file again and you should get something similar to this:<\/span><\/p>\n

\"Agile<\/a><\/p>\n

Congratulations! Your framework does nothing, but it passes. And that is a HUGE first step because it means you now ready to add code and get to know WebDriver. <\/span><\/p>\n

If you are a traditional manual agile testing team member, don\u2019t worry about coding. Getting this far is quite an accomplishment. Adding WebDriver code to your Cucumber framework will seem easy by comparison.<\/span><\/p>\n

In our next installment of this series, learn\u00a0how to use parameters in your Gherkin Script.<\/em><\/h3>\n","protected":false},"excerpt":{"rendered":"

Read about Step Definitions in of our How-To-Guide on applying Cucumber to lead your agile testing team down the path to automation.<\/p>\n","protected":false},"author":63,"featured_media":16759,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_oasis_is_in_workflow":0,"_oasis_original":0,"_oasis_task_priority":"","_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","footnotes":""},"categories":[1],"tags":[16649],"coauthors":[15012],"acf":[],"publishpress_future_action":{"enabled":false,"date":"2024-07-21 22:42:20","action":"change-status","newStatus":"draft","terms":[],"taxonomy":"category"},"_links":{"self":[{"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/posts\/13527"}],"collection":[{"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/comments?post=13527"}],"version-history":[{"count":0,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/posts\/13527\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/media\/16759"}],"wp:attachment":[{"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/media?parent=13527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/categories?post=13527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/tags?post=13527"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/coauthors?post=13527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}