Handling exception when parameters in TestNG are missing

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

Handling exception when parameters in TestNG are missing

Bagy
I am using TestNG Parameters in @BeforeMethod to configure the Test. When ever i want to run the suite using TestNG.xml, the parameters are successfully passed to the before method and it configures as expected. 

when i want to run one testcase using Eclipse, I have to configure  Run Configuration > Argument  to pass those parameters to the test. 

Is there a way, I can tell the script to pick the value from the property file if the parameters are NOT configured in the Arguments tab. How to by-pass the Exception "FAILED CONFIGURATION: @AfterMethod" org.testng.TestNGException: 

Can someone help me to find a solution to handle the @parameters in Eclipse when it is missed to configure. 


Thanks
Bagy



--
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.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Handling exception when parameters in TestNG are missing

anand_raja

Hi Bagy,


Please refer the testng documentation for this

http://testng.org/javadoc/org/testng/annotations/Optional.html


some snippets posted below for your easy understanding.

Parameters can be declared optional with the Optional annotation:

@Parameters("db")
@Test
public void testNonExistentParameter(@Optional("mysql") String db) { ... }
If no parameter named "db" is found in your testng.xml file, your test method will receive the default value specified inside the @Optional annotation: "mysql".



On Wednesday, 10 September 2014 19:18:43 UTC+5:30, Bagy wrote:
I am using TestNG Parameters in @BeforeMethod to configure the Test. When ever i want to run the suite using TestNG.xml, the parameters are successfully passed to the before method and it configures as expected. 

when i want to run one testcase using Eclipse, I have to configure  Run Configuration > Argument  to pass those parameters to the test. 

Is there a way, I can tell the script to pick the value from the property file if the parameters are NOT configured in the Arguments tab. How to by-pass the Exception "FAILED CONFIGURATION: @AfterMethod" org.testng.TestNGException: 

Can someone help me to find a solution to handle the @parameters in Eclipse when it is missed to configure. 


Thanks
Bagy



--
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.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Handling exception when parameters in TestNG are missing

Greg Martz
Good morning,

I gave this a try myself, and wound up freezing Eclipse.  As soon as I ran the test, I had to kill the task. Is something missing?  Here is what I had:

@BeforeMethod
@Parameters("browser")
public void setUp(@Optional ("firefox") String browser) throws Exception
{



Thanks!
Greg

On Wed, Sep 17, 2014 at 1:46 AM, Anand Raja.K <[hidden email]> wrote:

Hi Bagy,


Please refer the testng documentation for this

http://testng.org/javadoc/org/testng/annotations/Optional.html


some snippets posted below for your easy understanding.

Parameters can be declared optional with the Optional annotation:

@Parameters("db")
@Test
public void testNonExistentParameter(@Optional("mysql") String db) { ... }
If no parameter named "db" is found in your testng.xml file, your test method will receive the default value specified inside the @Optional annotation: "mysql".



On Wednesday, 10 September 2014 19:18:43 UTC+5:30, Bagy wrote:
I am using TestNG Parameters in @BeforeMethod to configure the Test. When ever i want to run the suite using TestNG.xml, the parameters are successfully passed to the before method and it configures as expected. 

when i want to run one testcase using Eclipse, I have to configure  Run Configuration > Argument  to pass those parameters to the test. 

Is there a way, I can tell the script to pick the value from the property file if the parameters are NOT configured in the Arguments tab. How to by-pass the Exception "FAILED CONFIGURATION: @AfterMethod" org.testng.TestNGException: 

Can someone help me to find a solution to handle the @parameters in Eclipse when it is missed to configure. 


Thanks
Bagy



--
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.
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 http://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: Handling exception when parameters in TestNG are missing

anand_raja
In reply to this post by Bagy
Hello,

I gave try it was working for me.. Any how I have attached testng.xml and .java for your reference.. Have a try with file attached. let me know whether you can proceed with it.

Regards
Anand Raja K

--
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.
For more options, visit https://groups.google.com/d/optout.

testNG.xml (386 bytes) Download Attachment
TestNGParameter.java (498 bytes) Download Attachment
TestNG.jpg (180K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Handling exception when parameters in TestNG are missing

Greg Martz
I'm not running the xml.  I'm trying to run the .java directly from in eclipse.  I've tried your code, but when I execute the .java, it just hangs and I have to quit the app.


Thanks!
Greg

On Wed, Sep 17, 2014 at 10:03 PM, Anand Raja.K <[hidden email]> wrote:
Hello,

I gave try it was working for me.. Any how I have attached testng.xml and .java for your reference.. Have a try with file attached. let me know whether you can proceed with it.

Regards
Anand Raja K

--
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.
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 http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.