Handling exception when parameters in TestNG are missing

194 views
Skip to first unread message

Bagy

unread,
Sep 10, 2014, 9:48:43 AM9/10/14
to testng...@googlegroups.com
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



Anand Raja.K

unread,
Sep 17, 2014, 4:46:57 AM9/17/14
to testng...@googlegroups.com

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

Greg Martz

unread,
Sep 17, 2014, 12:22:54 PM9/17/14
to testng...@googlegroups.com
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

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

Anand Raja.K

unread,
Sep 18, 2014, 1:03:19 AM9/18/14
to testng...@googlegroups.com
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
testNG.xml
TestNGParameter.java
TestNG.jpg

Greg Martz

unread,
Sep 22, 2014, 3:45:15 PM9/22/14
to testng...@googlegroups.com
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

--
Reply all
Reply to author
Forward
0 new messages