You are on page 1of 4

Automated Tests with Maximo and Selenium WebDriver

Google has created a new test automation tool, called Selenium WebDriver (and
Remote Webdriver). It is a very strong, and yet light, tool for scripting automated test
cases. With a simple configuration (described below), you are able to start scripting,
using Selenium’s methods to handle the application’s UI. This tool is free and supports
many kinds of web browsers and operational systems.
Talking about the differences of WebDriver and Remote Webdriver, the
WebDriver class is used for stand-alone tests, on a single computer, it executes one test
case at a time (no parallelism) and it supports Internet Explorer (IE), Firefox (FF) and
Google Chrome browsers. When working with Xpath, you should be aware that many
applications may render the UI in different ways among these browsers, so a specific
Xpath may work on a browser, and fail on another. The Remote WebDriver has the same
features as the previous one, plus the ability to be executed remotely and in parallel in
other computers or VMs. You can find more about Remote WebDriver at
https://code.google.com/p/selenium/wiki/Grid2. Since the Selenium driver is a .jar file, it
is not restricted to Windows only; it also works on Linux, without any kind of
adjustment.
Selenium is a free tool, widely used in the software development comunity, which
can be easily downloaded and installed in an existing Eclipse environment. There are
plenty of tutorials about how to install and configure your Eclipse/Selenium environment.
Here follows the basic steps:
1. Download and install Java (JDK) from Oracle website.
2. Download Eclipse from Eclipse.org. It doesn’t need to be installed, just run
eclipse.exe.
3. Download and install the Selenium Java WebDriver.

4.
5. Downloaded 'webDriver Java client driver' will be in zip format. Extract and
save it in your system at path C:\selenium in case your environment is
windows, or <root>/selenium in linux. There will be 'libs' folder, 2 jar files
and change log in unzipped folder as shown in bellow figure. We will use all
these files for configuring webdriver in eclipse.
6. Open Eclipse and click on File > New Project > Java Project. Name it the
way you want.
7. Right click on you Project and select New > Package. Name it the way you
want.
8. Right click on the new Package and select New > Class.

Ok, so far your Java environment is ready. Now let’s configure Selenium
webdriver in the Eclipse environment:
1. Right click on you project and select Properties > Java Build Path >
Libraries (tab).
2. Click on Add External Jars button. Select both .jar files from
<root>\selenium. Deleted: C:
3. Click on Add External Jars button. Select all .jar files <root>\selenium\libs. Deleted: C:
That’s all about configuring Selenium.
If you want to use Google Chrome as your test browser (which I recommend),
you will need to download the Chrome driver at http://docs.seleniumhq.org/download/:

In order to initiate a new Selenium WebDriver test, you should start your script by
these commands:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class TEST {

/**
* @param args
*/
public static void main(String[] args) throws InterruptedException{

WebDriver driver = null;


System.setProperty("webdriver.chrome.driver",
"C:/ChromeDriver/chromedriver.exe");
driver = new ChromeDriver();
driver.get("your URL");

WebElement userName =
driver.findElement("//input[@name='username']");
userName.sendKeys("wilson");

}
These commands will initiate the Webdriver, define Chrome as you test browser,
open the browser and navigate to your page.
Selenium has a very powerful element search method, called Xpath. It performs
the search for an element by browsing the html code and saving its position among the
html tags (<tr>, <td>, <div>, etc.). It is possible to use several attributes from a single
element in order to identify it (.alt, .src, .id, .text, .class, etc). Xpath can vary from a very
simple statement, to a very complex statement. Here are some examples of how to
indentify an element:
1. This simple path can be used to find the User Name text field in the login
screen: //input[@name='username']"
2. This complex path can be used to find an element as well:
/html/body/table[2]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/div/t
able/tbody/tr/td/div/table/tbody/tr[2]/td/table/tbody/tr/td/div/table/tbody/tr[3]/td/table/tbo
dy/tr/td/div/table/tbody/tr/td[2]/div[2]/input
Learning how to write an Xpath can be a little tricky at first, but it is one thing
that you can get good at really soon. There are also tools that help to extract xpaths, such
as Firebug (Firefox plug-in) and Xpath Helper (extension for Chrome). There are also
other sources in the internet that can help a lot the beginners.
After identifying the elements, Selenium provides the capability to write, get
value, click, right click, drag, swipe, etc. On preliminary tests, all UI elements from
Maximo could be identified and manipulated.
Applying Selenium into Maximo: As we all know, Maximo has a very singular
user interface, which is not compatible with most search mechanisms existent in the
market. Its elements have dynamic ID’s (until version 7.5.x.x), that breaks the search
methods, and a simple record/playback tool is not enough to record test scripts. Most of
the existing automation tools use the .id property of elements, and that just doesn’t work
with Maximo.
Thinking about the Maximo user needs, in order to test a new hotfix or execute a
test routine, which consumes precious time and money, the product’s test team has been
studying new ways and tools to make Maximo automation easier and usable. Selenium
fulfilled those needs. It works nicely with Maximo. Selenium has a set of search tools
that covers Maximo’s needs, such as by element’s name, id (for those objects whose .id
propery is known and static), and specially, by Xpath.
All objects existent in the xml presentation can be found by Xpath locator, and
one of the best things about Selenium is that it is 100% Java. You can write the scripts
the way you want, it will be compatible with other tools, it can be executed remotely, you
can configure everything the way you want, with zero purchasing cost.
Attached there is a fully commented script that can be used as reference. It logs
into Maximo, click on Go To menu, Assets module, Assets application, Create a new
simple Asset record, save and sign out. Before executing it, all the configuration above
must be done previously, and the Maximo environment must be using the default skin. If
the script is not able to find any of the elements and throw and error message, search for
the line indicated in the Eclipse console, and re-capture the element Xpath. It may vary in
different environments.
Quick explanation about the script’s structure:
Section 1: This is where all the UI elements are mapped. In this script, I mapped all of
them using the Xpath locator. If you prefer, you can use By.id(), By.name (if you
environment supports these type of locators).
Section 2: Created the Selenium WebDriver instance that will be used across the entire
script.
Section 3: Created some methods to facilitate the test case writing. Such as setText(),
waitForElementDisplayed() and clickOnObject().
Section 4: It is the Test Case itself. It calls the methods created on section 3 in the order
that the scenario requires.
Section 5: Java requirement. Main method, with the class instantiation. Also a command
line to specify where the Chromedriver.exe is located on your machine. Just click on the
Play icon in your Eclipse, and watch the test case being executed. If any error is caught,
the stacktrace will be displayed in the console, with the exact line where it failed.

Now you are ready to start writing automated test scripts using Selenium
WebDriver. You can do almost everything in Maximo with the basic commands
presented in this article. You easily map the objects once, and will only have to re-map if
there is any major change in the UI. You can structure you framework the way you want,
by using Java tools. There are plenty of comments, suggestions, tutorials in case you need
to use some advanced feature. Since it is a Java file, you can always create a .jar file and
execute it everywhere, cost free. The more scripts you have, the more elements you have
mapped, then writing new scripts will consist only in calling methods already existent in
the order you want.

You might also like