From iMacros
Jump to: navigation, search

The iMacros Editor (iMacrosEditor.exe) was designed specially to edit iMacros macros, but it can be used to edit any text file, including batch files, VBS and JS scripts, XML files, etc. The iMacros Editor is able to recognize these languages and highlight their syntax accordingly. The iMacros Editor is associated to the *.iim files so by right clicking on any .iim file and choosing Edit, the macro is open in the iMacros Editor. This is also the case from any "edit action" in iMacros Browser or iMacros for IE.

The iMacros Editor offers more than just highlighting the iMacros syntax. The Editor makes it much easy to edit the iMacros macros. Testing parts of the macro being edited can also be done directly from the editor. The editor also has the ability to export recorded macros to Selenium WebDriver Java code.

The iMacros Editor offers more than just highlighting iMacros syntax.

Export Macro

Once a macro is open in the editor, you can export it completely or partially to be played either by iMacros Scripting API, or through the Selenium WebDriver.

Export to Selenium WebDriver Java code

Now you can profit from the iMacros powerful recorder and export the recorded macro to Selenium WebDriver Java code (QA automation) using the iMacros Editor. Use any flavor of iMacros (Chrome, Firefox, Internet Explorer, or iMacros Browser) to record the elements on a webpage and export the commands to Java Selenium code directly from the iMacros Editor.

Whether you decide to export the complete macro or only a selection of it, when you choose the Selenium WebDriver option in the Export menu, a new file will be created with a complete snippet of code like the one below, ready to be inserted in your project.

The easiest way to export is to use the J button from the toolbar.

Export recorded iMacros macros to Selenium WebDriver Java code.
// WebDriver java snippet for Selenium generated by iMacros Editor
package Imacros;

import java.util.*;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.*;
import org.openqa.selenium.chrome.ChromeDriver;

public class FromiMacros {

	public static void main(String[] args) {
		// Please set the correct path to your Chromedriver.exe file
		System.setProperty("webdriver.chrome.driver", "\\Chromedriver.exe");
		WebDriver driver = new ChromeDriver();

		try {
			List<WebElement> frames;
			Set<String> tabs;
			WebElement element;
			// VERSION BUILD=11.5.497.9113
			tabs = driver.getWindowHandles();
			driver.switchTo().window(tabs.toArray(new String[0])[0]);
			// 'Macro that makes use of Css Selector while recording
			element = driver.findElement(By.cssSelector("#name"));
			element.sendKeys("iMacros user");
			// 'Drop down
			element = driver.findElement(By.cssSelector("#food"));
			element.sendKeys("%Bread and Butter");
			element = driver.findElement(By.cssSelector("#drink"));
			// 'Radio button
			element = driver.findElement(By.cssSelector("#large"));
			element = driver.findElement(By.cssSelector("#dessert"));
			element = driver.findElement(By.cssSelector("#demo>FIELDSET>OL>LI:nth-of-type(6)>INPUT"));
			element = driver.findElement(By.cssSelector("#demo>FIELDSET>OL>LI:nth-of-type(6)>INPUT:nth-of-type(2)"));
			element = driver.findElement(By.cssSelector("#demo>FIELDSET>OL>LI:nth-of-type(7)>TEXTAREA"));
			element.sendKeys("Order placed");
			// '
			element = driver.findElement(By.cssSelector("#demo>FIELDSET:nth-of-type(2)>BUTTON"));

		} catch (Exception e) {
		} finally {

However, there are times when you only need to append a few lines to your class or method. In this case, the Export to Clipboard menu item in the Edit menu will put only the required lines of code in the clipboard which you can then paste into your file.

In both cases, the generated code works best when the macro is recorded in the same browser which is going to be used by the WebDriver.

Export to Scripting Interface code

The iMacros Editor can also generate a snippet of C#, JavaScript, or VBScript code which embeds the current selected macro code and uses iMacros Scripting API. The example below shows the C# generated code from a partial selection of FillForm.iim.

The Editor generates C#, JavaScript or VBScript code for direct use with the iimPlayCode command.

// C# snippet generated by iMacros Editor.
// See http://wiki.imacros.net/Web_Scripting for details on how to use the iMacros Scripting Interface.

// iMacros.AppClass iim = new iMacros.AppClass();
// iMacros.Status status = iim.iimOpen("", true, timeout);
StringBuilder macro = new StringBuilder();
macro.AppendLine(@"URL GOTO=http://demo.imacros.net/Automate/TestForm1");
macro.AppendLine(@"'We use quotation marks for a content with spaces");
macro.AppendLine(@"TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:name CONTENT=""iMacros User""");
macro.AppendLine(@"'Selecting a drop down");
macro.AppendLine(@"TAG POS=1 TYPE=SELECT ATTR=NAME:food CONTENT=%French<SP>Fries");
macro.AppendLine(@"TAG POS=1 TYPE=SELECT ATTR=NAME:drink CONTENT=%Coke");
macro.AppendLine(@"'Selecting a radio button");
macro.AppendLine(@"TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:drinksize");
string macroCode = macro.ToString();
// status = iim.iimPlayCode(macroCode, timeout);

Uncomment the code lines which creates the iMacros object

iMacros.AppClass iim = new iMacros.AppClass();
iMacros.Status status = iim.iimOpen("", true, timeout);

and call the scripting interface methods

status = iim.iimPlayCode(macroCode, timeout);

to have a complete working program in the chosen language.

See iimOpen for more details on how to change the browser and browser options in the generated code.

Play Macro Selection

The Play menu. Choose "Play in..." to select another browser to play the macro or selection.

In the Play menu you'll not only find the option to play the complete macro that is currently open in the editor, but also fragments of it. The editor sends the macro or macro lines to the running iMacros Browser (or iMacros Sidebar for IE) to be played via iMacros Scripting API.

Please notice these few remarks about the play feature:

  • If no text is selected on the editor, the line currently under the cursor is played.
  • The editor sends complete lines to iMacros, even if the selection contains only a piece of a line.
  • Play from Here plays all lines from the cursor to the end of the macro.
  • Choose the submenu Play in... another browser like IE, Fx, or Cr where the macro or macro fragment will be played.
  • Play in IE is checked by default if the editor was started from iMacros for IE, via one of the "edit actions" in the iMacros sidebar.
  • The editor plays the macro in the currently open browser. If an open browser is not found, a new browser window is created to play the macro.
  • After playing the macro, the browser window remains open.

The editor uses the iMacros Scripting API to play the macro. iimOpen (<browser>, false) is called to connect to the existing iMacros browser and iimPlayCode is used to send the code from the editor to iMacros. Since only iMacros Enterprise Edition contains the Scripting API, this feature is disabled in other editions.

Other features

For a comfortable editing of macros containing IMAGESEARCH and IMAGECLICK commands, the editor shows thumbnails of the images referenced in these commands. When you hover the mouse over the name of an image file, it pops-up a small thumbnail preview of that image.

You can insert pre-defined command and variable templates directly into your macro using the Insert menu. The parameters can be adjusted after inserting the template. Additionally in Insert menu, you'll find the password encryption/decryption tool which recognizes an encrypted password and can decrypt it, given the master key is entered. The password tool can also be invoked using the shortcut key combinations Ctrl+E (for encryption) and Ctrl+D (for decryption).

The Insert menu. Insert pre-defined commands in your macro.