Posted on

Selenium IDE Running Suites of Suites

Selenium Add On Banner

For over a year now I’ve been running over a dozen Selenium IDE test suites every time I update the Store Locator Plus base plugin.  It is a manual process that is time consuming, though less consuming than manual testing by several orders of magnitude.   Today I learned how to be even more efficient with my time, which my forthcoming customer support and QA team will hopefully appreciate when they come on-board this summer.

Here is the Stack Overflow summary I posted on my automated “suite of suites” process which took me several days of searching and testing to discover.

I have a few dozen test suites built in Selenium IDE to assist with testing my Store Locator Plus WordPress plugin. Sometimes I need to run a single Selenium test suite. However when I release a new version of the base plugin I want to run a dozen test suites one-after-another.

While not a perfect fit for your use case of creating several “master suites”, I did find a pair of Selenium IDE plugins that allow me to create a single “favorites list of suites” and run all of my favorites back-to-back.

It may be possible to investigate & modify the plugin JavaScript to create several different “favorites lists” that may suit your needs. In the meantime you can get at least one “master list of suites” by combining these Selenium IDE add-ons:

After installing each of these add-ons (technically Mozilla Firefox plugins) you will see a favorites button inside the Selenium IDE interface. Mark your favorite suites and you will have your “list”. You can now select “Favorites / Run All” from the Selenium IDE menu.

You may want to be careful about the sequence in which you mark your favorites. I marked them in the order I wanted them to run. Open test suite #1, favorite, test suite #2 favorite etc. then “run all”. Worked great and shows me the total run count and fail count across all suites (and thus tests) that were executed. The log, sadly, appears to be reset at each suite however.

Posted on

Selenium IDE Includes AKA “Rollups”

Selenium IDE is used extensively to test the Store Locator Plus family of plugins.    As the testing continue to expand so do the rules being tested.   Today the addition of a rule that checks that the PHP notice “use of undefined constant” needed to be added.     There is an existing set of other PHP warnings and notices that was added last month that is in 30+ Selenium Scripts.  They were all copied by hand into each test.

Now I need to add one more rule to that test set.   Copy and paste into 30 files?  There HAS to be a better way.

Turns out there is a better way, but it requires a little JavaScript coding to make it happen.   Selenium IDE does not have an “include <file>” option in the base set of commands.   Personally I think they need to add it to the base command set as it will make it far easier for people to write “test subsets” and then include them in every test.    The solution is using something called a “rollup”.    A rollup is a label for a group of commands you want to execute in many places in your test scripts.

My original test suites looked something like this:

Selenium Test for PHP Warnings
Selenium Test for PHP Warnings

In the “old days”, yesterday to be precise, I would copy-and-paste this set of Selenium IDE tests into a LOT of test files.

Today I decided to be smart about it, happens every now-and-then… must be a full moon or something, and find out how to to an “include” of those commands.   The trick is to create a file called something like “rollups.js”.     My file is called slp_rollups.js.     It is a standard JavaScript file that I place in the same directory as all of my Selenium IDE test scripts (which happen to be nothing more than HTML snippets).

To replace those 4 commands with a rollup I created this slp_rollup.js file:

/**
 * For use in Selenium IDE.
 *
 * You will need to add this to Selenium under Options / Options in the Selenium Menu.
 * Put this under Selenium Core Extensions:
 * ~/selenium-ide-for-slp/sideflow.js , ~/selenium-ide-for-slp/slp_rollups.js
 *
 *
 */
var manager = new RollupManager();


/**
 * check_for_syntax_errors
 *
 * This rollup tests for php syntax errors, warnings, and notices.
 */
manager.addRollupRule({
    name: 'check_for_syntax_errors',
    description: 'Check for PHP syntax errors, notices, warnings.',
    args: [],
    commandMatchers: [],
    getExpandedCommands: function(args) {
        var commands = [];

        commands.push({
            command: 'assertNotText',
            target: '//body',
            value: '*Notice: Undefined*'
        });

        commands.push({
            command: 'assertNotText',
            target: '//body',
            value: '**Notice: Trying to get*'
        });

        commands.push({
            command: 'assertNotText',
            target: '//body',
            value: '*Notice: Use of*'
        });

        commands.push({
            command: 'assertNotText',
            target: '//body',
            value: '*Fatal error:*'
        });

        return commands;
    }
});

