Back to list of postings

Using Arquillian Drone and Graphene in Standalone Mode

I've been using Arquillian and its testing framework for a few years now and absolutely love it! It's super easy to manage a server's lifecycle, deploy applications, and then test them. Drone and Graphene's extensions also make it incredibly easy to write browser-based tests without getting too down and dirty with the Selenium WebDriver API (which is a little messy).

Since I love Drone and Graphene, it would be nice to use the page abstractions/fragments on non-Java apps (sure, you can use Arquillian Cube too… but that's another post). This post will go over what's needed to run Drone and Graphene in standalone mode.

What's standalone mode again?

When writing Arquillian tests, you need to define a method annotated with @Deployment that returns an Archive that will be deployed. Standalone mode does NOT require an archive. So, you use it… standalone!

 Note that the dependencies listed below are as of the date of this post. Feel free to update versions accordingly.

Add Dependencies

First, add the following entries to the dependencyManagement to your pom.xml. In case you haven't used the import scope before, you can almost think of it as inheriting another pom's dependencyManagement. In Maven, you can have only one parent pom. But, you can import several other poms. But, importing only brings in dependencyManagement. When we declare dependencies in the next step, the versions are pulled from one of the pom imports.

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.jboss.arquillian</groupId>
      <artifactId>arquillian-bom</artifactId>
      <version>1.1.11.Final</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.arquillian.extension</groupId>
      <artifactId>arquillian-drone-bom</artifactId>
      <version>2.0.0.Final</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.arquillian.selenium</groupId>
      <artifactId>selenium-bom</artifactId>
      <version>2.53.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

And in the dependencies section, add the following:

<dependencies>
  <dependency>
    <groupId>org.jboss.arquillian.junit</groupId>
    <artifactId>arquillian-junit-standalone</artifactId>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.jboss.arquillian.graphene</groupId>
    <artifactId>graphene-webdriver</artifactId>
    <version>2.1.0.CR2</version>
    <type>pom</type>
    <scope>test</scope>
  </dependency>
</dependencies>

Add base URL to arquillian.xml

The arquillian.xml file provides configuration necessary to setup Arquillian. Since we won't have a deployment, we need to provide the base URL for our tests. The arquillian.xml file goes in the src/test/resources directory.

<arquillian>
  <extension qualifier="graphene">
    <property name="url">https://blog.mikesir87.io/</property>
  </extension>
</arquillian>

Create the test case

Now, it's time to create the actual test case.

@RunWith(Arquillian.class)
public class BlogTest {

  @Drone
  private WebDriver browser;

  @ArquillianResource
  private URL baseUrl;

  @Test
  public void testTagCloud(@InitialPage HomePage homePage) {
    // Add your test code here...
  }
}

As is the case for non-standalone tests, the browser and baseUrls properties are injected by the testing framework.

Write your test

Since this is only a writeup on how to get to this point, I won't go into the actual test writing. But, I am planning on having a post soon about some of the "best practices" I've developed in regards to functional testing. So… stay tuned!