Sunday, January 7, 2018

How to write the Step Definitions for the Cucumber tests?

In the previous tutorial we learned about writing the scenarios and steps in the feature file. Also we seen that steps being highlighted in yellow color since they do not have step definitions. Now we will learn writing the step definitions.

I will be taking only one scenario for simplicity. You can follow same approach for remaining scenarios.

Step 1: Create a package say 'cucumberStepsDefinion' as shown below.

Copy the path of the 'cucumberStepsDefinion' package.

Step 2: Keep the cursor on the any step and press 'Alt+ENTER', you will get a pop up with two options 'Create Step Definition' and 'Create All Step Definitions'.

Step 3: Select 'Create Step Definition' (anyways 'Create All Step Definitions' is not working in the first attempt), then paste 'cucumberStepsDefinition' package file path in File location and enter 'StepDefinitions' class name. Click on 'OK' button.

You should see step definition being created in the newly created '' file as below

Step 4: For remaining steps place cursor and press 'Alt+ENTER', this time select 'Create steps definition' and IntelliJ will asks you to choose 'Create new file' or existing 'StepDefinitions' file. Select 'StepDefinitions'

Now you should see all the step definitions being added to the '' file as below

Step 5: Right Click on the 'gmailLoginFeature.feature' and Run 'Feature:gmailLoginFeature'. When you do this we get something like below in the console

Even though we defined the step definitions we are getting 'Undefined steps' in the console. The reason is, we have not mapped our steps from feature file with step definitions.

Step 6: To map them, click on the Edit Configuration in IntelliJ

Step 7: Then select 'Cucumber java' in the left pane, and in the right pane provide 'cucumberStepsDefinition' package name in the 'Glue' field, Features folder location in 'folder path'

Click 'Apply' and 'OK'.

Step 8: Now run the 'gmailLoginFeature.feature' gain,  this time you will see something like below (ignore the exception that doesn't matter) which means steps and step definitions are glued (mapped)

Step 9: Delete the existing or default content in the step definitions and write the respective actions that each step has to perform in their step definitions as below

We are not going to discuss selenium code here, you should be having basic idea selenium. This tutorial concentration is how to implement Cucumber in Selenium Automation.

We completed writing the step definitions as well.  I tried my best make it more understandable with all the screenshots. The next part is run the tests using Junit runner class. We will see that in the next part.

Thanks for reading. #seleniumbabu #HappyLearning


  1. Best and unique information from you on the concept of selenium automation testing. Keep updating more info on Selenium.
    selenium testing training in chennai | Best selenium training in chennai

    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

  2. I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.
    Best selenium training Institute in chennai

  3. Use your education as your most marketable asset. If you're an entry-level candidate with minimal professional experience, your education is your ticket. Coursework Writing Service


  4. Wonderful post!!Thank you for sharing this info with us.
    Keep updating I would like to know more updates on this topic
    Very useful content, I would like to suggest this blog to my friends.

    software testing selenium training

    Selenium Training in Chennai

  5. Thanks for providing the information . The articles in your blog helped me a lot for improving the knowledge on the subject. Also check my small collection on this at selenium Online Training Hyderabad blog

  6. Do not waste time winning money right now we have slot games Win an online casino.


  7. I found so many interesting stuff in your blog especially writing steps for the improvements of dissertation writing service
    . From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work

  8. I can only imagine how much research has gone into this. I like your writing skills as it makes one feel included in the journey. Thank you for the valuable notes.
    economics homework help

  9. Your work is very good and I appreciate you and hopping for some more informative posts. Thank you for sharing great information to us.
    my assigment

  10. I am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me. write essays for money

  11. Your post is very great.i read this post this is a very helpful. i will definitely go ahead and take advantage of this. You absolutely have wonderful stories.Cheers for sharing with us your blog. python training in noida

  12. Your post is very great.i read this post this is a very helpful. i will definitely go ahead and take advantage of this. You absolutely have wonderful stories.Cheers for sharing with us your blog. python training in noida

  13. Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
    digital marketing course in coimbatore

  14. Your post is very great.i read this post this is a very helpful. i will definitely go ahead and take advantage of this. You absolutely have wonderful stories.Cheers for sharing with us your blog
    autocad training in noida

  15. My Name is Abhay Kumar. I’m a Blogger living in India. I am a fan of technology, design, and writing. I’m also interested in programming and blog. I would like to share articles related to SEO, blogging tutorials, WordPress Tutorial, Make money online. You can read my blog.
    dot net training in gurgaon


Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...