iMacros is part of the Ipswitch family of tools and services. Learn More »

Best Practices of Using iMacros for Test Automation

by / Tuesday, 18 November 2014 / Published in Tips and Tricks

The following examples are based on the use of the WhatsUp Gold Server (WUG) of Ipswitch Inc.


1     Handling Dynamic IDs

Normally, the automatically generated macro files work the way they are recorded by iMacros. However, sometimes an error occurs during replay due to a “tricky” or dynamic web page. In this case, editing the macro manually will solve the problem.

1.1    Dynamic Web Pages

Some web sites, e. g. WUG, are generated dynamically each time the page is loaded. Some dynamic web pages may use session IDs, which are unique numbers changing each time you visit a page. During recording with iMacros, the session or dynamic IDs are written into the macro as part of the TAG command.  If you try to replay a macro with session IDs in a different browser session, iMacros will not find the exact link and will return an error.

1.2    Solution: Use Wildcards

There is an easy workaround with iMacros. The solution is to replace the dynamic (usually numeric) part of the ID’s value in a TAG command with the * wildcard symbol. The wildcard causes iMacros to accept any character where the * is placed.

1.3    Examples:

The following TAG command is a click on the Save button in WUG and has a session ID with dynamic values (numbers):


If you replace the numbers of the ID with the * wildcard, the macro will be successfully executed in every browser session:


1.4    Use Other Attributes to Identify the Element

Alternatively, you can use any other available attribute to specify the element, e.g. the CLASS or the TXT attribute, or both:



2     Using the Index Tree for Navigation rather than the Page URL

2.1    WUG Page Navigation

While recording, iMacros will automatically insert at the start of the macro the command URL GOTO=X. In case of recording on WUG, this way of navigation to a web page is not advantageous since each time it executes it will trigger a login to the system, which is time consuming.

2.2    Solution: Use WUG Index and iMacros TAG command for Navigation

Instead of using URL GOTO=X, you can use the TAG command created while recording a click on the WUG Index tree tab:




One problem here is that iMacros does not have any information on whether the Index tree is currently expanded or not. The TAG command will simply click on a certain item from the Index and will expand it if it is collapsed and vice versa.

Since iMacros is designed as a descriptive language like HTML, it does not contain conditional statements.  We can use any script or programming language to check if the index tree is expanded or not. For this purpose, we are using iMacros with VBScript in the following procedure:


This procedure is looking for a certain item from the Index. If the item can be found, then this means the tree has been expanded already. Otherwise, it has to be expanded using a TAG command.

Example: If we want to navigate to Network Performance Monitor -> Devices & Discovery -> Devices and Groups, we will call the procedure in the VB script as follows:


NavigateTree “Network Performance Monitor”, “Devices & Discovery”

NavigateTree “Devices & Discovery”, “Devices and Groups”


3     Closing all other Tabs in WUG

3.1    Tabbed Web Sites

Navigating to different pages in WUG will open them in page tabs. These page tabs are part of the web application, and should not be confused with tabs opened by the web browser. The tabbed web site contains elements, e.g. menus, with the same ID attribute. This can cause the macro to open a menu on a different tab than the intended one. You need to close all page tabs except the current one, so they will not interfere with the executed macro.




3.2    Solution: Close other Tabs

Before opening any menu, close all other web page tabs by adding the following code to your macro:


After WUG login and before starting the first test case step, run the following macro to ensure that you start the test case always from the same initial state, closing all tabs and viewing the Index tree:



4     Using Relative Positioning

4.1    Element Position

The position of the elements in the WUG tables can change in the next browser session depending on the number of elements, e.g. log report messages, that have been displayed. This can cause the macro to fail. It is possible to tag an element relative to its outer element in a nested situation.

4.2    Solution: Relative Positioning

The following macro first tags the table DIV element named User-Passive-Monitor and then looks for the previous occurrence of an image (in this case it is the Options menu icon):


Using relative positioning we can ensure that the macro opens the Options menu of the User-Passive-Monitor and not the options of any other available passive monitor. Otherwise we cannot distinguish between two Options menus.


5     Dealing with Timing Issues

Since the WUG User Interface needs time for the login, to display dialogs, and for some types of “processing request” messages, it is necessary to tune the macro’s behavior in order to avoid runtime errors and other timing issues.

5.1    Use the WAIT Command

Using the WAIT SECONDS=X command will specify the time before continuing replay with the next macro command.


5.2    Use the SET !TIMEOUT_STEP Command

It is possible to adjust the wait time by using SET !TIMEOUT_STEP X. The TAG command will wait up to a maximum of !TIMEOUT_STEP seconds, checking every second if the relevant element is loaded. Unlike WAIT, if the element is loaded prior to the timeout expiring, the macro will immediately continue. The default wait time is 6 seconds.



Alternatively, IMAGESEARCH can also be used. This requires some more work during recording, but allows you to avoid any WAIT statements.



6     iMacros Settings

In general, while recording with iMacros on WUG, you do not need to make any changes to the iMacros settings. However, changing some settings can help you investigate problems or edit the recording code.

6.1    Switching between Auto and Expert Recording Mode

Switching between Automatic and Expert Click Mode (iMacros Sidebar > Record tab > Click Mode) can be helpful if you want to manually edit one element’s attributes in a TAG command. In Auto mode, iMacros looks at the different attributes an element has (such as ID, Name, Class, Text, HFEF etc.) and selects the one attribute it thinks fits best. In Expert mode, iMacros does not select just one attribute but creates a TAG command with all attributes of the clicked HTML element. The purpose is to give a quick overview of all the element’s attributes so that the user can edit the TAG command manually and select the attribute (or combination of attributes) that work best.


AutoMode                                            ExpertMode


6.2    Changing the Replay Speed to Trace Problems

You can also change the Replay Speed in the iMacros settings to medium or slow while tracing problems.



7     Recording Tooltips Created with the qTip Plugin

7.1    Extract Custom Attributes

Normally, the tooltips are specified by the title attribute of an element. You can extract the tooltip content with iMacros:


WUG uses the qTip tooltip plugin for the jQuery JavaScript framework. A new feature in iMacros version 10.2 makes it possible to extract custom attributes, e.g. the data-qtip attribute used by the tooltip plugin:


ComputerName=* is the initial immutable part of the tooltip content and is used to specify which tooltip should be extracted.