Site icon Vinsguru

Selenium WebDriver – Blackbox Automated Testing using Arquillian Framework

I have been using Arquillian Graphene framework for more than a year for automated functional testing using Selenium WebDriver. I absolutely LOVE this framework. It is so easy to use and really helpful to keep your tests neat and clean by maintaining the test config in a separate file, by injecting the resources at run time when it is required etc.

 

What is Arquillian?

Arquillian is an integration/functional testing framework for testing JVM based application. It nicely integrates with other testing frameworks like JUnit/TestNG and helps to manage life cycle of the test and provides many other useful extensions. For functional browser automation, Arquillian provides Drone and Graphene extensions – both are built on top of Selenium WebDriver.

Arquillian is simply an extension to JUnit/TestNG frameworks. So If you already use JUnit and TestNG, you can just inlcude Arquillian w/o affecting your tests. Drone is for WebDriver managementGraphene is a wrapper around WebDriver with very nice utilities. So when you use all these, you do not miss any existing features of Junit/testNG/Selenium/WebDriver. You can add the jars and continue not to use any features of Arquillian Graphene if you do not like. Ie, your old code will still work fine. It does not force you to do anything! But please give sometime and You will love it!! [ It took some time for me 🙂 ]

Initially it was a bit hard for me to understand how it works as it was very confusing and I failed few times in finding all the maven dependencies to make it work. I am going to make it easy for you by showing you a very simple ‘Google Search’ project using Arquillian [the client mode].

 

Test run Modes:

Arquillian can run the tests in below modes.

Drone:

Drone is an Arquillian extension to manage the life cycle of the browser in the Arquillian tests. It helps to keep all the browser related test configuration in a separate file called ‘arquillian.xml’ outside of the java code. Drone simply takes care of WebDriver instance creation and configuration and then it delegates this session to Graphene.  Check here for more info.

Graphene:

Graphene is designed as set of extensions for Selenium WebDriver that focuses on rapid development and usability in Java environment. It has below nice features.

Lets create a simple project for WebDriver automation using Arquillian Grpahene.

Maven Dependency:

Include below mvn dependencies to bring the power of Aruqillian graphene into your existing Java-Webdriver automation framework. [I used TestNG extension for Arquillian framework. You can also use the JUnit extension]

Creating a simple Arquillian Project: 


@Location("https://www.google.com")
public class Google {

    @Drone
    private WebDriver driver;

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

    @FindBy(name = "btnG")
    private WebElement searchbutton;

    @FindByJQuery(".rc")
    private List <WebElement> results;

    public void searchFor(String searchQuery) {

        //Search
        searchBox.sendKeys(searchQuery);

        //Graphene gurads the request and waits for the response
        Graphene.guardAjax(this.searchbutton).click();

        //Print the result count
        System.out.println("Result count:" + results.size());

    }
}


@RunAsClient
public class Test1 extends Arquillian{

	  @Test(dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER)
	  public void googleSearchTest(@InitialPage Google GooglePage) {
		 GooglePage.searchFor("Arquillian Graphene"); 
  }
}


Arquillian Graphene Features:

 
   @FindByJQuery("a") 
   private List<WebElement> allLinks; 
   
   @FindByJQuery("a:visible")
    private List<WebElement> allVisibleLinks; 

@RunAsClient
public class NewTest extends Arquillian {
	
	@Page
	Login LoginPage;
	
	@Page
	Search SearchPage;
	
	@Page
	Order OrderPage;
	
	@Test
	public void f() {  
		LoginPage.LoginAsValidUser();
		SearchPage.searchForProduct();
		OrderPage.enterPaymentInformation();
		OrderPage.confirmOrder();  
	}
}

Summary:

We saw the basic features of Arquillian Graphene framework and how it makes our test more readable with its browser and page objects injection on the fly and handling the HTTP/AJAX requests etc.

To know more check more posts under ‘WebDriver‘ category of this site.

Ex: How can we create a page object which requires less maintenance?

Check here for the answer : http://www.testautomationguru.com/arquillian-graphene-page-fragments/

 

Happy testing 🙂

Share This:

Exit mobile version