DataProvider from multiple classes

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

DataProvider from multiple classes

Shekhar
What is efficient way to have DataProvider classes and how to access them in test class? One each for different data set?
1. Customer Search Data
2. Item Purchase Data
3. Credit Card Data

Should this be three different classes ? How to access these three classes under testNG test class?
-SK
Reply | Threaded
Open this post in threaded view
|

Re: DataProvider from multiple classes

softwaretestingforum
Administrator
I am not quite sure what you are trying to achieve. Do you want to access test data from three data providers in one test method? I think that would be not be possible.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: DataProvider from multiple classes

Shekhar
How to use multiple dataprovider for single class ?
Should all data be in dataset ? In my case
Search user (If present continue with sales(dataset1) else continue with (create and sale: dataset2) )
How should I get these two different set of dataset in single webdriver class.
-SK
Reply | Threaded
Open this post in threaded view
|

Re: DataProvider from multiple classes

softwaretestingforum
Administrator
Your data provider could return multiple objects and you test method could use them

@Dateprovider(name="testData")
public Object[][] dataProvider() {

// Construct your data objects
return new Object[][]{{dataset1, dataset2}};
}


@Test(dataProvider="testData") {
public void testMethod(DataSet dataset1, DataSet dataset2) {

// Use data set here, how ever you want.

}
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: DataProvider from multiple classes

Shekhar
So does it mean we can have only one class
in dataprovider package ?
-SK
Reply | Threaded
Open this post in threaded view
|

Re: DataProvider from multiple classes

softwaretestingforum
Administrator
Not quite sure what you are trying to ask, You could have as many classes in a package as you want
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: DataProvider from multiple classes

Shekhar
yes... like what we have in object package.
However in particular with dataprovider, as we can have only one class as dataprovider (e.g used in WebDriverTest).
Can we use one class is parent class as dataprovider and child classes to construct their own data sets?

-SK
Reply | Threaded
Open this post in threaded view
|

Re: DataProvider from multiple classes

softwaretestingforum
Administrator
Shekar, I guess I am missing some thing. You could have multiple classes in a package and these classes can have multiple data provider methods.
If you draw some psudo code it might be able to help.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: DataProvider from multiple classes

Shekhar
public class WebDriverTest extends SelTestCase {

        @Test(dataProvider = "cuData", dataProviderClass = CustomerSearchData.class)
        public void testCustomer(CustomerSearchData cuData, CustomerSearchData cuEnterData) {

                        <<using cudata and CuEnterData to drive test>>

               
        }
       
}

However in this cuData and cuEnterData both belongs to class CustomerSearchData.

what I am trying: both cuData and cuEnterData will be from two different classes.
Like cuData from CustomerSearchData.class and cuEnterData from NewCustomerData.class
However as I have only one dataProviderClass = CustomerSearchData.class, not sure how I can separate  these two data set in two different classes.

-SK
Reply | Threaded
Open this post in threaded view
|

Re: DataProvider from multiple classes

softwaretestingforum
Administrator
I don't think that's possible Shekhar, But you can always return different objects from data providers as I illustrated in my previous data set example.
~ seleniumtests.com