Need help to do parameterization with testng.xml file

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

Need help to do parameterization with testng.xml file

Mayank Srivastava
testng.xml file

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="gmail">
<parameter name="usrname1" value="technical"/>
<parameter name="usrname2" value="mayankt280"/>
<test name="log" preserve-order="true">
<classes>
<class name = "default package.parameterXML"></class>
</classes>
</test>
</suite>

Selenium Code

import org.openqa.selenium.By;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class parameterXML {
   
    @Test
    @Parameters ({ "usrname1" })
    public void gmail (String usrname){
       
        InternetExplorerDriver IE = new InternetExplorerDriver ();
       
        IE.get("http://www.linkedin.com");
        IE.findElement(By.xpath(".//*[@id='session_key-login']")).sendKeys(usrname);
       
   
    }
   
}

Result:

SKIPPED: gmail
org.testng.TestNGException:
Parameter 'usrname1' is required by @Test on method gmail but has not been marked @Optional or defined
in C:\Users\testng-eclipse-400811763\testng-customsuite.xml
    at org.testng.internal.Parameters.createParameters(Parameters.java:155)
    at org.testng.internal.Parameters.createParameters(Parameters.java:355)
    at org.testng.internal.Parameters.handleParameters(Parameters.java:447)


Can anyone please suggest me where I'm going wrong?

--
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 http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Need help to do parameterization with testng.xml file

⇜Krishnan Mahadevan⇝
Mayank,
At first sight everything looked fine, but only after taking a closer look I realized that you weren't running this via Run as > TestNG Suite but instead you seemed to be running this by right clicking on your class and choosing run as > TestNG test.

If you intend to run your test class by right clicking and choosing run as > TestNG test, then you would need to tell TestNG that your testng.xml file is going to be the template file [ Project > Properties > TestNG > Template XML file 

Once you are done with it, when you run your test it should work fine.

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/


On Wed, Mar 6, 2013 at 7:17 PM, Mayank Srivastava <[hidden email]> wrote:
testng.xml file

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="gmail">
<parameter name="usrname1" value="technical"/>
<parameter name="usrname2" value="mayankt280"/>
<test name="log" preserve-order="true">
<classes>
<class name = "default package.parameterXML"></class>
</classes>
</test>
</suite>

Selenium Code

import org.openqa.selenium.By;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class parameterXML {
   
    @Test
    @Parameters ({ "usrname1" })
    public void gmail (String usrname){
       
        InternetExplorerDriver IE = new InternetExplorerDriver ();
       
        IE.get("http://www.linkedin.com");
        IE.findElement(By.xpath(".//*[@id='session_key-login']")).sendKeys(usrname);
       
   
    }
   
}

Result:

SKIPPED: gmail
org.testng.TestNGException:
Parameter 'usrname1' is required by @Test on method gmail but has not been marked @Optional or defined
in C:\Users\testng-eclipse-400811763\testng-customsuite.xml
    at org.testng.internal.Parameters.createParameters(Parameters.java:155)
    at org.testng.internal.Parameters.createParameters(Parameters.java:355)
    at org.testng.internal.Parameters.handleParameters(Parameters.java:447)


Can anyone please suggest me where I'm going wrong?

--
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 http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
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 http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Need help to do parameterization with testng.xml file

Mayank Srivastava
Thanks Krishnan.

That was the mistake. Now it's working with Run As > TestNG Suite option.

On Thursday, March 7, 2013 9:53:51 AM UTC+5:30, Krishnan wrote:
Mayank,
At first sight everything looked fine, but only after taking a closer look I realized that you weren't running this via Run as > TestNG Suite but instead you seemed to be running this by right clicking on your class and choosing run as > TestNG test.

If you intend to run your test class by right clicking and choosing run as > TestNG test, then you would need to tell TestNG that your testng.xml file is going to be the template file [ Project > Properties > TestNG > Template XML file 

Once you are done with it, when you run your test it should work fine.

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/


On Wed, Mar 6, 2013 at 7:17 PM, Mayank Srivastava <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="yKCnyF2l1uIJ">techn...@...> wrote:
testng.xml file

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="gmail">
<parameter name="usrname1" value="technical"/>
<parameter name="usrname2" value="mayankt280"/>
<test name="log" preserve-order="true">
<classes>
<class name = "default package.parameterXML"></class>
</classes>
</test>
</suite>

Selenium Code

import org.openqa.selenium.By;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class parameterXML {
   
    @Test
    @Parameters ({ "usrname1" })
    public void gmail (String usrname){
       
        InternetExplorerDriver IE = new InternetExplorerDriver ();
       
        IE.get("http://www.linkedin.com");
        IE.findElement(By.xpath(".//*[@id='session_key-login']")).sendKeys(usrname);
       
   
    }
   
}

Result:

SKIPPED: gmail
org.testng.TestNGException:
Parameter 'usrname1' is required by @Test on method gmail but has not been marked @Optional or defined
in C:\Users\testng-eclipse-400811763\testng-customsuite.xml
    at org.testng.internal.Parameters.createParameters(Parameters.java:155)
    at org.testng.internal.Parameters.createParameters(Parameters.java:355)
    at org.testng.internal.Parameters.handleParameters(Parameters.java:447)


Can anyone please suggest me where I'm going wrong?

--
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="yKCnyF2l1uIJ">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="yKCnyF2l1uIJ">testng...@....
Visit this group at http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
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 http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Need help to do parameterization with testng.xml file

neha
This post has NOT been accepted by the mailing list yet.
In reply to this post by Mayank Srivastava
Hello,
The problem which you have mentioned in the post,  I am also getting the same but the given solution is not working for me.
What need to do after following steps:
project->testng->Template XML file(In this what  we need to browse)

Can you pls tell how your problem resolved.


Thanks & Regards
Neha