@Test level parameters in testng.xml

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

@Test level parameters in testng.xml

akshay.maldhure
Hello,

I'm wondering if there's a way to provide @Test level parameters through testng.xml file.

e.g. I know we could do something like this, in case of which the supplied parameters are applied to every @Test.

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
   
<parameter name="someParam2" value="someValue2" />

     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

I'm wondering if we could do something like this:

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
   
<parameter name="someParam2" value="someValue2" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

The reason I'm looking for something like this is that each of my @Test tests in my test class need different set of parameters/values.

Thanks,
Akshay

--
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
|  
Report Content as Inappropriate

Re: @Test level parameters in testng.xml

Krishnan Mahadevan

Akshay,

 

It should work. Here’s a sample

 

package com.rationaleemotions.googleforums.params;

 

import org.testng.Assert;

import org.testng.Reporter;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

 

public class TestClass {

    @Test

    @Parameters({"name", "age"})

    public void testMethod(String name, int age) {

        Reporter.log(name + " is " + age + " years old", true);

        Assert.assertNotNull(name);

        Assert.assertTrue(age > 0);

    }

}

 

Suite file :

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="1265_Suite" parallel="false" verbose="2">

    <parameter name="name" value="Jack"/>

    <test name="partOne" parallel="false" preserve-order="true">

        <parameter name="age" value="25"/>

        <classes>

            <class name="com.rationaleemotions.googleforums.params.TestClass"/>

        </classes>

    </test>

    <test name="partTwo" parallel="false" preserve-order="true">

        <parameter name="age" value="30"/>

        <parameter name="name" value="Jill"/>

        <classes>

            <class name="com.rationaleemotions.googleforums.params.TestClass"/>

        </classes>

    </test>

</suite>

 

 

Output

 

...

... TestNG 6.11 by Cédric Beust ([hidden email])

...

Jack is 25 years old

Jill is 30 years old

 

===============================================

1265_Suite

Total tests run: 2, Failures: 0, Skips: 0

===============================================

 

 

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: Monday, June 12, 2017 at 5:40 PM
To: testng-users <[hidden email]>
Subject: [testng-users] @Test level parameters in testng.xml

 

Hello,

 

I'm wondering if there's a way to provide @Test level parameters through testng.xml file.

 

e.g. I know we could do something like this, in case of which the supplied parameters are applied to every @Test.

 

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
   
<parameter name="someParam2" value="someValue2" />

     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

 

I'm wondering if we could do something like this:

 

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
   
<parameter name="someParam2" value="someValue2" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

 

The reason I'm looking for something like this is that each of my @Test tests in my test class need different set of parameters/values.

 

Thanks,

Akshay

--
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
|  
Report Content as Inappropriate

Re: @Test level parameters in testng.xml

akshay.maldhure
Hi Krishnan,

I think I did not explain the problem correctly. I meant, I'm looking for a way to have <method> level parameters.

e.g. Imagine a Java class having three @Test methods and each of them takes different sets of parameters altogether. I would like to know if there's some way for me to designate respective parameters at <method> level in my testng.xml file.

On Monday, June 12, 2017 at 8:31:14 PM UTC+5:30, Krishnan wrote:

Akshay,

 

It should work. Here’s a sample

 

package com.rationaleemotions.googleforums.params;

 

import org.testng.Assert;

import org.testng.Reporter;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

 

public class TestClass {

    @Test

    @Parameters({"name", "age"})

    public void testMethod(String name, int age) {

        Reporter.log(name + " is " + age + " years old", true);

        Assert.assertNotNull(name);

        Assert.assertTrue(age > 0);

    }

}

 

Suite file :

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">

<suite name="1265_Suite" parallel="false" verbose="2">

    <parameter name="name" value="Jack"/>

    <test name="partOne" parallel="false" preserve-order="true">

        <parameter name="age" value="25"/>

        <classes>

            <class name="com.rationaleemotions.googleforums.params.TestClass"/>

        </classes>

    </test>

    <test name="partTwo" parallel="false" preserve-order="true">

        <parameter name="age" value="30"/>

        <parameter name="name" value="Jill"/>

        <classes>

            <class name="com.rationaleemotions.googleforums.params.TestClass"/>

        </classes>

    </test>

