Newbie here so hoping you can bear with me!

Although new to automation in my new job, I have done a fair bit of reading on it. But I find myself thrown in the deep end here and have the task of setting up a framework. I am also new to coding.

We have some retrospective automation to set up to allow us to go BDD for future delivery. I am writing some feature files for existing behavior and writing the automation tests on the UI with Selenium in Java.

I am writing my locators and various page objects to interact with my page into a page class so I'm using an OOP approach for the framework. Examples being a method to populate field A, a method to populate field B, a method to click submit. The field methods will allow a string to be passed in.

A lot of guides I read on cucumber talk about passing in a string value from the feature file into the step def and then into the page object method that interacts with the field.

Now what if I am not interested in that value to be passed in and in fact the field isn't even mentioned in the feature file? But I still need to populate this field just to get me through my scenario. My Feature File will actually just read "Complete registration form" but I'm not bothered about what values to complete it with for this particular scenario.

Do I just pass in any value to the page methods at the step def stage? Eg. hard code any value at step def level? I'm worried that this may be bad practice and that there is a better way.

  • hard code is almost always a bad practice, you are already familiar with BDD, have you heard of TDD?
    – Yu Zhang
    Commented Jan 30, 2018 at 5:40
  • If you don't want to use data from feature file, you can use somehow parametrized/hardcoded value. Put in .properties file. It will act like a constant but you can always override it.
    – Fenio
    Commented Jan 30, 2018 at 9:44
  • Thanks for the replies. Liking the sound of a properties file that I can call into for inputs that I'm not interested in.
    – Matt
    Commented Jan 31, 2018 at 23:36
  • You could also create an object that represent the data being entered into the form and give default values to the fields (overriding with actual values when you do care)
    – Marit
    Commented Feb 1, 2018 at 12:07
  • Do note though that this will lead to long and brittle tests; if the fields in the form change your test will break. Is there any way you could get to the intended state without having to fill the form in the UI?
    – Marit
    Commented Feb 1, 2018 at 12:08

2 Answers 2


Depending on which cucumber library you are using its possible to define your scenario with a data table.

https://cucumber.io/docs/reference explains it in detail

Here's an example

Scenario Outline: feeding a suckler cow Given the cow weighs <weight> kg
When we calculate the feeding requirements Then the energy should be <energy> MJ 
And the protein should be <protein> kg 

| weight | energy | protein | 
| 450.   | 26500  | 215.    |
| 500    | 29500  | 245.    |
| 575.   | 31500  | 255.    | 
| 600.   | 37000  | 305.    |

The scenario runs for each entry in the table and the values are substituted in for the tokens.

Make sure your step definitions have regexes than can cope with the variable data or they might not match.

It's perfectly acceptable to also have a scenario with hardcoded values call the same step, I would consider it efficient.


so your first scenario should look like this:

Given I am on the form
When I fill the form with standard information and submit it
Then the form is submitted and I see the success message

The steps will look like this:

@step: given I am on the form:

@Step: when I fill out form with standard info:

@step: then form is submitted and confirmation appears()

This allows you to write subsequent scenarios that are more detailed without writing more code, and if the form gets updated, you don't have to fuss with the original feature file.

for example, with this template, you can do:

    Given I am on the form
    When I fill the one field with specific variable "Bob"
    And finish the standard information and submit it
    Then the form is submitted and I see the success message


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.