A Fluent API for browser Automation: Fluent Automation API for Selenium WebDriver

I spent sometime this weekend playing around WebDriver  API, I got the package from NuGet. At the time of installing the package, I realize there was another package named FluentAutomation API


But what is FluentAutomation anyway?

FluentAutomation is a  DSL(DSL stands for Domain Specific Language), which is a kind of programming language that helps to deal with some specific problems. An example of this Technology can be found at the heart of the O2 Platform , which uses  FluentSharp.

This API offers a set o methods that makes easy to interact with the browsers and most of the  expectations can be performed via Lambda Expressions , which  makes easy to write and read the code.

In this same line, FluentAutomation allow us to select in what browser(aka user agent) the test needs to be executed. It is easy to customize at the test level:

//If you want to run the test in IE
FluentAutomation.SeleniumWebDriver.Bootstrap(browser: SeleniumWebDriver.Browser.InternetExplorer);
//If you want to use Chrome instead
//or if you want to run the test in Firefox

As you can see here, just adding that sentences at the very top of the test, it automatically leads to execute the test in the browser selected. The below code shows how to use expectations and waits using lambda expressions:

private void TmLogin()
 I.Expect.Url(x => x.LocalPath.ToLower().Contains("teammentor"));
 //It waits until the div is displayed
 I.WaitUntil(() => I.Expect.Exists("#topRightMenu"));
 //Expected text in the div
 I.Expect.Text(x => x.Contains("Login")).In("#topRightMenu");
 //Taking a screen

The Capability of  saving Screenshots
This FluentAutomation API provides the capability of taking Screenshots of certain process or pages that you would like to capture (really powerful for documentation purposes), this operation can be performed by using or invoking the TakeScreenshot method. In order to create a pattern of usability I’ve created a base class (from where all the test classes inherit from) and I’ve specified the current path where the images should be stored (currently this is a hardcoded string but it can be a configuration value). Look at the following code:

public class BaseTest : FluentAutomation.FluentTest
  public void TakeScreenShot(string imageName)
     Settings.ScreenshotPath = @"C:\Results\SampleTestSuite";
     Settings.ScreenshotOnFailedExpect = false;
     Settings.ScreenshotOnFailedAction = false;
     Settings.DefaultWaitTimeout = TimeSpan.FromSeconds(1);
     Settings.DefaultWaitUntilTimeout = TimeSpan.FromSeconds(30);
     Settings.MinimizeAllWindowsOnTestStart = true;

We can take a Screenshot of the current process at anytime just by invoking that method. The following image has been taken following this approach:

Login Screenshot

Found Issues

I found an Issue using this API and Internet Explorer, for some reason this API cannot find  the div in the DOM when it has been rendered via IE, I got a time out in  the Wait method (The default time out seems to be 30000ms).


Then I opened an issue in their repository at GitHub, and I started to receive feedback:

Issue at GitHub

It seems like this could be a good tool to be used, hopefully those guys can fix the issue 🙂


About Michael Hidalgo

Michael is a Software Developer Engineer based on San José, Costa Rica. He leads the OWASP Chapter from Costa Rica. You can take a look at my blog at http://blog.michaelhidalgo.info/
This entry was posted in UnitTests and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s