Get current suite name during @Factory method call

View: New views
4 Messages — Rating Filter:   Alert me  

Get current suite name during @Factory method call

by Curtis W :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I have a group of tests that are created using an @Factory method, and
are part of a larger suite that I've defined in an xml file. I'd like
these tests to run against one of several environments which are at
different URLs. For normal @Test methods this is not a problem because
in the @BeforeSuite period of testng's lifecycle I can simply call a
method in a class which has the appropriate set-up hard coded.
@Factory runs before @BeforeSuite however, so I can't rely on the same
mechanism.

Is there any way to access the testng framework dynamically to
determine which xml file was used to configure the current test run?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Get current suite name during @Factory method call

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Curtis,

You can tell TestNG to pass your factory an ITestContext that contains all the information you need.

Maybe something a bit more flexible for you would be to use a parameter:

<suite name="Single" verbose="1" parallel="false" thread-count="2">

  <parameters>
    <parameter name="foo" value="bar" />
  </parameters>

  <test name="Single">
    <classes>
      <class name="test.factory.FactoryChild" />
    </classes>     
  </test>

</suite>

and your factory:

  @Factory
  public Object[] create(ITestContext ctx) {
    // will print "bar"
    System.out.println("Parameter:" + ctx.getCurrentXmlTest().getParameter("foo"));
    return new Object[] {
    // ...

Does this help?

--
Cedric




On Fri, Nov 6, 2009 at 12:05 PM, Curtis W <galvorn@...> wrote:

I have a group of tests that are created using an @Factory method, and
are part of a larger suite that I've defined in an xml file. I'd like
these tests to run against one of several environments which are at
different URLs. For normal @Test methods this is not a problem because
in the @BeforeSuite period of testng's lifecycle I can simply call a
method in a class which has the appropriate set-up hard coded.
@Factory runs before @BeforeSuite however, so I can't rely on the same
mechanism.

Is there any way to access the testng framework dynamically to
determine which xml file was used to configure the current test run?





--
Cédric



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Get current suite name during @Factory method call

by Curtis W :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


That works perfectly. You're a legend!

On Nov 6, 1:24 pm, Cédric Beust ♔ <cbe...@...> wrote:

> Hi Curtis,
>
> You can tell TestNG to pass your factory an ITestContext that contains all
> the information you need.
>
> Maybe something a bit more flexible for you would be to use a parameter:
>
> <suite name="Single" verbose="1" parallel="false" thread-count="2">
>
>   <parameters>
>     <parameter name="foo" value="bar" />
>   </parameters>
>
>   <test name="Single">
>     <classes>
>       <class name="test.factory.FactoryChild" />
>     </classes>
>   </test>
>
> </suite>
>
> and your factory:
>
>   @Factory
>   public Object[] create(ITestContext ctx) {
>     // will print "bar"
>     System.out.println("Parameter:" +
> ctx.getCurrentXmlTest().getParameter("foo"));
>     return new Object[] {
>     // ...
>
> Does this help?
>
> --
> Cedric
>
>
>
> On Fri, Nov 6, 2009 at 12:05 PM, Curtis W <galv...@...> wrote:
>
> > I have a group of tests that are created using an @Factory method, and
> > are part of a larger suite that I've defined in an xml file. I'd like
> > these tests to run against one of several environments which are at
> > different URLs. For normal @Test methods this is not a problem because
> > in the @BeforeSuite period of testng's lifecycle I can simply call a
> > method in a class which has the appropriate set-up hard coded.
> > @Factory runs before @BeforeSuite however, so I can't rely on the same
> > mechanism.
>
> > Is there any way to access the testng framework dynamically to
> > determine which xml file was used to configure the current test run?
>
> --
> ***Cédric
> *
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Get current suite name during @Factory method call

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Fri, Nov 6, 2009 at 12:47 PM, Curtis W <galvorn@...> wrote:

That works perfectly. You're a legend!

Wow, thanks :-)

--
Cédric



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---