</suite>

 

 

Output

 

...

... TestNG 6.11 by Cédric Beust (<a href="javascript:" target="_blank" gdf-obfuscated-mailto="OPTxX0riBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ced...@...)

...

Jack is 25 years old

Jill is 30 years old

 

===============================================

1265_Suite

Total tests run: 2, Failures: 0, Skips: 0

===============================================

 

 

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="OPTxX0riBgAJ" 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="OPTxX0riBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">akshay....@...>
Reply-To: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="OPTxX0riBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Date: Monday, June 12, 2017 at 5:40 PM
To: testng-users <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="OPTxX0riBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Subject: [testng-users] @Test level parameters in testng.xml

 

Hello,

 

I'm wondering if there's a way to provide @Test level parameters through testng.xml file.

 

e.g. I know we could do something like this, in case of which the supplied parameters are applied to every @Test.

 

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
   
<parameter name="someParam2" value="someValue2" />

     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

 

I'm wondering if we could do something like this:

 

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
   
<parameter name="someParam2" value="someValue2" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

 

The reason I'm looking for something like this is that each of my @Test tests in my test class need different set of parameters/values.

 

Thanks,

Akshay

--
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="OPTxX0riBgAJ" 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="OPTxX0riBgAJ" 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
|  
Report Content as Inappropriate

Re: @Test level parameters in testng.xml

Krishnan Mahadevan

Akshay,

 

Thanks for clarifying your usecase. No AFAIK, I don’t think you can pass in <parameters> to <method> via a TestNG suite xml file.

 

That said and done, you can very well achieve that using a @DataProvider annotation. Compared to passing parameters via <parameters> tag, it’s a lot more flexible, doesn’t involve an elaborately built suite xml file and gives you the luxury of making your parameters more dynamic. Wouldn’t that work for you ?

 

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, June 13, 2017 at 9:51 AM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] @Test level parameters in testng.xml

 

Hi Krishnan,

 

I think I did not explain the problem correctly. I meant, I'm looking for a way to have <method> level parameters.

 

e.g. Imagine a Java class having three @Test methods and each of them takes different sets of parameters altogether. I would like to know if there's some way for me to designate respective parameters at <method> level in my testng.xml file.

On Monday, June 12, 2017 at 8:31:14 PM UTC+5:30, Krishnan wrote:

Akshay,

 

It should work. Here’s a sample

 

package com.rationaleemotions.googleforums.params;

 

import org.testng.Assert;

import org.testng.Reporter;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

 

public class TestClass {

    @Test

    @Parameters({"name", "age"})

    public void testMethod(String name, int age) {

        Reporter.log(name + " is " + age + " years old", true);

        Assert.assertNotNull(name);

        Assert.assertTrue(age > 0);

    }

}

 

Suite file :

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="1265_Suite" parallel="false" verbose="2">

    <parameter name="name" value="Jack"/>

    <test name="partOne" parallel="false" preserve-order="true">

        <parameter name="age" value="25"/>

        <classes>

            <class name="com.rationaleemotions.googleforums.params.TestClass"/>

        </classes>

    </test>

    <test name="partTwo" parallel="false" preserve-order="true">

        <parameter name="age" value="30"/>

        <parameter name="name" value="Jill"/>

        <classes>

            <class name="com.rationaleemotions.googleforums.params.TestClass"/>

        </classes>

    </test>

</suite>

 

 

Output

 

...

... TestNG 6.11 by Cédric Beust (<a href="javascript:" target="_blank">ced...@...)

...

Jack is 25 years old

Jill is 30 years old

 

===============================================

1265_Suite

Total tests run: 2, Failures: 0, Skips: 0

===============================================

 

 

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: <<a href="javascript:" target="_blank">testng...@...> on behalf of <<a href="javascript:" target="_blank">akshay....@...>
Reply-To: <<a href="javascript:" target="_blank">testng...@...>
Date: Monday, June 12, 2017 at 5:40 PM
To: testng-users <<a href="javascript:" target="_blank">testng...@...>
Subject: [testng-users] @Test level parameters in testng.xml

 

Hello,

 

I'm wondering if there's a way to provide @Test level parameters through testng.xml file.

 

