BDD: Embedded tables with serenity and jbehave

phury

I'm trying to create a BDD test with serenity (former thucydides) using the jbehave extension, this is my story (originating from the serenity jbehave examples)

Scenario: a scenario with embedded tables
Given that I sell the following fruit
| fruit  | price |
| apples | 5.00  |
| pears  | 6.00  |
And I sell the following vegetables
| vegetable | price |
| potatoe   | 4.00  |
| carrot    | 5.50  |
When I sell fruit
Then the total cost should be total
Examples:
| goods           | total |
| apples, carrot  | 11.50 |
| apples, pears   | 11.00 |
| potatoe, carrot | 9.50 |

The generated java code is the following:

@Given("that I sell the following fruit\r\n| fruit  | price |\r\n| apples | 5.00  |\r\n| pears  | 6.00  |")
public void givenThatISellTheFollowingFruitFruitPriceApples500Pears600() {
    // PENDING
}

@Given("I sell the following vegetables\r\n| vegetable | price |\r\n| potatoe   | 4.00  |\r\n| carrot    | 5.50  |")
public void givenISellTheFollowingVegetablesVegetablePricePotatoe400Carrot550() {
    // PENDING
}

@When("I sell fruit")
public void whenISellFruit() {
}

@Then("the total cost should be total")
public void thenTheTotalCostShouldBeTotal() {
    // PENDING
}

How do I retrieve the table arguments in my test ?

I tried the ExamplesTable parameters as per documentation on jbehave tabular parameters but that did not work.

Is there a way to make the given annotation more readable (by not adding the table parameters) ?

spcial

You can retrieve the ExampleTable parameter like this (and have more readable given annotations):

@Given("that I sell the following fruit $exampleTable")
public void thatISellTheFollowingFruit(ExamplesTable exampleTable) {
    System.out.println("MyTable: "+exampleTable.asString());
}

If it doesn't find the declared method and tells you that this step is pending, you could check if you have a whitespace in your story after the word fruit:

Given that I sell the following fruit 

How to access the several rows and columns in your tables is written in the jBehave documentation under http://jbehave.org/reference/stable/tabular-parameters.html

You could also think about creating only one table instead of three:

Scenario: a scenario with embedded tables
Given I sell <product1> 
And the price is <product1price>
And I sell <product2> 
And the price is <product2price>
When I sell something
Then the total cost should be <total>
Examples:
| product1 | product1price | product2 | product2price | total |
| apples   | 5.00          | carrot   | 6.50          | 11.50 |
| apples   | 5.00          | pears    | 6.00          | 11.00 |
| potatoe  | 4.00          | carrot   | 9.50          | 13.50

The java code would have to look like this to access the parameters:

@Given("I sell <product1>")
public void iSellProduct(@Named("product1") String product1) {
    //do something with product1
}

Does this help? If not, what exactly does not work when you try to read the exampleTable?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Serenity BDD report does not show stories with Examples (Embedded tables)

From Dev

Serenity BDD with JBehave loading duplicate requirements

From Dev

Serenity BDD reports naming

From Dev

Configure Default WebDriver Serenity Jbehave

From Dev

Timeout setup for Serenity BDD or Cucumber BDD framework?

From Dev

Spring Boot BDD Testing with serenity

From Dev

Serenity BDD fun features by groups

From Dev

Serenity BDD test cases are not running on Chrome browser

From Dev

Serenity BDD test cases are not running on Chrome browser

From Dev

Remember credentials with serenity BDD (using selenium)

From Dev

serenity-bdd with cucumber feature hooks

From Dev

How can I change serenity-bdd log settings

From Dev

Serenity BDD with jUnit how to inject steps into setup method?

From Dev

serenity bdd default url with spring boot random port number

From Dev

How to set up a configured embedder for use of meta filters (-skip) with Serenity, JBehave and Selenium

From Dev

Serenity- add values from a form into 2 tables

From Dev

Creating R tables with embedded graphics

From Dev

Create SYM Tables in SymmetricDS Embedded

From Dev

Removing mouseover event issue in case of embedded tables

From Dev

Serenity properties

From Dev

Is H2 database suitable as embedded database with large tables?

From Dev

JBehave - run a single scenario

From Dev

Is it possible to integrate Jbehave with testNG?

From Dev

JBehave story parameters sample

From Dev

Jbehave : GivenStories in the end of execution

From Dev

Eclipse Jbehave eclipse error

From Dev

Custom Story Reporters in Jbehave

From Dev

JBehave resources not found in reports

From Dev

BDD and microservices

Related Related

HotTag

Archive