Question

I'm having some trouble understanding how the formatter works for Selenium IDE. I don't want to write a formatter from scratch, I want to modify the existing code which turns selenese into webdriver backed java. Normally I would sit down with the Javascript code and try to figure out how it works, but I am a little stuck.

Here is a typical formatter:

function parse(testcase, source){}
function format(testcase,name){
    var Javaprogram = ""
    for each command in testcase{
        switch command.command
        case something:
            Javaprogram += "driver.something(" + command.target + (command.value!=""?");":","+command.value+");")
        ...

I can't find this logic anywhere in the Java formatter, there isn't even a format function, just a "formatComment" and "formatSuite". which leads me to believe this is being done under the hood, but reverse engineering it would take time that I really don't have.

Does anyone Know how this works? Does anyone have a link to a tutorial on modifying the existing formatters? Either is fine. I will keep looking for answers to this and link them in comments if I find them. Clearly people have done and are capable of doing this.

Was it helpful?

Solution

Adam Goucher wrote a wonderful series of blog posts back in 2009 that talk about this stuff, in the context of writing a Selenium IDE plugin (which the formatters are):

There's also some useful information at the IDE release notes on formatter plugins , and the old Wiki has a page that describes how to write a formatter (be forewarned, it's O-L-D).

The Selenium HQ downloads page has examples of several formatter plugins that you might find helpful:

  • Play! Framework: A plugin for Selenium-IDE that adds support for the simplified markup used by the Play! framework.
  • Grails Formatters: Adds Grails Formatters.

OTHER TIPS

  1. Open Selenium-IDE source code, you can do this either by downloading it from GitHub or on Windows Explorer go to: (C:\Users\YOUR_USER_NAME\AppData\Roaming\Mozilla\Firefox\Profiles\FIREFOX_PROFILE\extensions)
  2. Copy Selenium-IDE extension {a6fd85ed-e919-4a43-a5af-8da18bda539f}.xpi to your Desktop
  3. Rename the file to {a6fd85ed-e919-4a43-a5af-8da18bda539f}.xpi.zip
  4. Extract the Zip file
  5. Go to ZIP\chrome\content\formats\
  6. Open webdriver.js
  7. Search for function formatCommand(command), you will find it on line ~425

Now this function is responsible for calling the Formatter Extension of Selenium-IDE, this function take command as input and return string as output, which is the corresponding line in the target programming language.

If you edit this function, this will customize Formatter in all programming languages, if you want to customize specific programming language you have to edit the extension source code:

  1. Go to (C:\Users\YOUR_USER_NAME\AppData\Roaming\Mozilla\Firefox\Profiles\FIREFOX_PROFILE\extensions)
  2. Find the target formatter X-formatters@seleniumhq.org.xpi copy it to your Desktop, Unzip it and Go to chrome\content\formats\, where you can find the js files of the formatter.

In order to apply your edit:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top