1

I can't use returned value in the next steps. Exaple: I have a method:

public class learn_BDD {



    @Test
    @When("^ I have \"([^\"]*)\" dolars on acount$")
    public String checkAcount(String amount){

        String Value = Acount.checkValueOfAcount();

                return returnValue;
    }
    @Test
    @Then("^Check how much I spend$")
    public void howMuchISpend(String returnValue){


        String actualValue = Acount.actualAcountState();
        if (actualValue < returnValue) {
            System.out.println("You are spend money");
        }
    }

In this case I give than error:

***BDD is declared with 1 parameters. However, the gherkin step has 0 arguments [].***

If somebody can help me I will be grateful.

Justi1991
  • 11
  • 2

1 Answers1

0

The error you are seeing is due to a lack of a capture group in the regular expression provided to the Then annotation.

The howMuchISpend method has 1 argument so Cucumber expects 1 capture group, for example, @Then("^Check how much (.+) I spend$"). The string captured by (.+) is passed as the value of its argument.

@Test
@Then("^Check how much (.+) I spend$")
public void howMuchISpend(String returnValue){


    String actualValue = Acount.actualAcountState();
    if (actualValue < returnValue) {
        System.out.println("You are spend money");
    }
}

Regarding the other part of your question, each step definition is independent, the value returned by a test method is ignored. If you want to pass values from one step to another you have to use a class scoped variable.

BTW, making steps dependent should be avoided.

whbogado
  • 929
  • 5
  • 15