e.g. I know we could do something like this, in case of which the supplied parameters are applied to every @Test.

 

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
   
<parameter name="someParam2" value="someValue2" />

     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

 

I'm wondering if we could do something like this:

 

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
   
<parameter name="someParam2" value="someValue2" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

 

The reason I'm looking for something like this is that each of my @Test tests in my test class need different set of parameters/values.

 

Thanks,

Akshay

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

--
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
|  
Report Content as Inappropriate

Re: @Test level parameters in testng.xml

akshay.maldhure
It seems I can do that. Please check this link (comment by drapostolos), and it very well works for me. Please check the code sample below.

Test class:

package temp;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Temp {

 
@Test()
 
@Parameters ({"param","methodSpecificParam"})
 
public void test(String key1, String key2) {
 
System.out.println(key1+" "+key2);
 
}
}


Suite file:
   <test name="Test1">
   
<parameter name="param" value="globalValue" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<parameter name="methodSpecificParam"  value="methodSpecificValue"/>
               
<parameter name="param"  value="overridenValue"/>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>


Output: 
overridenValue methodSpecificValue

Hope this helps someone in future.

Regarding @DataProvider, incorporating that would need me to make a lot of code changes in order to the test flow and parameters configurable, and I do not really need a complex structure for the same.

On Tuesday, June 13, 2017 at 9:54:23 AM UTC+5:30, Krishnan wrote:

Akshay,

 

Thanks for clarifying your usecase. No AFAIK, I don’t think you can pass in <parameters> to <method> via a TestNG suite xml file.

 

That said and done, you can very well achieve that using a @DataProvider annotation. Compared to passing parameters via <parameters> tag, it’s a lot more flexible, doesn’t involve an elaborately built suite xml file and gives you the luxury of making your parameters more dynamic. Wouldn’t that work for you ?

 

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="80nPOh4OBwAJ" 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="80nPOh4OBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">akshay....@...>
Reply-To: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="80nPOh4OBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Date: Tuesday, June 13, 2017 at 9:51 AM
To: testng-users <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="80nPOh4OBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@...>
Subject: Re: [testng-users] @Test level parameters in testng.xml

 

Hi Krishnan,

 

I think I did not explain the problem correctly. I meant, I'm looking for a way to have <method> level parameters.

 

e.g. Imagine a Java class having three @Test methods and each of them takes different sets of parameters altogether. I would like to know if there's some way for me to designate respective parameters at <method> level in my testng.xml file.

On Monday, June 12, 2017 at 8:31:14 PM UTC+5:30, Krishnan wrote:

Akshay,

 

It should work. Here’s a sample

 

package com.rationaleemotions.googleforums.params;

 

import org.testng.Assert;

import org.testng.Reporter;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

 

public class TestClass {

    @Test

    @Parameters({"name", "age"})

    public void testMethod(String name, int age) {

        Reporter.log(name + " is " + age + " years old", true);

        Assert.assertNotNull(name);

        Assert.assertTrue(age > 0);

    }

}

 

Suite file :

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">

<suite name="1265_Suite" parallel="false" verbose="2">

    <parameter name="name" value="Jack"/>

    <test name="partOne" parallel="false" preserve-order="true">

        <parameter name="age" value="25"/>

        <classes>

            <class name="com.rationaleemotions.googleforums.params.TestClass"/>

        </classes>

    </test>

    <test name="partTwo" parallel="false" preserve-order="true">

        <parameter name="age" value="30"/>

        <parameter name="name" value="Jill"/>

        <classes>

            <class name="com.rationaleemotions.googleforums.params.TestClass"/>

        </classes>

    </test>

</suite>

 

 

Output

 

...

... TestNG 6.11 by Cédric Beust ([hidden email])

...

Jack is 25 years old

Jill is 30 years old

 

===============================================

1265_Suite

Total tests run: 2, Failures: 0, Skips: 0

===============================================

 

 

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: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>
Date: Monday, June 12, 2017 at 5:40 PM
To: testng-users <[hidden email]>
Subject: [testng-users] @Test level parameters in testng.xml

 

Hello,

 

I'm wondering if there's a way to provide @Test level parameters through testng.xml file.

 