To activate this I update Selenium IDE by going to Options/Options and adding this new slp_rollup.js file to the Selenium Core Extensions. Since I also use the sideflow.js file to provide Go To / If and other looping constructs I add both sideflow.js and slp_rollups.js to my extensions list by separating the file names with a comma.

Selenium IDE Options
Selenium IDE Options with sideflow and slp_rollups enabled.

Now I can replace that block of 4 commands with the following single command in ALL 30 scripts. The best part is the next time I need to add another test for a new warning or error I only edit ONE file, the slp_rollups.js file which means less editing, less copy & paste, and less commits to the git repository.

Selenium IDE Implementing Rollups
Selenium IDE Implementing Rollups
Posted on

Adding gotoIf and other Flow Control to Selenium IDE

selenium ide

Some of my Selenium IDE test scripts make use of the gotoIf command.   Flow control logic like the gotoIf and label statements are not part of the standard Selenium IDE core library.   Like most apps these days, Selenium IDE has a method for extending the base functionality with plugins and core extensions.   The “sideflow” core extension from darenderidder is an extension that provides the oft-referenced goto controls for Selenium IDE.

Adding sideflow Flow Control To Selenium

I like to keep current with any repository updates, so I use git to clone the repository into my documents folder on my Vagrant WP Dev Kit CentOS box.    Using SmartGit I clone via the github URL:

https://github.com/darrenderidder/sideflow.git

Open Selnium IDE, go to the Options menu and select options.  Under the Selenum Core extensions browse to the sideflow.js file that was cloned via git.

Installing Selenium IDE SideFlow Extension
Installing Selenium IDE SideFlow Extension

The other option is to just download the sideflow.js file here.   No promises or guarantees this is current or will work on every system.  You should really grab the code from the source.

Example Selenium IDE Script

Here is an example script that uses flow control to ensure only ONE Store Locator Plus locations page is added. If the page already exists it skips the page setup process on my test site.

<tr><td rowspan="1" colspan="3">SLP - Add Page, SLPLUS</td></tr>
</thead><tbody>
<tr>
	<td>setSpeed</td>
	<td>200</td>
	<td></td>
</tr>
<!--Open WP Pages Interface-->
<tr>
	<td>open</td>
	<td>/wp-admin/edit.php?post_type=page</td>
	<td></td>
</tr>
<tr>
	<td>waitForElementPresent</td>
	<td>id=doaction2</td>
	<td></td>
</tr>
<tr>
	<td>storeElementPresent</td>
	<td>xpath=//table[@class='wp-list-table widefat fixed pages']//td[@class='post-title page-title column-title']//a[contains(text(),'Locations')]</td>
	<td>slplus_page_exists</td>
</tr>
<tr>
	<td>gotoIf</td>
	<td>storedVars['slplus_page_exists']</td>
	<td>SKIP_LOCATION_PAGE_CREATION</td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>css=a.add-new-h2</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>id=title</td>
	<td>Locations</td>
</tr>
<tr>
	<td>click</td>
	<td>id=content-html</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>id=content</td>
	<td>[[slplus]]</td>
</tr>
<tr>
	<td>waitForElementPresent</td>
	<td>id=publish</td>
	<td></td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>id=publish</td>
	<td></td>
</tr>
<tr>
	<td>label</td>
	<td>SKIP_LOCATION_PAGE_CREATION</td>
	<td></td>
</tr>
Posted on

Selenium IDE Script for New WordPress Site Setup

selenium ide

I use Selenium IDE as a testing tool for WordPress plugins.  It provides basic testing of the user interface elements via a record-and-playback browser script.   However, there is another use for tools like Selenium IDE; automation of repetitive web tasks.   On every build I reset my WordPress install and build a new site.   The setup form is short, but it is something I do at least once every week and answer the same half-dozen questions the same way.

