Selenium IDE - User-Extensions

The name it self we can find this is nothing but Extend the selenium Usage by user. I used one of the Extension GOTOIF,  this is the extend of goto command.
i.e goto and label commands help us to skip the steps and focus under the commands of label, we can extend it as
IF
<Argument>
Goto à Label 1
Else
<Execute the next line>
It can be used by Selenium IDE with following process
Goal : I need to Check the Check box if it is not already checked. If already checked i should not check (uncheck) it again.
Selenium - IDE
Command
Target
Value
StoreChecked
Check Box
On
gotoIf
${on}
T1
click
Check Box

clickAndWait
Button Save

Label
T1

clickAndWait
Element (To check the action to verify check box value change)

Verify/Assert



To get the above command we have to do the followings:
1.Copy and paste the following and save it as (.js ) javascript file
var gotoLabels= {};
var whileLabels = {};

// overload the original Selenium reset function
Selenium.prototype.reset = function() {
    // reset the labels
    this.initialiseLabels();
    // proceed with original reset code
    this.defaultTimeout = Selenium.DEFAULT_TIMEOUT;
    this.browserbot.selectWindow("null");
    this.browserbot.resetPopups();
}

Selenium.prototype.initialiseLabels = function()
{
    gotoLabels = {};
    whileLabels = { ends: {}, whiles: {} };
    var command_rows = [];
    var numCommands = testCase.commands.length;
    for (var i = 0; i < numCommands; ++i) {
        var x = testCase.commands[i];
        command_rows.push(x);
    }
    var cycles = [];
    for( var i = 0; i < command_rows.length; i++ ) {
        if (command_rows[i].type == 'command')
        switch( command_rows[i].command.toLowerCase() ) {
            case "label":
                gotoLabels[ command_rows[i].target ] = i;
                break;
            case "while":
            case "endwhile":
                cycles.push( [command_rows[i].command.toLowerCase(), i] )
                break;
        }
    } 
    var i = 0;
    while( cycles.length ) {
        if( i >= cycles.length ) {
            throw new Error( "non-matching while/endWhile found" );
        }
        switch( cycles[i][0] ) {
            case "while":
                if( ( i+1 < cycles.length ) && ( "endwhile" == cycles[i+1][0] ) ) {
                    // pair found
                    whileLabels.ends[ cycles[i+1][1] ] = cycles[i][1];
                    whileLabels.whiles[ cycles[i][1] ] = cycles[i+1][1];
                    cycles.splice( i, 2 );
                    i = 0;
                } else ++i;
                break;
            case "endwhile":
                ++i;
                break;
        }
    }
}

Selenium.prototype.continueFromRow = function( row_num )
{
    if(row_num == undefined || row_num == null || row_num < 0) {
        throw new Error( "Invalid row_num specified." );
    }
    testCase.debugContext.debugIndex = row_num;
}

// do nothing. simple label
Selenium.prototype.doLabel = function(){};

Selenium.prototype.doGotolabel = function( label )
{
    if( undefined == gotoLabels[label] ) {
        throw new Error( "Specified label '" + label + "' is not found." );
    }
    this.continueFromRow( gotoLabels[ label ] );
};

Selenium.prototype.doGoto = Selenium.prototype.doGotolabel;

Selenium.prototype.doGotoIf = function( condition, label )
{
    if( eval(condition) ) this.doGotolabel( label );
}

Selenium.prototype.doWhile = function( condition )
{
    if( !eval(condition) ) {
        var last_row = testCase.debugContext.debugIndex;
        var end_while_row = whileLabels.whiles[ last_row ];
        if( undefined == end_while_row ) throw new Error( "Corresponding 'endWhile' is not found." );
        this.continueFromRow( end_while_row );
    }
}

Selenium.prototype.doEndWhile = function()
{
    var last_row = testCase.debugContext.debugIndex;
    var while_row = whileLabels.ends[ last_row ] - 1;
    if( undefined == while_row ) throw new Error( "Corresponding 'While' is not found." );
    this.continueFromRow( while_row );
}
Selenium.prototype.doGotoIfNot = function( condition, label )
{
    if( !eval(condition) ) this.doGotolabel( label );
}
2. Open Firefox and open Selenium-IDE.
3. Click Options menu and select Options
4. Click Browse button under Selenium Core extensions (User-extensions.js) and select the js file and click OK.
5. Restart the selenium IDE.
6. From the command drop down you can find the commands gotoif and some more handled in above prototype.

16 comments:

  1. Failed to load user-extensions.js!
    files=/Users/name/Documents/Sele.js
    lineNumber=1
    error=SyntaxError: illegal character..

    could you please give me the reason why it failed?

    ReplyDelete
  2. How to run user-extensions.js using Selenium RC.

    ReplyDelete
  3. Thank you for sharing this information.I have gone through your blog and its very wonderful Selenium training in chennai

    ReplyDelete
  4. Selenium Testing Real Time Hands on Training in Chennai…

    Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

    http://thecreatingexperts.com/selenium-training-in-chennai/

    If You need a Best Trainer in Selenium Testing??? Then be ready for a DEMO From the Trainer MR.Karthick
    CONTACT:8122241286

    Both Classroom/Online Training is Available!!!!!!

    ReplyDelete
  5. Looking for best training in SELENIUM, take a glance at http://thecreatingexperts.com/selenium-training-in-chennai/

    ReplyDelete
  6. Thanks for sharing great information in your blog.

    Selenium training institute which provides Real Time Hands on Training…THE CREATING EXPERTS

    http://thecreatingexperts.com/selenium-training-in-chennai/


    contact-8122241286

    ReplyDelete
  7. Thanks for sharing this blog.Creating Experts provides Best training in selenium

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  8. I was looking for Selenium and Appium training in Chennai and got a link,it was the CREATING EXPERTS.

    If you are looking for one click the link below and contact 8122241286.

    http://thecreatingexperts.com/appium-training-in-chennai/
    http://thecreatingexperts.com/selenium-training-in-chennai/

    ReplyDelete
  9. THE CREATING EXPERTS is one of the leading training provider in SELENIUM they provide hands on training with real time scenario

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact +91-08122241286

    ReplyDelete
  10. The Creating Experts provides training in SELENIUM

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact +91-08122241286

    ReplyDelete
  11. Nice blog...

    Selenium training institute which provides Real Time Hands on Training…THE CREATING EXPERTS

    http://thecreatingexperts.com/selenium-training-in-chennai/


    contact-8122241286

    ReplyDelete
  12. SELENIUM training in Chennai

    http://thecreatingexperts.com/selenium-training-in-chennai/

    SELENIUM training in Chennai by THE CREATING EXPERTS ,

    They provide you hands on training with real time scenarios

    contact 8122241286

    ReplyDelete
  13. Hi, all nice blog for a long time i was searching for a real time trainer and landed with my trainer in selenium
    SELENIUM training is provided by THE CREATING EXPERTS in CHENNAI

    http://thecreatingexperts.com/selenium-training-in-chennai/

    Contact 8122241286 for more info

    ReplyDelete
  14. Nice blog...

    Selenium training institute which provides Real Time Hands on Training…THE CREATING EXPERTS

    http://thecreatingexperts.com/selenium-training-in-chennai/


    contact-8122241286

    ReplyDelete
  15. NICE BLOG...Selenium training in CHENNAI provided by THE CREATING EXPERTS

    http://thecreatingexperts.com/selenium-training-in-chennai/

    CONTACT 8122241286.

    ReplyDelete