How to perform data driven testing in cucumber using a xml file

1,441 views
Skip to first unread message

Abhijit Biradar

unread,
Jul 3, 2016, 3:00:38 AM7/3/16
to Cukes
Hi,

I am working on selenium cucumber where i want to perform data driven testing in cucumber using xml file. Means i want keep all test data for my all scripts in xml file & want to read that test data, execute feature file, step definitions using that.

I have done some work on that i have created a xmlParser class which read all test data from xml file but, not able to pass that test data to cucumber feature & to step definition file.

I have tried a lot but, haven't got any solution on that.could any one help me on this & suggest how can i pass that test data to feature file & step definition.

Regards,
Abhijit

Andrew Premdas

unread,
Jul 3, 2016, 3:21:59 AM7/3/16
to cu...@googlegroups.com
This is like saying

Hey I'm new to football. What I want to do is pick up the ball and run with it, because I don't like using my feet to kick the ball.

If you want to use data to drive tests then use a programming language test tool for example JUnit. Because 'tests' in JUnit are written in code, you can do whatever you want in terms of importing test data, executing particular tests, and making particular assertions.

A fundamental part of using Cucumber is writing scenarios in features files. That is writing, not driving with data files from any source, not programming, looping having conditional, or having large tables of complicated examples. The process of writing the scenario benefits the development of functionality by exploring how to succinctly and clearly describe 'WHAT' you are trying to do, whilst at the same time giving some context about 'WHY' you are doing this. This is not data, its considered information. There is no point at all in doing this if its not going to be written with great care, and read with great scrutiny. I repeat, there is no point in using Cucumber if you are not going to write scenarios with great care and read them with great scrutiny. Trying to generate scenarios from data files is a complete waste of time.

You have two clear choices:

1. Use a suitable tool for generating large amounts of tests driven by xml data

2. Change the way you think about 'testing' and development and perhaps use Cucumber to support this process.

Both are perfectly valid. I suspect what you want to follow  the first choice, so use your parser to pass data to JUnit/RSpec ...


All best

Andrew

--
------------------------
Andrew Premdas

George Dinwiddie

unread,
Jul 3, 2016, 5:29:24 AM7/3/16
to cu...@googlegroups.com
Abhijit,

On 7/3/16 3:21 AM, Andrew Premdas wrote:
>
>
> On 1 July 2016 at 13:36, Abhijit Biradar <biradar...@gmail.com
> <mailto:biradar...@gmail.com>> wrote:
>
> Hi,
>
> I am working on selenium cucumber where i want to perform data
> driven testing in cucumber using xml file. Means i want keep all
> test data for my all scripts in xml file & want to read that test
> data, execute feature file, step definitions using that.
>
> I have done some work on that i have created a xmlParser class which
> read all test data from xml file but, not able to pass that test
> data to cucumber feature & to step definition file.
>
> I have tried a lot but, haven't got any solution on that.could any
> one help me on this & suggest how can i pass that test data to
> feature file & step definition.
>
>
>
> This is like saying
>
> Hey I'm new to football. What I want to do is pick up the ball and run
> with it, because I don't like using my feet to kick the ball.

As an American, I understand picking up the football and running with
it. :-) So while his advice still holds, I'll offer another alternative.

>
> If you want to use data to drive tests then use a programming language
> test tool for example JUnit. Because 'tests' in JUnit are written in
> code, you can do whatever you want in terms of importing test data,
> executing particular tests, and making particular assertions.
>
> A fundamental part of using Cucumber is writing scenarios in features
> files. That is writing, not driving with data files from any source, not
> programming, looping having conditional, or having large tables of
> complicated examples. The process of writing the scenario benefits the
> development of functionality by exploring how to succinctly and clearly
> describe 'WHAT' you are trying to do, whilst at the same time giving
> some context about 'WHY' you are doing this. This is not data, its
> considered information. There is no point at all in doing this if its
> not going to be written with great care, and read with great scrutiny. I
> repeat, there is no point in using Cucumber if you are not going to
> write scenarios with great care and read them with great scrutiny.
> Trying to generate scenarios from data files is a complete waste of time.
>
> You have two clear choices:
>
> 1. Use a suitable tool for generating large amounts of tests driven by
> xml data
>
> 2. Change the way you think about 'testing' and development and perhaps
> use Cucumber to support this process.
>
> Both are perfectly valid. I suspect what you want to follow the first
> choice, so use your parser to pass data to JUnit/RSpec ...

Cucumber step definitions are also written in code, the same as
JUnit/RSpec tests. The step definitions can as easily access the data
parsed from your XML files.

I would suggest writing your Scenarios using _logical names_ for data
elements, e.g. "customer_mailing_address" rather than "234 Main Street,
Anytown, CO, 30303." Let your step definitions lookup the actual data
values using the logical name.

I suspect you'll find this a bit clumsier than standard Cucumber usage,
but there are times when the context makes it seem desirable. I started
down this path once (using XLS rather than XML) at a client where the
database contents were controlled by another group. Rather than being
able to set up the test data I needed, I was dependent on them
identifying the test data they had loaded. The data was to change over
time, but "customer_who_fits_XYZ_criteria" should not. The external data
definition file allowed that other group to specify exactly which
customer fit that criteria.

Good luck with it.

- George

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

Roberto Lo Giacco

unread,
Jul 4, 2016, 7:49:04 AM7/4/16
to Cukes
Sorry George, but I'm with Andrew on this: if it's not relevant to the specification than it should not end up in the feature file. I would understand decoupling the information (business driven) from the actual data (varying under certain conditions), but that to me sounds really different than having data driven scenarios.

It smells as the usual "use Cucumber as a testing framework"....

Abhijit Biradar

unread,
Jul 8, 2016, 3:10:29 PM7/8/16
to Cukes
Thanks all for your suggestion

First i will explore all suggested ways & try to understand which one satisfies my requirement.

Regards,
Abhijit
Reply all
Reply to author
Forward
0 new messages