The script shown below is my Selenium IDE script that sets up the website and activates a few plugins I know I am going to want on every site setup.   The script prompts for the admin password during execution.  Other than that it is hands off.    As for the plugins, they are already in my wp-content/plugins sub-directory.  You will need to modify the checkbox IDs and email address to implement this effectively on  your WordPress development and testing servers.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://localhost/" />
<title>New SLP Install</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New SLP Install</td></tr>
</thead><tbody>
<tr>
	<td>setSpeed[box type="info"]Determines how fast the test script runs.  Delay between commands in ms.  0 (fast) is the default.  Slow is 900.[/box] </td>
	<td>200</td>
	<td></td>
</tr>
<tr>
	<td>open</td>
	<td>/wp-admin/install.php</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>id=weblog_title</td>
	<td>SLP Dev</td>
</tr>
<tr>
	<td>storeEval</td>
	<td>prompt(&quot;Password&quot;)</td>
	<td>password</td>
</tr>
<tr>
	<td>type</td>
	<td>id=user_login</td>
	<td>admin</td>
</tr>
<tr>
	<td>type</td>
	<td>id=pass1</td>
	<td>${password}</td>
</tr>
<tr>
	<td>type</td>
	<td>id=pass2</td>
	<td>${password}</td>
</tr>
<tr>
	<td>type</td>
	<td>id=admin_email</td>
	<td>your...email...here</td>
</tr>
<tr>
	<td>click</td>
	<td>name=blog_public</td>
	<td></td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>name=Submit</td>
	<td></td>
</tr>
<tr>
	<td>open</td>
	<td>/wp-login.php</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>id=user_login</td>
	<td>admin</td>
</tr>
<tr>
	<td>type</td>
	<td>id=user_pass</td>
	<td>${password}</td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>id=wp-submit</td>
	<td></td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>//li[@id='menu-pages']/a/div[3]</td>
	<td></td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>link=Edit</td>
	<td></td>
</tr>
<tr>
	<td>type</td>
	<td>id=content</td>
	<td>[slplus]</td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>id=publish</td>
	<td></td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>link=Installed Plugins</td>
	<td></td>
</tr>
<tr>
	<td>click</td>
	<td>id=checkbox_a55f1e83ab4fee1b42772d08e9971a9c</td>
	<td></td>
</tr>
<tr>
	<td>click</td>
	<td>id=checkbox_bac6e3a30c8d87d2221981bfc36c48c6</td>
	<td></td>
</tr>
<tr>
	<td>click</td>
	<td>id=checkbox_b70d95e549c77d1ee381947b403a4ff0</td>
	<td></td>
</tr>
<tr>
	<td>select</td>
	<td>name=action</td>
	<td>label=Activate</td>
</tr>
<tr>
	<td>clickAndWait</td>
	<td>id=doaction</td>
	<td></td>
</tr>
</tbody></table>
</body>
</html>

Yes, Selenium IDE stores the script data in an HTML table.    The first cell is the command, the second is the target the third is the value.  Makes for easy editing of scripts with other tools if you find the need.

Posted on

Daily Update, Trello, BrowserStack

The past few days I’ve been mostly working on client projects related to the plugins, helping people with their websites and server issues, and dealing with my own server issues.   Along the way I’ve learned some new tricks.

Tagalong 0.9

Tagalong version 0.9 is in development.  I am working through some reported bugs and trying to iron out the kinks.    This version also has patches to make it  work with SLP version 3.10.4.   This is where my focus will be until I get some of the more notable bugs squashed.  As soon as this is ready testing will ensue on SLP 3.10.4, EM 0.7, and Tagalong 0.9.

This version will require SLP 3.10.4

Store Locator Plus 3.10.4

Store Locator Plus 3.10.4  is entering testing.  There are no notable features but there are hooks and filters as well as minor updates that help make a new Enhanced Map v0.7 feature come to life.

When this version is ready you will need to update Enhanced Map to version 0.7+ and Tagalong to version 0.9+.

