Show menu Show popup Search

Automated Testing that’s Easy on the Eyes

Let me introduce myself as a new contributor to this blog. I’m Doug Simons, one of the founding developers of eggPlant Functional. I’ll be contributing occasional posts here, sharing some thoughts about testing with eggPlant with an emphasis on the SenseTalk scripting language, which is of particular interest to me as the primary designer of the language.

Making Testing Easy

In creating eggPlant one of our main goals has always been to make your life as a tester as easy as possible. Scripts are at the heart of everything you do with eggPlant so we do what we can to make the process of creating, running, modifying and maintaining scripts as easy as possible. Much of what we do involves adding or improving features related to working with scripts, such as the new tabbed editor introduced in v12, or the autocompletion of terms within a script added for Windows and Linux users in v14. Expect to see more enhancements in the script editor in the future, to make your job of editing scripts even smoother and simpler.

In addition to helpful features for working with scripts, another aspect of eggPlant designed to make your life easier is the SenseTalk language itself. SenseTalk is an unusual scripting language in the level of flexibility it offers and the degree to which it resembles plain English. At first glance, some experienced programmers see the English-like “wordiness” of SenseTalk and mistakenly assume it must be a lightweight language without much depth. In fact, SenseTalk offers many high-level features that provide a considerable breadth and depth of capability without sacrificing a script’s readability.

In this and future blog entries, I’ll take a look at some of the ways that the SenseTalk language makes your job of creating and maintaining test scripts easier.

Intuitive Scripting

SenseTalk was designed to be an “Intuitive” scripting language. The first and most fundamental aspect of an intuitive language is that it must be easily readable, ideally even by someone unfamiliar with the language.

Readability provides a lot of benefits. When it’s easy to read a script that you write, it’s easier for someone else to see and understand what the script does (or for you to remember what it does, if it’s been a while since you wrote it!). Because it’s easier to understand, it’s also much easier to maintain the script when adjustments are needed.

Here’s a little sample. See if you can understand what it does.

Image 1

Okay, that was a silly contrived example that doesn’t really show much (well, it shows the number 42, but that’s not very interesting). Even this simple example illustrates a couple of points, though. It uses ordinary words and language, avoiding the use of special symbols that might not be understood by a newcomer. That makes it easy for anyone to follow, even if they’ve never met a programming language in their life.

Here’s another contrived example, but this is a much more complex (and interesting!) one that could represent an actual testing scenario. Take a minute to see if you can figure out what it does before you read the description that follows.

Image 2

Hopefully even if you never saw a SenseTalk script before you could get at least some idea of what’s being done here. First we record the current time at the start of the test, define a region of the screen where eggPlant will be searching, and initialize a counter to zero.

Then we get to the interesting part. The everyImageLocation() function gets a list of all of the locations where a given image appears on the screen. Here we’re looking for an image called “goldfish”. Because we defined a searchRectangle earlier, we’ll only get the locations of goldfish found within that region, not everywhere on the entire screen. In this test we don’t care where the goldfish are within that area, only how many are found, so we ask for the number of items in the list.

The script adds the number of goldfish to the count. Then, if the number seen wasn’t zero we wait briefly (presumably to give the goldfish time to swim around a bit before we look again). We do this repeatedly, looking for goldfish until we’ve counted at least 10 of them. Then the script calculates how much time has passed while we were looking and counting, and logs a message giving us the total count and how long the test took.

So how did you do? Were you able to follow what the script was doing before you read the description? Now, suppose you were given this script and told that instead of counting and timing the appearance of the first 10 fish, it should be changed to count the number of fish that are seen in the pond within 30 seconds.

Fortunately for you, SenseTalk makes that easy too, without making the script any harder to read. Just change the repeat line to say:

Image 3

I hope this example has helped make clear the value of readable test scripts. In writing this script I paid particular attention to making it easy to read. You may not find every test script to be quite so easy to follow. Well-written SenseTalk scripts can read very much like English statements; those written poorly can be much harder to understand.

Keep it Readable

As you write your own scripts, it’s a good idea to keep the readability of your scripts in mind. Will it be easy for someone else who looks at your script to understand what it’s doing? Will it be easy for you understand six months from now when you need to update the test?

Imagine a scenario where your boss hands you a test script, written months earlier by someone else who has since left the company, and asks you to make some changes. If it’s written in a readable style you’ll probably be very grateful that you can understand it quickly without a lot of wasted effort.

Until next time… happy scripting!

No comments

Leave a Reply