@Factory Annotation

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

@Factory Annotation

SPS
Hello,

I have a class ABCFactory with two methods , in first method I am trying to collect all  parameters from ITestContext  needed to run the tests
in another method which is with @factory with data provider I am trying to call my testcases. I have a problem with as @factory gets executed first and  ITestContext  is null
how can I resolve my problem?

public class ABCFactory{

ITestContext ctx

public class ABCFactory(){
 

}


public class ABCFactory(ITestContext ctx){

  param =

context.getSuite().getXmlSuite().getAllParameters();

 

}

@Factory(dataProvider = "xyz", dataProviderClass = dp.class)

       public Object[] factoryMethod(Hashtable<String, String> data) {

             

              return new Object[] { new ABCFactory(ctx), new PQR(data) };

 

       }

      



}


Thanks





--
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 https://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: @Factory Annotation

Krishnan Mahadevan

Sneha

What exactly are you trying to do ? Can you please explain your use case ?

By default if Testng sees a factory annotation in a class then I think Testng will first invoke it and may or may not invoke your desired constructor.

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/

From: SPS
Sent: Tuesday, June 7, 01:49
Subject: [testng-users] @Factory Annotation
To: testng-users

Hello,

I have a class ABCFactory with two methods , in first method I am trying to collect all  parameters from ITestContext  needed to run the tests

in another method which is with @factory with data provider I am trying to call my testcases. I have a problem with as @factory gets executed first and  ITestContext  is null

how can I resolve my problem?

public class ABCFactory{

ITestContext ctx

public class ABCFactory(){

 

}

public class ABCFactory(ITestContext ctx){

  param =

context.getSuite().getXmlSuite().getAllParameters();

 

}

@Factory(dataProvider = "xyz", dataProviderClass = dp.class)

       public Object[] factoryMethod(Hashtable<String, String> data) {

             

              return new Object[] { new ABCFactory(ctx), new PQR(data) };

 

       }

      

}

Thanks




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

Re: @Factory Annotation

SPS
In reply to this post by SPS
Yes, if @Factory is present, TestNg invokes that first.
I want to collect all parameter information before I hit @Factory. I need that information to pass it to data provider. since it is hitting @Factory ISuiteContext , ITestContext are null.

On Monday, June 6, 2016 at 3:19:13 PM UTC-5, SPS wrote:
Hello,

I have a class ABCFactory with two methods , in first method I am trying to collect all  parameters from ITestContext  needed to run the tests
in another method which is with @factory with data provider I am trying to call my testcases. I have a problem with as @factory gets executed first and  ITestContext  is null
how can I resolve my problem?

public class ABCFactory{

ITestContext ctx

public class ABCFactory(){
 

}


public class ABCFactory(ITestContext ctx){

  param =

context.getSuite().getXmlSuite().getAllParameters();

 

}

@Factory(dataProvider = "xyz", dataProviderClass = dp.class)

       public Object[] factoryMethod(Hashtable<String, String> data) {

             

              return new Object[] { new ABCFactory(ctx), new PQR(data) };

 

       }

      



}


Thanks





--
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 https://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: @Factory Annotation

Krishnan Mahadevan
Sneha,

See if the below sample is what you are looking for :

public class DataDrivenSample {
private RemoteWebDriver driver;
private int a;
private String b;
private boolean c;

@Factory (dataProvider = "dp")
public DataDrivenSample(Integer a, String b, Boolean c) {
this.a = a;
this.b = b;
this.c = c;
}

@BeforeClass
public void setup() {
driver = new ChromeDriver();
}

@AfterClass
public void cleanup() {
driver.quit();
}

@Test
public void testMethod() {
driver.get("http://www.google.com");
System.err.println("accessing the passed values ");
System.err.println("a = " + a);
System.err.println("b = " + b);
System.err.println("c = " + c);

}

@Test
public void anotherTestMethod() {
//Here is another test method that works on the parameters passed.
System.err.println("accessing the passed values ");
System.err.println("a = " + a);
System.err.println("b = " + b);
System.err.println("c = " + c);
}

@DataProvider (name = "dp")
public static Object[][] getData(ITestContext ctx) {
//Just showing how to access the parameters from the TestNG suite xml file.
//You can use this incase, you want to have your .xls file also passed via the suite file.
System.err.println("test name " + ctx.getName());
//Replace the below logic with your .xls reading logic.
return new Object[][] {
{10, "TestNG", true},
{20, "Selenium", false}
};
}
}

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/

On Tue, Jun 7, 2016 at 2:58 PM, SPS <[hidden email]> wrote:
Yes, if @Factory is present, TestNg invokes that first.
I want to collect all parameter information before I hit @Factory. I need that information to pass it to data provider. since it is hitting @Factory ISuiteContext , ITestContext are null.

On Monday, June 6, 2016 at 3:19:13 PM UTC-5, SPS wrote:
Hello,

I have a class ABCFactory with two methods , in first method I am trying to collect all  parameters from ITestContext  needed to run the tests
in another method which is with @factory with data provider I am trying to call my testcases. I have a problem with as @factory gets executed first and  ITestContext  is null
how can I resolve my problem?

public class ABCFactory{

ITestContext ctx

public class ABCFactory(){
 

}


public class ABCFactory(ITestContext ctx){

  param =

context.getSuite().getXmlSuite().getAllParameters();

 

}

@Factory(dataProvider = "xyz", dataProviderClass = dp.class)

       public Object[] factoryMethod(Hashtable<String, String> data) {

             

              return new Object[] { new ABCFactory(ctx), new PQR(data) };

 

       }

      



}


Thanks





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

Re: @Factory Annotation

SPS
In reply to this post by SPS

Thanks Krishnan !!!
On Monday, June 6, 2016 at 3:19:13 PM UTC-5, SPS wrote:
Hello,

I have a class ABCFactory with two methods , in first method I am trying to collect all  parameters from ITestContext  needed to run the tests
in another method which is with @factory with data provider I am trying to call my testcases. I have a problem with as @factory gets executed first and  ITestContext  is null
how can I resolve my problem?

public class ABCFactory{

ITestContext ctx

public class ABCFactory(){
 

}


public class ABCFactory(ITestContext ctx){

  param =

context.getSuite().getXmlSuite().getAllParameters();

 

}

@Factory(dataProvider = "xyz", dataProviderClass = dp.class)

       public Object[] factoryMethod(Hashtable<String, String> data) {

             

              return new Object[] { new ABCFactory(ctx), new PQR(data) };

 

       }

      



}


Thanks





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