If you haven’t read my previous blog post about test automation or aren’t familiar with Regression Automation, it might be a good idea for you to get up to speed on that before reading this piece. So now we understand a bit more about Automation. How about Eggplant? What is it? How can it be used?
I’ll start a line from some of their product marketing. Eggplant Functional is a “GUI automation and software testing product.” You probably know that GUI means Graphic User Interface, but how does that apply to a software testing tool? It provides a way to automate items that appear graphically. The interface provided to an end user of a software product is typically some mixture text and images, which are both graphic components. The images can range from a company logo to a drop down menu to select options on a web form. The text can range in size, color and shape (font), but ultimately, text is an image as well.
If your software product is designed to give a human being an interface to interact with… on a Website, Tablet, Smartphone, Desktop Application, or any combination of these, Eggplant Functional gives you a way to build automated tests that will ensure the quality of your product.
Eggplant can automate just about anything you interact with on a screen. If you can see it on a screen, you can use the element to automate and/or to validate. Eggplant can find images and even read text to help drive or validate tests. This means that Eggplant doesn’t rely on any underpinnings in your source code, instead, it is used to test the results of the interactions amongst all of that code.
Like most Quality Assurance testing, there are many different levels you can test to. The Eggplant scripting language is simple enough that it gives beginners and novices the ability to create linear scripts that do a number of things in a particular order. For more advanced applications and QA resources, it can be used to build an expansive library of scripts that interactively call to each other for different combinations of functionality to be tested. The modular nature of this method provides flexibility in testing and functional test expansion.
Write Once, Run Anywhere
One of the best features of Eggplant is that you can write one test, and run it on multiple platforms and/or browsers. If I needed to test that your “Contact Us” form elements appear for every browser that your company chooses to support, I can write one script that will connect to a number of different devices, launch any number of browsers and verify that all of the fields appear and function.
Let’s look at an example of what we could do with Eggplant on our Portland Webworks site. A simple linear Eggplant script would test that the header of our site appears at the top of the home page. To set this up, I’d need to capture an image of the header and the URL Field for my browser. Eggplant has a simple way to capture these images and writing the script at the same time. It’s not record-and-run functionality, but it’s close.
Here’s what the script would look like. Notice how human-readable the language is (comments are in green).
Click “URLField” // clicks [the area that matches the picture of] where we need to type
Typetext “Portlandwebworks.com”, “Enterkey” // Types the url and the enter key.
Click “PortlandwebworksLogo” // Clicks the home navigation link.
if imagefound(8, “PortlandWebworksHeader”) // waits up to 8 seconds for the PortlandWebworksHeader image to appear
logsuccess “Our header loaded successfully using the PortlandwebworksLogo link” // log a success in the run log
logwarning “Eggplant was unable to find our header using the PortlandwebworksLogo link. See the screenshot in the log” // log a warning
capturescreen(Name: “MissingHeader_PortlandwebworksLogo” ) // capture a screenshot so we can see what was wrong
A Better Way:
Currently, at the time of this writing, our site has 7 links at the top. The Portland Webworks Logo, Company , Blog, Services, Clients, Careers and Contact. In a linear script, I could copy and paste the above script 7 times, and change the:
Click “PortlandwebworksLogo” to Click “Company” , then to Click “Blog” etc, etc.
We would end up with a lot more code than is necessary, as it would be redundant with only one change in each section. A slightly more powerful way to write this test would be to iterate through each of the links. This allows us to write the code block once and reuse it by using a repeat:
Click “URLField” // clicks where we need to type
Typetext “Portlandwebworks.com”, “Enterkey” // Types the url and the enter key.
repeat with each item in (“PortlandwebworksLogo”,”Company”,”Blog”,“Services”,“Clients”,“Careers”,“Contacts”) // will use this list to iterate through
Click it // This is where we’re clicking on each of the navigation links to see if the header is appearing on every page. “it” refers to the variable in the iteration.. the first one will be PortlandWebworksLogo, the second will be Company, then Services etc.
if imagefound(8, “PortlandWebworksHeader”) // waits 8 seconds for the PortlandWebworksHeader image to appear
logsuccess “Our header loaded successfully using the link: ” & it // log a success in the run log. Remember, “it” would be replaced by the PortlandwebworksLogo in the log for the first iteration.
logwarning “Eggplant was unable to find our header using the “& it &” link. See the screenshot in the log” // log a warning
capturescreen(Name: “MissingHeader_” & it ) // capture a screenshot so we can see what was wrong. In the first iteration, this would create a screenshot named “MissingHeader_Portandwebworkslogo”
To do the same thing, we could also use a container (a single variable that contains multiple items) to iterate through. Although we’re getting slightly more technical here, but I’ll still keep it a light post.
put (“PortlandwebworksLogo”,”Company”,”Blog”,“Services”,“Clients”,“Careers”,“Contacts”) into TopNavLinks //store these in the TopNavLinks container
We could also store the items in another script, property file or text file (this would be ideal if items were expected to change often).
Set TopNavLinks to MyTopNavLinks.script
In either of the above cases, our repeat would then start with :
repeat with each item in TopNavLinks
We could take this to another level by iterating through multiple containers. If we had different Bottom Nav links, we could put them each into their own container.
repeat with each item in (TopNavLinks, BottomNavLinks)
Note: I don’t want to get too technical at this point, but in the above example, we would likely need to do a few things in-between each container.
My next blog post will contain more advanced scripting examples. There are a number of more powerful scripting features that make Eggplant far more extensible. Some Eggplant features:
- Read and write to local files
- XML (with XPath)
- Iteration Loops (like the Repeat loop above)including Repeat while(boolean value) and Repeat for (Time Span, or number of repeats)
- Passing parameters
- Storing local, global and universal variables
- Basic math
- Capturing movies (helpful in documenting failures)
For anything Eggplant doesn’t support natively, since it supports clicking on anything in a GUI, there are a number of ways that other programming or scripting methods can be used to augment it. For example, you can write a shell or batch script that performs an action to help set up or run a test. Eggplant can run shell and batch scripts natively, but alternatively, you could make it executable and tell Eggplant to double-click it. I have used this to clear preferences / caches of applications before they launch so they load fresh from the start.
For Developing and executing scripts, Eggplant will run on a PC, Mac or Linux computer. For testing, it can run tests on just about any platform including: Mac, PC, Linux, iPhone/iPad, Android
There’s a lot more information on the Eggplant site.
Stay tuned for more advanced examples in my next blog post.
- 12 May 14
- Posted by Brett Amundsen