e.g. I know we could do something like this, in case of which the supplied parameters are applied to every @Test.

 

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
   
<parameter name="someParam2" value="someValue2" />

     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

 

I'm wondering if we could do something like this:

 

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
   
<parameter name="someParam2" value="someValue2" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

 

The reason I'm looking for something like this is that each of my @Test tests in my test class need different set of parameters/values.

 

Thanks,

Akshay

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

--
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="80nPOh4OBwAJ" 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="80nPOh4OBwAJ" 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
|  
Report Content as Inappropriate

Re: <method> level parameters in testng.xml

akshay.maldhure
Fixing the subject line.

On Tuesday, June 13, 2017 at 10:06:29 AM UTC+5:30, [hidden email] wrote:
It seems I can do that. Please check <a href="https://github.com/cbeust/testng/issues/823" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcbeust%2Ftestng%2Fissues%2F823\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFUaz7Mdt1AM74gzT5RxYR3X9Yr2A&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcbeust%2Ftestng%2Fissues%2F823\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFUaz7Mdt1AM74gzT5RxYR3X9Yr2A&#39;;return true;">this link (comment by drapostolos), and it very well works for me. Please check the code sample below.

Test class:

package temp;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Temp {

 
@Test()
 
@Parameters ({"param","methodSpecificParam"})
 
public void test(String key1, String key2) {
 
System.out.println(key1+" "+key2);
 
}
}


Suite file:
   <test name="Test1">
   
<parameter name="param" value="globalValue" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<parameter name="methodSpecificParam"  value="methodSpecificValue"/>
               
<parameter name="param"  value="overridenValue"/>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>


Output: 
overridenValue methodSpecificValue

Hope this helps someone in future.

Regarding @DataProvider, incorporating that would need me to make a lot of code changes in order to the test flow and parameters configurable, and I do not really need a complex structure for the same.

On Tuesday, June 13, 2017 at 9:54:23 AM UTC+5:30, Krishnan wrote:

Akshay,

 

Thanks for clarifying your usecase. No AFAIK, I don’t think you can pass in <parameters> to <method> via a TestNG suite xml file.

 

That said and done, you can very well achieve that using a @DataProvider annotation. Compared to passing parameters via <parameters> tag, it’s a lot more flexible, doesn’t involve an elaborately built suite xml file and gives you the luxury of making your parameters more dynamic. Wouldn’t that work for you ?

 

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, June 13, 2017 at 9:51 AM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] @Test level parameters in testng.xml

 

Hi Krishnan,

 

I think I did not explain the problem correctly. I meant, I'm looking for a way to have <method> level parameters.

 

e.g. Imagine a Java class having three @Test methods and each of them takes different sets of parameters altogether. I would like to know if there's some way for me to designate respective parameters at <method> level in my testng.xml file.

On Monday, June 12, 2017 at 8:31:14 PM UTC+5:30, Krishnan wrote:

Akshay,

 

It should work. Here’s a sample

 

package com.rationaleemotions.googleforums.params;

 

import org.testng.Assert;

import org.testng.Reporter;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

 

public class TestClass {

    @Test

    @Parameters({"name", "age"})

    public void testMethod(String name, int age) {

        Reporter.log(name + " is " + age + " years old", true);

        Assert.assertNotNull(name);

        Assert.assertTrue(age > 0);

    }

}

 

Suite file :

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd">

<suite name="1265_Suite" parallel="false" verbose="2">

    <parameter name="name" value="Jack"/>

    <test <span style="font-size:10.0pt;font-family:&qu

--
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
|  
Report Content as Inappropriate

Re: @Test level parameters in testng.xml

Krishnan Mahadevan
In reply to this post by akshay.maldhure

Great. Thanks for sharing that information. To be honest, I wasn’t aware of that till now!

Glad that this resolves your query.

 

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, June 13, 2017 at 10:06 AM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] @Test level parameters in testng.xml

 

It seems I can do that. Please check this link (comment by drapostolos), and it very well works for me. Please check the code sample below.

 

Test class:

 

package temp;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Temp {

 
@Test()
 
@Parameters ({"param","methodSpecificParam"})
 
public void test(String key1, String key2) {
 
System.out.println(key1+" "+key2);
 
}
}

 

 

