[JVM] How can I create a cucmber datatable having an object in one of the datatable column ?

21 views
Skip to first unread message

Rinky Mangal

unread,
Apr 24, 2015, 5:57:41 AM4/24/15
to cu...@googlegroups.com
Hi All,

I have a feature file say:

         Given user adds following details:
             |user_name |User_details                                                                                             |
             |xyz_user    |details{firstName=firstname, middleName=middileName, lastName=lastname} |

I want to map it to say:

    @Given ("^user adds following details:$")
    public void createUser(final String List<Users> users) throws Throwable { }

Where,
Users is the pojo like:

class Users {
    private userName;
    private Details details;

   // Along with the setters and getter
}

Here Users is further having an object reference "Details".

How to create and handle such datatables having an object in one of its column?

I tried to create the DataTable with:
        DataTable.create(usersList);
But it create the datatable with one one property. Like:

             |user_name |User_details |
             |xyz_user    |firstname     |

But i want the complete object.

Is there any way to do this?

Regards,
~Rinky

Roberto Lo Giacco

unread,
Apr 26, 2015, 10:01:24 AM4/26/15
to cu...@googlegroups.com

Il giorno venerdì 24 aprile 2015 11:57:41 UTC+2, Rinky Mangal ha scritto:
Hi All,

I have a feature file say:

         Given user adds following details:
             |user_name |User_details                                                                                             |
             |xyz_user    |details{firstName=firstname, middleName=middileName, lastName=lastname} |


This is a bad feature description as it exposes too much about the implementation.

you should re formulate it into something like

Given user "user_name" adds following details:
             | firstName     | firstName      |
             | middleName | middileName |
             | lastName     | lastname}      |

 
I want to map it to say:

    @Given ("^user adds following details:$")
    public void createUser(final String List<Users> users) throws Throwable { }


Which you can map into 

    @Given ("^user \"(.*)\" adds following details:$")
    public void createUser(final String username, final Details details) throws Throwable { }

and then you can create the User instance with the appropriate data.
Reply all
Reply to author
Forward
0 new messages