Friday 8 February 2013

Faster Arquillian and Graphene 2 test development

Tired of long turnaround when writing tests with Arquillian and Graphene 2?
Thanks to Pavol Pitonak we've learned how to speed test development up by order of magnitude.

Graphene 2 allows you to efficiently test user interfaces of web applications. You write the simple test code and run it in your IDE or with Maven and Graphen takes care of starting selenium server, lunching the web browser and do the clicking.

Sounds fantastic, but when you are developing the test the time between running the test, fixing it and running again is too long. It's pure waste.
It's because for each run the selenium-server needs to be started and a new session be created.
For deveopment purposes we can speed it up by starting selenium server ourselves in standalone mode and configuring Arquillian to reuse existing session.

Here are few simple steps to achieve that:

1. Download Selenium Server in standalone version from For example:

2. Run it with command:
java -jar selenium-server-standalone-2.29.0.jar

3. Create new Maven project. If you want to use Arquillian with Graphene 2 and WebDriver, you should add these dependencies to your pom.xml:

If you want to use JUnit in standalone mode:

or in container mode:
rest of dependencies:

<!-- Graphene dependency chain - imports all other dependencies required -->

<!-- Graphene WebDriver -->
For a few dependencies above, you should have added JBoss repository to Maven's settings.xml or alternatively add repository directly in project pom.xml file, like this:
4. Now, you should specify, which browser will be used to execute tests. I assume, you have Firefox in your computer. So, in next step you should add arquillian.xml to project in /src/test/resources directory. Example configuration, with Firefox as default browser for WebDriver:
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="" xmlns:xsi=""

   <!-- configuration for graphene2 -->
   <extension qualifier="webdriver">
       <property name="browserCapabilities">firefox</property>
       <property name="remoteReusable">true</property>
The essential property is "remoteReusable", which instructs graphene to reuse existing session, so that the browser is opened only once and reused for following test runs.

Other useful property would be "remoteAddress" in case your selenium server runs on different port or host.
<property name="remoteAddress">http://localhost:4444/wd/hub</property>
5. At the end, you can write new test. Simple empty test class should look like this:
public class GrapheneTest {

    WebDriver driver;

    public void testHappyPath(){
        String pageTitle = driver.getTitle();
        Assert.assertEquals(pageTitle, "Google"); 
Finally, you can run tests from your IDE or trough mvn test command.

Browser session is preserved across the tests, so if you need to reset browser cookies between tests, you can add this line whenever deleting cookies is needed.
To automate clearing cookies between tests, you should use @Before annotation:
private void beforeEachTest(){
If JUnit is in standalone mode, you should be aware of this bug: ARQ-1070 , but versions from pom.xml included above seems not affected, @Before annotation works fine.

Useful links


  1. Thanks for sharing this blog. This idea of test development speed up by order of magnitude is just great.