Skip to content

Extending web controller support

Thanos edited this page Jan 20, 2014 · 2 revisions

Overview

In latest stevia commit in master, we add the ability to extend the framework with additional web controllers at compile/runtime.

How this works

###Backgrounder

Stevia automatically includes the following extension spring contexts found in the classpath:

  • the test beans of your application (META-INF/spring/test-beans-*.xml)
  • extension points for augmenting the framework (META-INF/spring/stevia-extensions-drivers-*.xml) Got it?

###Extending controllers support

We use the stevia-extensions-drivers-*.xml to add to our context the needed wiring for driver registrations. The following two statements are necessary:

<bean id="xyzController" class="com.mycompany.stevia.controllers.XYZWebController" scope="prototype" />
<bean id="xyz-driver" class="com.persado.oss.quality.stevia.selenium.core.controllers.registry.Driver"
  p:name="xyzDriver" p:className="com.mycompany.stevia.controllers.factories.xyzWebControllerFactoryImpl"/>

The first statement is obvious - you're registering a controller XYZWebController (must be extending WebController for this to work, right?) in your context. The second statement is a bit weird - you're using one of our classes (...registry.Driver) to pass two arguments to it: p:name and p:className.

The p:name argument must be exactly the same as the name you use in the testng.xml to specify the driver to use. We already support 'webdriver' and 'selenium', so figure your own now.

The p:className argument must be a fully-qualified name of a class implementing WebControllerFactory. We dynamically instanciate the factory, and using the implemented Factory methods we will configure the bean to launch a new test framework runner. Now that we've covered Selenium and Webdriver, QTP anyone?

####Really now, how does this work??

Well. Spring wizadry aside, we do the following steps:

  • We load and populate a factory registry with the beans you've specified.
  • At the time of Stevia initialisation, we do the following:
    • We get the type of driver you want from testng.xml (parameter driverType)
    • We search for a factory in the registry by this name
    • We get the bean for the driver from spring context by asking the factory "what is the bean name?"
    • We call the factory with the bean name to do additional configuration (e.g. url, size of window, etc)
  • We give back to Stevia the driver initialised and attached to the testing thread, ready for action.

That's it...