Suite file:

   <test name="Test1">
   
<parameter name="param" value="globalValue" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<parameter name="methodSpecificParam"  value="methodSpecificValue"/>
               
<parameter name="param"  value="overridenValue"/>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>

 

 

Output: 

overridenValue methodSpecificValue


Hope this helps someone in future.

 

Regarding @DataProvider, incorporating that would need me to make a lot of code changes in order to the test flow and parameters configurable, and I do not really need a complex structure for the same.


On Tuesday, June 13, 2017 at 9:54:23 AM UTC+5:30, Krishnan wrote:

Akshay,

 

Thanks for clarifying your usecase. No AFAIK, I don’t think you can pass in <parameters> to <method> via a TestNG suite xml file.

 

That said and done, you can very well achieve that using a @DataProvider annotation. Compared to passing parameters via <parameters> tag, it’s a lot more flexible, doesn’t involve an elaborately built suite xml file and gives you the luxury of making your parameters more dynamic. Wouldn’t that work for you ?

 

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: <<a href="javascript:" target="_blank">testng...@...> on behalf of <<a href="javascript:" target="_blank">akshay....@...>
Reply-To: <<a href="javascript:" target="_blank">testng...@...>
Date: Tuesday, June 13, 2017 at 9:51 AM
To: testng-users <<a href="javascript:" target="_blank">testng...@...>
Subject: Re: [testng-users] @Test level parameters in testng.xml

 

Hi Krishnan,

 

I think I did not explain the problem correctly. I meant, I'm looking for a way to have <method> level parameters.

 

e.g. Imagine a Java class having three @Test methods and each of them takes different sets of parameters altogether. I would like to know if there's some way for me to designate respective parameters at <method> level in my testng.xml file.

On Monday, June 12, 2017 at 8:31:14 PM UTC+5:30, Krishnan wrote:

Akshay,

 

It should work. Here’s a sample

 

package com.rationaleemotions.googleforums.params;

 

import org.testng.Assert;

import org.testng.Reporter;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

 

public class TestClass {

    @Test

    @Parameters({"name", "age"})

    public void testMethod(String name, int age) {

        Reporter.log(name + " is " + age + " years old", true);

        Assert.assertNotNull(name);

        Assert.assertTrue(age > 0);

    }

}

 

Suite file :

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="1265_Suite" parallel="false" verbose="2">

    <parameter name="name" value="Jack"/>

    <test name="partOne" parallel="false" preserve-order="true">

        <parameter name="age" value="25"/>

        <classes>

            <class name="com.rationaleemotions.googleforums.params.TestClass"/>

        </classes>

    </test>

    <test name="partTwo" parallel="false" preserve-order="true">

        <parameter name="age" value="30"/>

        <parameter name="name" value="Jill"/>

        <classes>

            <class name="com.rationaleemotions.googleforums.params.TestClass"/>

        </classes>

    </test>

</suite>

 

 

Output

 

...

... TestNG 6.11 by Cédric Beust ([hidden email])

...

Jack is 25 years old

Jill is 30 years old

 

===============================================

1265_Suite

Total tests run: 2, Failures: 0, Skips: 0

===============================================

 

 

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: Monday, June 12, 2017 at 5:40 PM
To: testng-users <[hidden email]>
Subject: [testng-users] @Test level parameters in testng.xml

 

Hello,

 

I'm wondering if there's a way to provide @Test level parameters through testng.xml file.

 

e.g. I know we could do something like this, in case of which the supplied parameters are applied to every @Test.

 

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
   
<parameter name="someParam2" value="someValue2" />

     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

 

I'm wondering if we could do something like this:

 

   <test name="Test1">
   
<parameter name="someParam" value="someValue" />
   
<parameter name="someOtherParam" value="someOtherValue" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test1" />
           
</methods>
         
</class>
     
</classes>
   
</test>
   
<test name="Test2">
   
<parameter name="someParam2" value="someValue2" />
     
<classes>
         
<class name="temp.Temp">
           
<methods>
               
<include name="test2" />
           
</methods>
         
</class>
     
</classes>
   
</test>

 

The reason I'm looking for something like this is that each of my @Test tests in my test class need different set of parameters/values.

 

Thanks,

Akshay

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

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