Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

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

Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

nikhil.shah
Hello,

In below example, dataProvider and dataProviderClass are same for every @Test method.

I have multiple class were dataProvider and dataProviderClass are same. Can we set dataProvider and dataProviderClass in XML testng or Suite level outside?

@Test(priority = 1, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test1(LinkedHashMap<String, String> data) {

}

@Test(priority = 2, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test2(LinkedHashMap<String, String> data) {

}

@Test(priority =3, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test3(LinkedHashMap<String, String> data) {

}

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

⇜Krishnan Mahadevan⇝

Why not set them via a listener implementation of org.testng.IAnnotationTransformer2 and then plug in this listener using <listeners> tag or an SPI (Service Loader implementation)


On Tue, Nov 21, 2017, 11:07 <[hidden email]> wrote:
Hello,

In below example, dataProvider and dataProviderClass are same for every @Test method.

I have multiple class were dataProvider and dataProviderClass are same. Can we set dataProvider and dataProviderClass in XML testng or Suite level outside?

@Test(priority = 1, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test1(LinkedHashMap<String, String> data) {

}

@Test(priority = 2, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test2(LinkedHashMap<String, String> data) {

}

@Test(priority =3, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test3(LinkedHashMap<String, String> data) {

}

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

nikhil.shah
Can you please give me an example.

Thanks in advance.


On Tuesday, November 21, 2017 at 11:11:55 AM UTC+5:30, Krishnan Mahadevan wrote:

Why not set them via a listener implementation of org.testng.IAnnotationTransformer2 and then plug in this listener using <listeners> tag or an SPI (Service Loader implementation)


On Tue, Nov 21, 2017, 11:07 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="IYTfXaofAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">nikhi...@...> wrote:
Hello,

In below example, dataProvider and dataProviderClass are same for every @Test method.

I have multiple class were dataProvider and dataProviderClass are same. Can we set dataProvider and dataProviderClass in XML testng or Suite level outside?

@Test(priority = 1, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test1(LinkedHashMap<String, String> data) {

}

@Test(priority = 2, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test2(LinkedHashMap<String, String> data) {

}

@Test(priority =3, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test3(LinkedHashMap<String, String> data) {

}

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="IYTfXaofAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="IYTfXaofAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

⇜Krishnan Mahadevan⇝

public static class DataProviderAdder implements IAnnotationTransformer {

 

    @Override

    public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

        if (annotation != null) {

            annotation.setDataProvider("someDataProvider");

            annotation.setDataProviderClass(SampleClass.class);

        }

    }

}

 

This should get you started.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

From: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>
Date: Tuesday, November 21, 2017 at 2:47 PM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

 

Can you please give me an example.

 

Thanks in advance.



On Tuesday, November 21, 2017 at 11:11:55 AM UTC+5:30, Krishnan Mahadevan wrote:

Why not set them via a listener implementation of org.testng.IAnnotationTransformer2 and then plug in this listener using <listeners> tag or an SPI (Service Loader implementation)

 

On Tue, Nov 21, 2017, 11:07 <<a href="javascript:" target="_blank">nikhi...@...> wrote:

Hello,

 

In below example, dataProvider and dataProviderClass are same for every @Test method.

 

I have multiple class were dataProvider and dataProviderClass are same. Can we set dataProvider and dataProviderClass in XML testng or Suite level outside?

 

@Test(priority = 1, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test1(LinkedHashMap<String, String> data) {
 
}
 
@Test(priority = 2, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test2(LinkedHashMap<String, String> data) {
 
}
 
@Test(priority =3, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test3(LinkedHashMap<String, String> data) {
 
}

--
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 <a href="javascript:" target="_blank">testng-users...@....
To post to this group, send email to <a href="javascript:" target="_blank">testng...@....
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

nikhil.shah
Thank you Krishnan.

Above code work for me in 6.8 version of testng but fails in 6.11 version.

Below code used for generating XML FIle:

static List<Class> listenerClasses = new ArrayList<Class>();

public static List<XmlSuite> genarateXmlFile() {
XmlSuite suite = new XmlSuite();
suite.setName(Constant.BaseTestHelperConstant.SUITENAME);

XmlTest test = new XmlTest(suite);

test.setName(Constant.BaseTestHelperConstant.TESTCASENAME);

test.setGroupByInstances(true);

List<XmlClass> classes = new ArrayList<XmlClass>();
for (int i = 0; i < Common.BaseTestHelperClass.sheetsName.size(); i++)
classes.add(new XmlClass(Constant.BaseTestHelperConstant.TESTSUITEPATH + Common.BaseTestHelperClass.sheetsName.get(i)));

listenerClasses.add(main.java.com.agrostar.utility.DataProviderAdder.class);

test.setXmlClasses(classes);

List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);

System.out.println("Printing TestNG Suite Xml");
System.out.println(suite.toXml());

return suites;

}

public static void runXmlSuite(List<XmlSuite> suites) {
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.setListenerClasses(listenerClasses);
tng.run();
}

Exception in 6.11 testng:  incompatible types: java.util.List<java.lang.Class> cannot be converted to java.util.List<java.lang.Class<? extends org.testng.ITestNGListener>>

Please let me know if you have any workaround.

Thanks for your help.

On Thursday, November 23, 2017 at 9:46:42 AM UTC+5:30, Krishnan Mahadevan wrote:

public static class DataProviderAdder implements IAnnotationTransformer {

 

    @Override

    public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

        if (annotation != null) {

            annotation.setDataProvider("someDataProvider");

            annotation.setDataProviderClass(SampleClass.class);

        }

    }

}

 

This should get you started.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

 

From: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="yRX40y9GAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...> on behalf of <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="yRX40y9GAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">nikhi...@...>
Reply-To: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="yRX40y9GAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Date: Tuesday, November 21, 2017 at 2:47 PM
To: testng-users <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="yRX40y9GAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Subject: Re: [testng-users] Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

 

Can you please give me an example.

 

Thanks in advance.



On Tuesday, November 21, 2017 at 11:11:55 AM UTC+5:30, Krishnan Mahadevan wrote:

Why not set them via a listener implementation of org.testng.IAnnotationTransformer2 and then plug in this listener using <listeners> tag or an SPI (Service Loader implementation)

 

On Tue, Nov 21, 2017, 11:07 <[hidden email]> wrote:

Hello,

 

In below example, dataProvider and dataProviderClass are same for every @Test method.

 

I have multiple class were dataProvider and dataProviderClass are same. Can we set dataProvider and dataProviderClass in XML testng or Suite level outside?

 

@Test(priority = 1, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test1(LinkedHashMap<String, String> data) {
 
}
 
@Test(priority = 2, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test2(LinkedHashMap<String, String> data) {
 
}
 
@Test(priority =3, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test3(LinkedHashMap<String, String> data) {
 
}

--
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 [hidden email].
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="yRX40y9GAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="yRX40y9GAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

⇜Krishnan Mahadevan⇝

Either use tng.addListener() or
Change listenerClasses definition to :

List<Class<? extends ITestNGListener>> = new Array list<>()


On Thu, Nov 23, 2017, 13:35 <[hidden email]> wrote:
Thank you Krishnan.

Above code work for me in 6.8 version of testng but fails in 6.11 version.

Below code used for generating XML FIle:

static List<Class> listenerClasses = new ArrayList<Class>();

public static List<XmlSuite> genarateXmlFile() {
XmlSuite suite = new XmlSuite();
suite.setName(Constant.BaseTestHelperConstant.SUITENAME);

XmlTest test = new XmlTest(suite);

test.setName(Constant.BaseTestHelperConstant.TESTCASENAME);

test.setGroupByInstances(true);

List<XmlClass> classes = new ArrayList<XmlClass>();
for (int i = 0; i < Common.BaseTestHelperClass.sheetsName.size(); i++)
classes.add(new XmlClass(Constant.BaseTestHelperConstant.TESTSUITEPATH + Common.BaseTestHelperClass.sheetsName.get(i)));

listenerClasses.add(main.java.com.agrostar.utility.DataProviderAdder.class);

test.setXmlClasses(classes);

List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);

System.out.println("Printing TestNG Suite Xml");
System.out.println(suite.toXml());

return suites;

}

public static void runXmlSuite(List<XmlSuite> suites) {
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.setListenerClasses(listenerClasses);
tng.run();
}

Exception in 6.11 testng:  incompatible types: java.util.List<java.lang.Class> cannot be converted to java.util.List<java.lang.Class<? extends org.testng.ITestNGListener>>

Please let me know if you have any workaround.

Thanks for your help.

On Thursday, November 23, 2017 at 9:46:42 AM UTC+5:30, Krishnan Mahadevan wrote:

public static class DataProviderAdder implements IAnnotationTransformer {

 

    @Override

    public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

        if (annotation != null) {

            annotation.setDataProvider("someDataProvider");

            annotation.setDataProviderClass(SampleClass.class);

        }

    }

}

 

This should get you started.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

From: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>


Date: Tuesday, November 21, 2017 at 2:47 PM

To: testng-users <[hidden email]>


Subject: Re: [testng-users] Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

 

Can you please give me an example.

 

Thanks in advance.



On Tuesday, November 21, 2017 at 11:11:55 AM UTC+5:30, Krishnan Mahadevan wrote:

Why not set them via a listener implementation of org.testng.IAnnotationTransformer2 and then plug in this listener using <listeners> tag or an SPI (Service Loader implementation)

 

On Tue, Nov 21, 2017, 11:07 <[hidden email]> wrote:

Hello,

 

In below example, dataProvider and dataProviderClass are same for every @Test method.

 

I have multiple class were dataProvider and dataProviderClass are same. Can we set dataProvider and dataProviderClass in XML testng or Suite level outside?

 

@Test(priority = 1, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test1(LinkedHashMap<String, String> data) {
 
}
 
@Test(priority = 2, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test2(LinkedHashMap<String, String> data) {
 
}
 
@Test(priority =3, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test3(LinkedHashMap<String, String> data) {
 
}

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

nikhil.shah
Thank you Krishnan.

On Thursday, November 23, 2017 at 1:46:20 PM UTC+5:30, Krishnan Mahadevan wrote:

Either use tng.addListener() or
Change listenerClasses definition to :

List<Class<? extends ITestNGListener>> = new Array list<>()


On Thu, Nov 23, 2017, 13:35 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="MsoVTUNTAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">nikhi...@...> wrote:
Thank you Krishnan.

Above code work for me in 6.8 version of testng but fails in 6.11 version.

Below code used for generating XML FIle:

static List<Class> listenerClasses = new ArrayList<Class>();

public static List<XmlSuite> genarateXmlFile() {
XmlSuite suite = new XmlSuite();
suite.setName(Constant.BaseTestHelperConstant.SUITENAME);

XmlTest test = new XmlTest(suite);

test.setName(Constant.BaseTestHelperConstant.TESTCASENAME);

test.setGroupByInstances(true);

List<XmlClass> classes = new ArrayList<XmlClass>();
for (int i = 0; i < Common.BaseTestHelperClass.sheetsName.size(); i++)
classes.add(new XmlClass(Constant.BaseTestHelperConstant.TESTSUITEPATH + Common.BaseTestHelperClass.sheetsName.get(i)));

listenerClasses.add(main.java.com.agrostar.utility.DataProviderAdder.class);

test.setXmlClasses(classes);

List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);

System.out.println("Printing TestNG Suite Xml");
System.out.println(suite.toXml());

return suites;

}

public static void runXmlSuite(List<XmlSuite> suites) {
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.setListenerClasses(listenerClasses);
tng.run();
}

Exception in 6.11 testng:  incompatible types: java.util.List<java.lang.Class> cannot be converted to java.util.List<java.lang.Class<? extends org.testng.ITestNGListener>>

Please let me know if you have any workaround.

Thanks for your help.

On Thursday, November 23, 2017 at 9:46:42 AM UTC+5:30, Krishnan Mahadevan wrote:

public static class DataProviderAdder implements IAnnotationTransformer {

 

    @Override

    public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

        if (annotation != null) {

            annotation.setDataProvider("someDataProvider");

            annotation.setDataProviderClass(SampleClass.class);

        }

    }

}

 

This should get you started.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

 

From: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>


Date: Tuesday, November 21, 2017 at 2:47 PM

To: testng-users <[hidden email]>


Subject: Re: [testng-users] Can we set dataProvider and dataProviderClass in XML testng or Suite level outside.

 

Can you please give me an example.

 

Thanks in advance.



On Tuesday, November 21, 2017 at 11:11:55 AM UTC+5:30, Krishnan Mahadevan wrote:

Why not set them via a listener implementation of org.testng.IAnnotationTransformer2 and then plug in this listener using <listeners> tag or an SPI (Service Loader implementation)

 

On Tue, Nov 21, 2017, 11:07 <[hidden email]> wrote:

Hello,

 

In below example, dataProvider and dataProviderClass are same for every @Test method.

 

I have multiple class were dataProvider and dataProviderClass are same. Can we set dataProvider and dataProviderClass in XML testng or Suite level outside?

 

@Test(priority = 1, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test1(LinkedHashMap<String, String> data) {
 
}
 
@Test(priority = 2, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test2(LinkedHashMap<String, String> data) {
 
}
 
@Test(priority =3, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test3(LinkedHashMap<String, String> data) {
 
}

--
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 [hidden email].
Visit this group at <a href="https://groups.google.com/group/testng-users" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

--
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 [hidden email].
Visit this group at <a href="https://groups.google.com/group/testng-users" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="MsoVTUNTAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="MsoVTUNTAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.