The tutorial #1 is a good start. See link to the tutorial at
http://code.google.com/p/guiceberry/
In a nutshell,
1. Download the full release source code
http://code.google.com/p/guiceberry/downloads/list
2. Run this
You've got GuiceBerry + JUnit4 + WebDriver at this point. So:
3. @Inject Selenium selenium
into the test
4. See lines 23 to 27 of this file, where the WebDriver is @Provided:
5. Create a similar
@Provides @TestScoped
Selenium getSelenium() {
// put here all the code to get an instance of Selenium -- start the
Selenium RC and all
}
You're done. You might want to start the Selenium RC in the
GuiceBerryEnvMain instead, but even this should work. Post back the
change here when you get it working so it becomes documentation for
others.
Peace,
Z
> --
> You received this message because you are subscribed to the Google Groups "guiceberry-users" group.
> To post to this group, send email to guiceber...@googlegroups.com.
> To unsubscribe from this group, send email to guiceberry-use...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/guiceberry-users?hl=en.
>
>
1. I would generally prefer creating Selenium as a @Singleton, since
it would be cheaper (sorry I told you @TestScoped originally, it was a
slip of thought, even if it works). Also see note below.
2. Also ideally, the "selenium.start" method should not happen in the
provider method. I don't know if there's a good canonical article out
there on this Guice-y topic, but doing expensive things in a provider
is frowned upon. If you don't "start" in the provider method, this is
where you can move it to:
a. If you make it an @Singleton, put it in the GuiceBerryEnvMain (i.e.
@Inject Selenium into the GBEM, and start it there).
b. If you keep it an @TestScoped, put it in a TestWrapper. BTW, if you
keep it a @TestScoped, you should likely want to "stop" it at the end
of the test, lest selenium instances will pile up. Here's how that
code would look like:
@Provides
TestWrapper getTestWrapper(final TearDownAccepter tearDownAccepter,
final Selenium selenium) {
return new TestWrapper() {
public void toRunBeforeTest() {
tearDownAccepter.addTearDown(new TearDown() {
public void tearDown() throws Exception {
// This gets executed after every test
selenium.stop();
}
});
}
// This gets executed before every test
selenium.start();
}
}
Z