Enhanced Map 0.7

This version is entering testing.  As noted previously, the most notable feature of Enhanced Map 0.7 is the ability to set per-location map markers.

This version will require SLP v3.10.4

Store Locator Plus 3.11

This is in development.  Future release date is not yet set.    I am trying to get a version ahead of the public release that is in beta/testing in order to give the beta group more time to test an upcoming release.   This version has some notable improvements to how the plugin information is loaded and passed to the JavaScript process on the UI.  This lightens the load on the server when processing the map page load.  This all came about due to the Enhanced Map 0.8 tweaks.

Enhanced Map 0.8

Another future release.  Thus far the notable feature is the “center_map_at” shortcode attribute that a few people have asked for.    It was a lot of work to get this wired into Store Locator Plus, which uncovered some of the produce inefficiencies in the code logic that loads the JavaScript.

Trello

While exploring Easy Digital Downloads I was introduced to Trello.   I’ve only been playing with it for a few days and already love it.  It has a super-simple interface for task management.    If  you are juggling a half-dozen tasks at once, this is a great list management tool.   I already like how it organizes my thoughts and visually lets me see what I’m working on which allows me to easily see dependencies and move tasks/projects around in the queue.  It is all AJAX with a great drag-and-drop interface.  I’d love to emulate some of this user experience into Store Locator Plus but I need to up my UX skills first.

BrowserStack

I discovered BrowserStack while testing IE8 for a client.   They have customers that are complaining about compatibility with IE8.    There are some issues with the location sensor on IE8 that I thought were resolved.   It looks like SLP 3.10 through 3.10.3 have an issue which is resolved in 3.10.4.     Using BrowserStack is a simple solution for doing multiple browser tests on different platforms.  You can get a 3-month free trial if you follow the link from the modern.ie website.    It is costly, at $20/month.   However if you don’t want to fire up a dozen virtual machines to test IE8 on XP or IE10 on Windows 8 then this may be worth the expense.

Posted on

Intro To Debug Bar : Debugging WordPress With A Plugin

One of the sessions I attended at WordCamp Atlanta had some very useful information for developing and debugging WordPress plugins.  Another had useful information on speeding up sites with transients.  And another touched on security issues.   Almost every session that went a little deeper into the tech side of WordPress mentioned a plugin that they all used… Debug Bar.

One of the sessions had a brief blurb on what Debug Bar does and what it looks like.  In short, it throws a small “Debug” link up on the admin menu bar.    Hidden under that little debug button is a treasure trove of useful site debugging information.   This is NOT something you want to have up and running at all times on a production site, but for a development site it is a God-send.    No longer will I be writing dozens of hooks in my code and cluttering up the UI with debug output expansion boxes… even though I spent some time building a jQuery based expandable div for that over the past few months.    Debug Bar is a much cleaner UI experience, and based on what I’m seeing in the plugin directory it is full of hooks and filters I can tap into with my plugins.

hello debug bar
hello debug bar

Getting and Prepping for Debug Bar

As with any plugin, getting and installing Debug Bar was simple.  Go to the admin panel / plugins page to get the add new process started.  Type in “debug bar” and there it is, right at the top of the listing.  Install and activate.

However, one thing I immediately noticed is the documentation is very sparse.  No links to an external site for more info.  No instructions on configuration.   I guess that is the built-in litmus test.  If you can’t figure out how to get debugging setup, how to use the plugin, or where to go next then you shouldn’t be playing with it.

In fact, I feel that is a good point.

If you don’t know what this plugin could be useful for, don’t understand what an SQL query, global variable, or memory dump is from PHP then DO NOT INSTALL THIS.    For one thing it could be used to exploit your site if you do not lock this down.   In fact I’d not put this on a live site unless I was having serious site problems I could not sort out on my staging/development server (you DO have a staging site for your mission critical business site, right?).

OK, so you’ve got the plugin.  but do NOT make that the only thing you do.  You need to feed that thing AND you should be using the built-in debugging resources you’ve got built into the core WordPress product…. setup your environment for debugging.  Again, only in a development or staging system.

