Question

I want to generate a step that has a pyString inside I did as follow:
First in my .feature file I have these codes

Then I should see the following something:
    |label   |value|
    |test|12   |

And I define the step as bellow:

/**
     * @Then /^I should see the following something:$/
     */
    public function iShouldSeeTheFollowingAppStatistic(TableNode $table) {
        $hash = $table->getHash ();
        $steps=array();
        foreach ( $hash as $row ) {

            $then=new Then("I should see:\n\"\"\"\n \"label\" : \"".$row['label']."\"\n \"value\" : ".$row['value']."\n\"\"\"");
            $steps[]=$then;
        }
        return $steps;
    }

And for the $then variable I define another custom step like this:

/**
     * @Then /^I should see:$/
     */
    public function iShouldSee(PyStringNode $string)
    {
        echo $string;
    }

But sadly I still get undefined step error.

 Undefined step "I should see:
      """
       "label" : "test"
       "value" : 12
      """"

I think the problem is the pystring. How can I handle this situation? Thank you in advance.

Was it helpful?

Solution

You could use:

new Then("I should see:", new PyStringNode($string));

However, step chaining will be removed in Behat 3. This feature's going to be provided as an extension, but it's advised to use standard OO practices instead. In your case you could just do:

$this->iShouldSee(new PyStringNode($string));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top