Selenium with Arquillian as Maven project

Today we will try to test google.com page by Selenium. You can see structure of environment on following picture:

Selenium server installation

We will start by Selenium server which is connected to browser. In my example is used Internet Explorer. 
Download Selenium server from Selenium. It will be only simple jar like selenium-server-standalone-2.35.0.jar. Next we need WebDriver driver for IE. It is under "The Internet Explorer Driver Server" on the same page. You will download IEDriverServer_Win32_2.35.1.zip file, which contains IEDriverServer.exe.

Copy both files into one directory and create starting script, for example start.bat:

SET JAVA_HOME="c:\progra~2\Java\jdk1.7.0_17"
java -jar selenium-server-standalone-2.35.0.jar -Dwebdriver.ie.driver=IEDriverServer.exe -port 14444

Start server by created script. Result can be something like:

You can see line with Selenium server URL in console:
INFO - RemoteWebDriver instances should connect to:
We will use it later. Server side is ready.

Create Maven project

Now we need some test. Create directory structure. Maven can help you:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart
 -DgroupId=com.mil -DartifactId=selenium-test -Dversion=1.0.0

Create class GooglePage.java under src/test/java/com.mil.selenium.page. This class represents "Page Object" pattern so it models page (Google.com) to object.

package com.mil.selenium.page;

import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class GooglePage {

 @FindBy(name = "q")
 private WebElement search;

 public void search(String query) {
Next class is TestNG test which will call Page Object class.
package com.mil.selenium.test;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.graphene.spi.annotations.Page;
import org.jboss.arquillian.testng.Arquillian;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

import com.mil.selenium.page.GooglePage;

public class GoogleTest extends Arquillian {
 GooglePage page;

 private WebDriver driver;

 public void testSearch() {
  try {
     .setScriptTimeout(Integer.valueOf(10), TimeUnit.SECONDS);
     .implicitlyWait(Integer.valueOf(10), TimeUnit.SECONDS);
     .pageLoadTimeout(Integer.valueOf(10), TimeUnit.SECONDS);


   page.search("test query");

   List resultOfSearch = driver.findElements(By
   Assert.assertTrue(resultOfSearch.size() > 0);
  } catch (Exception e) {


 public void afterClass() {

Check testSearch() method. We open Google page, enter some query and check if there is some result. Simple.

If you want to close Internet Explorer browser after test, you need to call driver.quit(). See afterClass() method.

This test class cannot be started without Arquillian configuration. The following file is located in:

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"

 <!-- Uncomment to have test archives exported to the file system for inspection -->
 <!-- <engine> -->
 <!-- <property name="deploymentExportPath">target/</property> -->
 <!-- </engine> -->

 <!-- Force the use of the Servlet 3.0 protocol with all containers, as it 
  is the most mature -->
 <defaultProtocol type="Servlet 3.0" />

 <!-- Example configuration for a remote JBoss AS 7 instance -->
 <container qualifier="jboss" default="true">
  <!-- If you want to use the JBOSS_HOME environment variable, just delete 
   the jbossHome property -->
  <!-- configuration>
   <property name="jbossHome">PATH_TO_JBOSS</property>

 <extension qualifier="webdriver">
  <property name="browserCapabilities">internetExplorer</property>
  <property name="javascriptEnabled">true</property>
  <property name="remoteReusable">true</property>
  <property name="remoteAddress">http://localhost:14444/wd/hub</property>

 <extension qualifier="graphene">
  <property name="waitAjax">5</property>
  <property name="waitGui">5</property>
  <property name="waitModel">10</property>

 <!-- this is because of the dependency on testng-listener containing graphene 
  and drone, which automatically starts selenium server -->
 <extension qualifier="selenium-server">
  <property name="skip">true</property>


You do not need to change anything in this file. Only remoteAddress if you have Selenium server on different computer (mentioned previously).

Test run

Now you can test it. Try it by:
   mvn clean test

Your test will conect to configured Selenium server which will open Internet Explorer browser for your test.
Any issues? Ask please.

Maven project to download: selenium-test.zip
▼ Click here to say thanks ▼

1 comment :

  1. I've just looking for running Arquillian tests against a running site. This code just nicely does the work. Thanks!
    Note: there is a issue with version of test-ng specified in pom.xml. Prefer use 5.14.6 version as helpfully mentioned there: https://community.jboss.org/message/596290