views:

335

answers:

1

I am setting up JUnit 4.7 tests with Selenium 1.x and Spring 3.0.

I want to extend Selenium's SeleneseTestCase for the shortcuts and conventions it provides (more importantly, the Selenium IDE generated code seems to expect this). Yet I want the Spring context and other goodness to be present during the execution.

Because I cannot extend Spring's AbstractJUnit4SpringContextTests, I tried decorating my test case with @RunWith(SpringJUnit4ClassRunner.class). This succesfully setups Spring but causes some oddities in Selenium execution: tests are executed slowly and browser windows are left open, for example. I suppose it overrides some part of Selenium (just a guess)... unfortunately, the base SeleneseTestCase class only permits altering a restricted set of parameters, exluding setting the execution speed, for example (makes me wonder, if the base class is that nice after all...).

To my understanding, in order to make all the bells and whistles of Spring working, I must either extend the AbstractJUnit4SpringContextTests or decorate the class with @RunWith(SpringJUnit4ClassRunner.class). However, the former I cannot, and the latter brings problems.

Having only @ContextConfiguration does load up the context, but at least dependency injection is not working. That's where I stopped.

How can I initialize Spring neatly with Selenium (or any other library with same case)?

Edit: Made the text more readable.

+1  A: 

I was annoyed by a similar problem enough to write a MethodRule implementation that will load a Spring context and autowire it's host test. Maybe that is the start of what you're looking for.

It will allow you to do something like this:

@Rule
public TemporarySpringContext context = new TemporarySpringContext("context.xml");

@Autowired
MyService myServiceBean;

If you make any improvements please let me know.

iwein