Turning WordPress Debugging “Full On”

Go to this WordPress page on debugging.  Read it.   The do this:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY',false);
@ini_set('display_errors',0);
define('SCRIPT_DEBUG',true);

If you cannot figure out where to put these elements in the wp-config file then you should stop now. Do not play with this unless you know what you are doing. If you have a clue then you are going to make your WordPress debugging and research a LOT easier. I cannot believe I did not know about this sooner… but at least I know about it now.

Ok, Got It… Now What?

Now you can start using the Debug Bar and the micro-system of associated add-on packs to gain more insight into your WordPress installation.  By default the plugin shows you some basic site metrics that can be useful such as your server name, current PHP version, current MySQL version, and how much RAM is being used by the WordPress process for the page you are viewing at the time.   You can also get the Object Cache hits (and misses) on any page.   On a page that is processing request variables? It will show that plus any matching rewrite rules from your permalink structure.  Nice things to know.

Here is a default view on my dev box on a basic Store Locator Plus page.    I see that the initial page rendering “hit” adds about 2MB to the memory footprint.  I’ve been playing with reducing the memory footprint of the wpCSL framework I use to help render pages, so I’ll be very interested if the swap in the code logic reduces the memory.  This one piece of information saves me a lot of extra code debugging inserts and keeps my code lighter.  Already worth the 5 minute install and configuration of Debug Bar.

debug bar default output on page request
debug bar default output on page request
Posted on

Simple Web App Testing

After all the discussions about testing web apps and working with a variety of relatively horrible app testing platforms, I have been learning Selenium IDE.  Selenium IDE is the “little brother” of the full blown Selenium Web Driver.    Where Web Driver is a robust client/server framework with distributed testing and full test logic options, IDE is a simple light weight scripting plugin for your browser.

 That is what I like about IDE.   I know what it is and don’t push it beyond those limits.  It is basically a “web input” record & playback utility with a few commands added to make it a rudimentary testing system. I now use it for testing the WordPress plugin base functionality with limited effort.   Spending an extra 10 minutes writing a test case pays off in numerous “one-click-and-done” script runs in the future when I want to do something like “make sure the Pro Pack name search is not broken” after a new release.
The premise is simple, when you add Selenium IDE to your browser as a plugin you get a menu option in the browser “Selenium IDE”.   You can record a script by clicking a record button, “do you web thing”, then stop recording.  You now have a script outline.   Click the “run this button” on the interface and the script runs again.
One caveat.   The recorded scripts are not very good.  They get the job done for a quick start, but you are much better off spending and extra 5 minutes and writing the test commands by hand. They are far more efficient and accurate.

Getting Started

When you select it a new popup window opens with a simple test case table on the left and commands table on the right.   The Test Case table is mostly for Test Suites (groups of test cases you run in sequence) so we’ll ignore it for now.    On the right side is the commands and it start out with a “blank slate” of commands.   I have another blog post about the commands I use that handle 90% of my test scripts that you can use as a quick cheat-sheet.
To start a new script you use the right-side command window.  The general command sequence is to  click on a new blank line, start typing a command in the bottom-of-screen command box and press enter to auto-complete, enter a target which identifies an on-screen element in jQuery-like fashion, and a value for certain commands.  Repeat.

An Example Session

Here is how I create a simple test to make sure SLP Pro Pack is installed and allowing lat/long editing to occur:
  • Click the first blank line.
  • Select command on the bottom entry form.
  • Start typing “open”.  This is the “open  a web page in same window” command.
  • Select target.  type the relative path (you can use a full http address, but I want my scripts to run on any server)
  • Click on the next blank line & continue building out my script.

I won’t bore you with each command, here is a screen shot of the Pro Pack Edit Location lat/long script that is also on GitHub.

selenium script example
selenium script example

Commands

