Re: [testng-users] Merge Multiple DataProviders into Single one and then feed the merger DataProvider to Test

3,062 views
Skip to first unread message

Cédric Beust ♔

unread,
May 31, 2013, 1:12:15 AM5/31/13
to testng...@googlegroups.com
Make these regular methods then have your various data providers call these methods and combine them.


-- 
Cédric



On Thu, May 30, 2013 at 10:09 AM, Shaik <skaha...@gmail.com> wrote:

Hello All,

 

I have an requirement to merge the DataProviders and then feed to the Test

 

Steps :

 


 
@DataProvider
 public Object[][] getData1() {
   Object[][]a=TestUtil.getData(emp1xls, "TestCase_A3");
  return a;
 
 }
 

@DataProvider
 public Object[][] getData2() {
   Object[][]b=TestUtil.getData(emp1xls, "TestCase_A3");
  return b;
   
 }

@DataProvider

public Object[][] merge(){

a+b 

}

@Test(dataProvider="merge")

public void test(String Col1,String Col2.....){

}

 

if any one has idea , please share.

 

 

Thanks

Shaik

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Shaik

unread,
May 31, 2013, 3:51:07 AM5/31/13
to testng...@googlegroups.com, ced...@beust.com
 
Thanks Cedric for the reply..
 
I tried many ways to combine since two days , unable to combine the data as I require ..please if possible share the code to combine the Objects (Object[][])
 
Method1: Assume test data in Object[][] a returns
 
FirstName  LastName
Mark             Waugh
Steve             Thomson
 
Method2 : Assume test data in Object[][] b returns
Company   Email                                  Phone number
Apple        mwa...@apple.com           99998766
Microsoft    Tho...@mic.com           88765688
 
 
Expected Data (Combined Data) should be
Mark             Waugh       Apple        mwa...@apple.com           99998766
Steve             Thomson  Microsoft    Tho...@mic.com           88765688
 
 
Thanks
Shaik

Mark Derricutt

unread,
May 31, 2013, 7:43:07 AM5/31/13
to testng...@googlegroups.com, ced...@beust.com

Hey - looks like this what my Cartesian Data Provider did:


http://www.theoryinpractice.net/post/29190379586/cartesian-data-providers


I never did get around to seeing if I could rip out the Guava dependency to submit it upstream did I?


Shaik - does this help you?




--
Mark Derricutt
Sent with Airmail

Shaik

unread,
May 31, 2013, 8:34:32 AM5/31/13
to testng...@googlegroups.com, ced...@beust.com
Mark,
 
cartesian-data-providers does not help my requirement because it is iterating with each column combination . see the below result comparision.
 
 
 
cerstain-dataprovider with one

providerCounts (iterating once)                             Expected Result (which am looking for)

Peter - 53 - Blue - 0                                                 Peter - 53 - Red- 0                                  

Mary - 16 - Blue - 0                                                  Mary - 16 - Blue 

Paul - 25 - Blue - 0                                                   Paul - 25 - Green

Peter - 53 - Green - 0                                               Mary - 16 - Blue

Mary - 16 - Green - 0

Paul - 25 - Green - 0

Peter - 53 - Red - 0

Mary - 16 - Red - 0

Paul - 25 - Red - 0

 

Thanks

Shaik

Mark Derricutt

unread,
May 31, 2013, 2:50:59 PM5/31/13
to testng...@googlegroups.com

Ah, close - but you could probably adopt the code to get what you want.  From what I can see, you're basically wanting a simple "zip" operation like you find in a lot of functional programming languages:


1) for each next Object[] in EACH request dataset

2) construct a new Object[], combing the two above

3) add that to a new collection

4) use it :) 


--
Mark Derricutt
Sent with Airmail

Aha Med

unread,
May 31, 2013, 4:00:57 PM5/31/13
to testng...@googlegroups.com
couldn't get :-)
 
if possible can you share code snippet.. struggling since three days..
 
Appreciate your Help ..Mark
 
 
Thanks
Shaik


--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/lpuEaNcpY4A/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to testng-users...@googlegroups.com.

Aha Med

unread,
Jun 1, 2013, 2:37:09 PM6/1/13
to testng...@googlegroups.com
Thank You  Mark and Cedric for the valuable inputs..finally i got ..


Shaik

Reinier Post

unread,
Jun 4, 2013, 6:08:47 PM6/4/13
to testng...@googlegroups.com
On Fri May 31 23:43:07 2013, ma...@talios.com (Mark Derricutt) wrote:
> Hey - looks like this what my Cartesian Data Provider did:
>
> http://www.theoryinpractice.net/post/29190379586/cartesian-data-providers

Nice. I wrote my own, a class called DataProviderExtender.
The code that uses it looks like this (with [...] parts cut out):

@DataProvider
Iterator<Object[]> a() {
[...]
return Iterators.forArray(new Object[][] {{ [...] }};
}

@DataProvider
Iterator<Object[]> b() {
[...]
return [...];
}

@DataProvider
Iterator<Object[]> c() {
return new DataProviderExtender<String>().combined(
a(), b());
}

@DataProvider
Iterator<Object[]> d() {
[...]
return [...];
}

@DataProvider
Iterator<Object[]> e() {
return new DataProviderExtender<String>().combined(
c(), d());
}

DataProviderExtender.java:

package [...];

import java.util.Iterator;

import org.testng.internal.collections.Pair;

public class DataProviderExtender<T> {
public Iterator<Object[]> combined(final Iterator<Object[]> dp,
final Iterable<T> xtra) {
return new Iterator<Object[]>() {

private final Iterable<Object[]> sites_and_browsers = new Iterable<Object[]>() {
@Override
public Iterator<Object[]> iterator() {
// TODO Auto-generated method stub
return dp;
}
};

private final Iterable<Pair<Object[], T>> product = new CartesianProduct<Object[], T>(
sites_and_browsers, xtra);
private final Iterator<Pair<Object[], T>> pairs = product
.iterator();

@Override
public boolean hasNext() {
return pairs.hasNext();
}

@Override
public Object[] next() {
Pair<Object[], T> p = pairs.next();
return new Object[] { p.first()[0], p.first()[1],
p.second() };
}

@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
}

It's not pretty, but it works.

Now if I could get right-clicking on the tests that use these
(to rerun them with the same parameters) to work,
I'd be a happy man.

--
Reinier Post

fred jnou

unread,
Nov 4, 2013, 10:18:31 AM11/4/13
to testng...@googlegroups.com, ced...@beust.com
Hi,

For those of you who need a tool for merging data providers and feeding a test with the merged data, you can have a look to the following post:
http://globalknowledgedb.blogspot.com/2013/10/testng-custom-data-provider.html

Fred


On Thursday, May 30, 2013 10:12:15 PM UTC-7, Cédric Beust ♔ wrote:

fred jnou

unread,
Nov 4, 2013, 11:17:50 AM11/4/13
to testng...@googlegroups.com, ced...@beust.com
Hi,

An example of merger data provider can be found here:
http://globalknowledgedb.blogspot.fr/2013/10/testng-custom-data-provider.html

Thanks,

Fred





On Thursday, May 30, 2013 10:12:15 PM UTC-7, Cédric Beust ♔ wrote:

Vishakh Rathore

unread,
Jan 29, 2014, 1:54:45 AM1/29/14
to testng...@googlegroups.com, ced...@beust.com
Hi Cedric,
 I need to supply a Array's of Array of data into a testNG TestCase but I can only use a single Variable to pass data into it using data provider.
All the fields would be coming up one by one.
Is there any way to pass a array of data into the data provider for all these sets.
Reply all
Reply to author
Forward
0 new messages