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
----------------------------------------------------------------------