The commands are detailed in my other post, but the quick summary:

  • open = open a web page
  • waitForElementPresent = pause execution until something that needs to be on the page is present
  • clickAndWait = click an element and wait for the page to reload before continuing
  • type = type text into an HTML element, like an input box
  • assertValue = flag an error and STOP SCRIPT EXECUTION if the value does not match

Targets

The “target” element of the script commands can be tricky for people that do not know XHTML or JavaScript/jQuery style targets.   I find the easiest way to manage this is to make sure my web apps have discrete input names or IDs on most elements or useful and distinct class names for IDs that may be dynamic like “location-id-33”.   With a unique name or ID you can get to your target element easily, just type name=foo or id=bar and you are there if it is the only element with that ID or name.

For items without a discrete name or with multiple instances you can combine XHTML-like references with other elements.   Two key things to remember about this, using a single-slash means “exactly at this point in the document hierarchy and double-slashes means “first found”.     For example /table/thead/tbody/tr[1] is THE first row after the table, thead, tbody elements.  If any are missing it will fail.    In contrast /table//tr[1] will meant the first table row that can be located after the first table in the document.    I often mix-and-match “select by name” and the double-slash “first found” options so that something like this shows up:

//table[@id=’foo’]//tr[2]//th[2]//a[@class=’bar’]

This is useful in WordPress where I can never be certain that a theme will not change the page structure.  In this case it says “find the first table element with an id set to foo, within that find the second tr element (since a theme/plugin may throw in some thead or other element I continue the // format), find the second th element in that row, and select the first hyperlink with a class set to ‘bar’.

Targets take some getting used to, but luckily you can test your “guess” at the right path after it is entered with the “find” button that will go show you which element it thinks you mean on the page that is currently rendered in the browser window.

What I’ve Learned

A couple of important things I’ve learned along the way.   First, use waitForElementPresent judiciously.   I usually put this in place before I interact with the first item on the screen.  The “…AndWait” commands wait for the page to load but with so much jQuery page loaders out there it is common for the element you need to not be ready when the page first comes online.   The “waitFor…” commands can wait a long time and will not always flag an error if they time out.    Use “assert…” whenever something critical must be on the page or to flag a script as failing.   “assert…” is NOT the only way a script will fail, which is a feature I like about Selenium IDE.  If you try to click an element and it is not there it fails the script but tries to continue running.  This makes it very easy to write light-weight test scripts.

No Excuses

Overall it is not as robust as many testing platforms, but that is a good thing IMO.   Because it is light & easy you can get Selenium IDE in place and get your first test scripts online in well under an hour.    That means you really have no excuse not to be doing at least RUDIMENTARY repetitive task testing on your web apps.

I’ve started using this to test my WordPress plugins and try to add at least one new short test case in each plugin release.  It adds about 10-15 minutes on average to the test cycle but it means one more feature is tested before each release.  Even now with just a dozen test suites I’ve prevented at least two significant functional bugs from getting out to the public.

Use Selenium IDE and do some web tests.   The user community will thank you for it.

### Technorati Claim Code CGBQWRFD3GA5 ###
Posted on

Selenium IDE Commands

I’ve been using Selenium IDE for a few months now with very simple test scripts.   Mostly scripts I’ve recorded to test my WordPress plugins.   They are not very sophisticated, but as my release schedule has increased so has my need for more robust testing.  Unfortunately the Selenium IDE 2 documentation is sparse at best.   Maybe they have a complete list of commands and how they work, but I can’t find it.

So I decided to create my own Selenium IDE commands list.   This is my cheat sheet and is based on my current knowledge as an end user.  It may not be accurate, so always check what you read here before applying it to a production test suite.

Using Selenium IDE

One of the first lessons I learned is that recording/playing back scripts is a great way to get started.   The second lesson learned seconds later is that the scripts are far from perfect, very inefficient, and always need editing.

Add wait commands, it is key to successful tests.   Always make sure an element is loaded before running full speed through the script.

Edit the first couple of commands to go directly to the test URL.  Often the scripts start elsewhere.

Realize this is not a full programming language.  Out of the box it does NOT support if, goto, or loop constructs.  It is a pure linear command execution.  If you need more you should get an add-on OR use the full Selenium RC line.

Selenium IDE Commands

(that I use)

assertElementPresent

Arguments:

locator – an element locator

Description:

Make sure an element is present, if not fail and abort the remainder of the test.

Notes:

I use this to make sure that a previous test suite or action did what I expected.  If not, something is horribly wrong.   Assert commands tell Selenium IDE “hey, something bad happened… stop testing”.

assertElementPresent

Arguments:

target – a piece of javascript that returns a value

value – what you expect the value to be set to

Description:

Make sure the javascript executes.  The find button will not work here, you must execute the command to test this.

Notes:

This is a recent addition to my Selenium IDE arsenal.  I use it to check custom CSS rules and make sure that when I tweak a CSS rule via my admin panel textarea field that it makes it to the front end.   I check the computed style of a specific element and make sure the attribute is set as I expect.  For example, check that the final style sets a font size to 48px.

Example target:

window.document.defaultView.getComputedStyle(window.document.getElementsByClassName(‘entry-title’)[0]).getPropertyValue(‘font-size’)

Example value:

48px

check

Arguments:

locator – an element locator

Description:

Check a toggle-button (checkbox/radio).

Notes:

This is a great way to force a checkbox on.   The mirror command is uncheck.

  • command: check
  • target: you element finder i.e. name=checkbox_name_property
  • value: n/a (leave blank)

click

Arguments:

locator – an element locator

Description:

Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), call waitForPageToLoad.

