Factory madness

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

Factory madness

Joe DeSantis
I'm attempting to use both Guice and Factories for my project.
I'm attempting to use Testng factories as I have a bunch of tests that are configurable based on constructor arguments.
I am using Guice because I want a lot of flexibility on certain dependencies that I couldn't seem to fully get out of testng from the boot.
For example using Annotations on parameters as they have slightly different requirements.

This is my first stab at this so, please if you have input comment away.

I have a few concerns with this current design:
1) How do I add more than module with (line 1 in my script below)
2) The factory method calls the constructor which in my case starts up a new instance of a chrome driver.
If I have 100 tests, I can have 100 chrome drivers sitting around not even being used. Is there a way to defer instantiation with testng,
or what is the approach here?


@org.testng.annotations.Guice(modules=ActorObtainableModule.class)
public class VanityUrlFactory {

private GuiceFactory guiceFactory;

// public interface GuiceFactory {
// VanityUrl create(TestingUrl url, boolean useOfferCode, String realCpc);
// }

// @Inject
// public VanityUrl(@Assisted TestingUrl url, @Assisted boolean useOfferCode, @Assisted String realCpc, FunnelActor actor) {

@Inject
VanityUrlFactory(GuiceFactory guiceFactory){
this.guiceFactory = guiceFactory;
}

@Factory
// @Inject
public Object[] factoryMethod() {
System.out.println(guiceFactory);
return new Object[]{
// No offer code tests
guiceFactory.create(TestingUrl.VANITYQUICK, false, "ebf93e"),
guiceFactory.create(TestingUrl.VANITYFAST, false, "c47385")
};
}
}

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

Mrunal Gosar
Your 2nd problem can be solved by applying the concept of lazy loading. Example as below:
private Webdriver browser;


public WebDriver getBrowser() {
if(browser == null) {
//Instantiate your browser here.
}
return browser;
}

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