Change reports path in testng.xml

1,468 views
Skip to first unread message

Greg Martz

unread,
Jul 17, 2015, 9:11:08 AM7/17/15
to testng...@googlegroups.com
Greetings all,

I need to run selenium on a read-only drive under Win7.  So, I need to be able to send the test-output directory to a different drive.  I'm running both under Selenium and via command line.  I've scoured google, and I've seen a method of setting the output directory either via command line, or via @BeforeTest with:

@BeforeTest
public void setup(ITestContext ctx)
{
   TestRunner runner = (TestRunner) ctx;
   runner.setOutputDirectory(System.getProperty("user.home") + "\\Desktop\\BPMSLogs\\");
}

Is there a way to perhaps set a listener in the testng.xml file instead of putting the @BeforeTest in all 43 of my test classes?  Here is a snippet of my testng.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SuiteEndToEnd" parallel="false" verbose="10" thread-count="2">
<listeners>
        <listener class-name="com.bpms.utility.RetryListener"/>
        <listener class-name="com.bpms.utility.TestListener"/>
</listeners>
<test name="End to End Test Suite">
<parameter name="browser" value="firefox"/>
<parameter name="debug" value="true"/>
<parameter name="defaults" value="false"/>
<classes>
<class name="com.bpms.tests.InitiateBuyPlan"/>
<class name="com.bpms.tests.AddItemsToBuyPlan"/>
<class name="com.bpms.tests.ReviewBuyPlan"/>
<class name="com.bpms.tests.ApproveBuyPlan"/>
<class name="com.bpms.tests.ManageQuoteSolicitation"/>
<class name="com.bpms.tests.StartQuote"/>
<class name="com.bpms.tests.ReviewQuote"/>
<class name="com.bpms.tests.RecordInterestInQuotes"/>
                        ...
</classes>
</test>
</suite>


Thanks!
Greg

吴亭

unread,
Jul 17, 2015, 9:47:34 AM7/17/15
to testng...@googlegroups.com
not sure if I fully understand your question, but based on your code, you can use ITestListener:

public class MyListener implements ITestListener{

Inside this listener, there is a method called
    public void onStart(ITestContext context) {


This may help.

Br,
Tim


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

Krishnan Mahadevan

unread,
Jul 18, 2015, 9:31:04 AM7/18/15
to testng...@googlegroups.com
@Greg

If you are trying to run your tests using TestNG command line, then you can change the output directory via the command line argument –d. For the full list of command line arguments that TestNG supports take a look here.
If you are working with a Maven project and using the surefire plugin to run your tests then you can specify an alternate output folder using “reportsDirectory” attribute.

Please refer here for more information.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Greg Martz

unread,
Jul 20, 2015, 9:08:19 AM7/20/15
to testng-users
I believe I can do that.  One question...  I need the output directory to be:  System.getProperty("user.home") + "\\Desktop\\BPMSLogs\\".  How is that possible through the command line?


Thanks!
Greg

Greg Martz
Test Analyst III  |  (425)416-5039  |  gma...@Costco.com 

"Confidentiality Notice:  This e-mail message, including any attachments, is for the sole use to the intended recipient(s) and may contain confidential and privileged information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message."

Krishnan Mahadevan

unread,
Jul 21, 2015, 1:41:27 AM7/21/15
to testng...@googlegroups.com
Greg,
I dont have a windows machine so I cant experiment and given you an answer.

In UNIX, I would do something like this

-d "`echo $HOME` + /Desktop/BPMSLogs"

You can try something similar in Java.



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/

Reply all
Reply to author
Forward
0 new messages