Notes:

A good idea to use waitForElement to make sure your locator is present before doing this.

open

Arguments:

url – the URL to open; may be relative or absolute

Description:

Opens an URL in the test frame. This accepts both relative and absolute URLs. The “open” command waits for the page to load before proceeding, ie. the “AndWait” suffix is implicit. Note: The URL must be on the same domain as the runner HTML due to security restrictions in the browser (Same Origin Policy). If you need to open an URL on another domain, use the Selenium Server to start a new browser session on that domain.

select

Arguments:

selectLocator – an element locator identifying a drop-down menu
optionLocator – an option locator (a label by default)

Description:

Select an option from a drop-down using an option locator.

Notes:

The easiest way to select an element on a pulldown list is:

    • command: select
    • target: id=<input id>
    • value: label=<text string of item to select>

Here are notes on the selectors from Selenium IDE:

Option locators provide different ways of specifying options of an HTML Select element (e.g. for selecting a specific option, or for asserting that the selected option satisfies a specification). There are several forms of Select Option Locator.

    • label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.)
    • label=regexp:^[Oo]ther
    • value=valuePattern: matches options based on their values.
    • value=other
    • id=id: matches options based on their ids.
    • id=option1
    • index=index: matches an option based on its index (offset from zero).
    • index=2

If no option locator prefix is provided, the default behaviour is to match on label.

type

Arguments:

locator – an element locator

value – the value to type

Description:

Can also be used to set the value of combo boxes, check boxes, etc. In these cases, value should be the value of the option selected, not the visible text.

Notes:

This is what I use to “type” data into an input field.

uncheck

Arguments:

locator – an element locator

Description:

Uncheck a toggle-button (checkbox/radio).

Notes:

This is a great way to force a checkbox off.   The mirror command is check.

  • command: uncheck
  • target: you element finder i.e. name=checkbox_name_property
  • value: n/a (leave blank)

waitForElementPresent

Arguments:

locator – an element locator

Returns:

true if the element is present, false otherwise

Description:

Verifies that the specified element is somewhere on the page.

Notes:

I try to use this before I click on anything, enter input values, etc.  Often an element is not loaded yet.  This waits until it is (or fails).

Checking if a hyperlink that contains specific text is a good way to manage the AJAX operations of WordPress categories.    You can use the following command set:

command: waitForElementPresent
Target: xpath=//a[text()='Category Name']

My Script(s)

I  have my Store Locator Plus testing scripts on a public GitHub repo for anyone that wants to see them.

Enjoy & please share your Selenium IDE wisdom here.  We can all use help when it comes to using this tool.