If you are in the “test automation business”, most probably you are familiar with the Selenium IDE. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE). It gives you the ability to export your tests to number of popular programming languages, including Java, C#, Groovy, Perl, PHP, Python and Ruby. However, the built-in formatters cannot be customized and usually are generating not very useful code (not following your framework design). In this article, I am going to share with you how you can extend the Selenium IDE and add your custom Selenium IDE Export format template.

Use Firefox Extensions

There are tons of already created Selenium IDE export plug-ins you can always see if some of them are working for you.

Allows users to take advantage of WebDriver without having to modify their tests.

Create Custom Selenium IDE Export to WebDriver

You can add any format you like by writing JavaScript code. Follow the steps below:

Open Firefox and Selenium IDE

and Open Options dialog

dialog Click Formats tab

tab Create a new format by clicking “Add” button

­There are three empty functions- parse, format, formatCommands.

Parse Function

The parse function is almost opposite of format. This function parses the String and updates test case.

FormatCommands Function

The formatCommands function is similar to format function. You can add additional logic to it. In my code format will call formatCommands.

Format Function

The “format” function creates an array of commands contains command object (Command, Target, Value).

Create Complete Selenium IDE Format to WebDriver C# Framework

If we have the following sample base test class. Our goal might be to export our Selenium IDE tests to C# code that uses the methods provided by this base test class.

Below you can find the full source code of the new Selenium IDE Export format.

There are a couple of interesting parts of the presented code. Most of the magic happens inside the setCommand function. There, through a switch statement the function generates a string for the corresponding C# code for the used Selenium IDE command. The locator expressions are made in the searchContext.

One more thing, you can use XUL XML (XML User Interface Language) to describe how the format settings form will look like.

After you add different text boxes and other controls, you can later use the default values set in them in your Selenium IDE Export format.

Create Selenium IDE Export for Page Object Map Generation

As you, probably know I am a big fan of the Page Object Design Pattern. Until now I have introduced to you a couple of different ways to use the design pattern. Usually, the most tedious part of it is the creation of the element map classes. We can ease the process with the help of Selenium IDE and a new Selenium IDE Export format. This format is going to export to a new file only the elements in the below format.

I haven’t figured a smart way to name the generated elements because of that the first version is producing them with an increasing index suffix added to the element’s name.

Here is the full source code.