0

i want to use dataprovider to pass data directly into step definition without passing from feature file, as i want to pass null values as well. here is what i am doing.

Scenario: User should get empty field highlight, when that fields is empty and clicked submit. When Submit is clicked after providing values in nethier or either of Reg Id or PC

@Test(dataProvider = "getData")
    @When("^Submit is clicked after providing values in nethier or either of Reg Id or PC$")
    public void submit_is_clicked_after_providing_values_in_nethier_or_either_of_reg_id_something_or_pc_something(
            String regvalue, String pcvalue) throws Throwable {
//code
}

@DataProvider

    public Object[][] getData() {
        Object[][] data = new Object[3][2]; // 3 is number of combinations and 2 is number of values
        // 1st set
        data[0][0] = "Username1";
        data[0][1] = null;
        // 2nd set
        data[1][0] = null;
        data[1][1] = "Password1";
        // 3nd set
        data[2][0] = null;
        data[2][1] = null;
        return data;
}

Error i am getting is

Step [^Submit is clicked after providing values in nethier or either of Reg Id or PC$] is defined with 2 parameters at 'com.commcard.stepdefinition.StepDef.submit_is_clicked_after_providing_values_in_nethier_or_either_of_reg_id_something_or_pc_something(String,String) in file:/D:/Eclipse-Workspace/CucumberProject.CitiCommCard/target/test-classes/'. However, the gherkin step has 0 arguments.

James Z
  • 12,209
  • 10
  • 24
  • 44
Muthu Akilan
  • 5
  • 1
  • 5
  • Remove the parameters on your step definition method. The number of arguments on your feature file should always be equal to your step definition method – Millie Anne Volante Nov 16 '20 at 04:09
  • Okay, but any idea how else i can declare a variable in step definition and fetch the data from data provider – Muthu Akilan Nov 16 '20 at 05:55
  • If you want you can directly call the method getData() . But what bothers me is the way you write your steps. If I were you, separate the step definition for entering inputs and clicking submit. – Millie Anne Volante Nov 16 '20 at 06:26

1 Answers1

1

You can use a yml file as a data-lookup. For JSON style testing I would advocate this. As you can use a regular fixture or build it up mid-process.

So you could have something like this.

Given I have a valid request to create a user
But the username is invalid
Given I have a valid request to create a user
But the username is too short
# yaml file

user:
  create:
    issues:
      username:
        invalid: "Can't Use W3!rd char$"
        too_short: "usrnm"

Then your steps just use whatever programming language you use and convert the yml into a data lookup (Hash/List), and alter the keys.

Luke Hill
  • 460
  • 2
  • 10