Saturday, April 14, 2018

Selenium with Robot Framework Tool

Selenium with Robot Framework Tool:

Yes, you are reading right selenium can be integrated with the existing framework which is "Robot Framework". Its developed in python language and it can compatible with jython as well i.e. we can test Java developed applications as well and of course python developed application too.

Basically, Robot Framework works with Build-in(Internal) library and External library. On top of these library automation engineer develops code to test application in automation.

Here Selenium library is called as Selenium2Library :

Java - https://github.com/MarkusBernhardt/robotframework-selenium2library-java#readme

Python - https://github.com/robotframework/Selenium2Library

 this external library needs to be added as a plug-in in robot framework. Then we can access their APIs in the actual our testing framework.

Personally I feel with python it is very easy to consume existing API's when we extend the automation framework.

Use of Label & While Loop with Selenium IDE

To use the Labels & While Loop functionality with Selenium IDE we need to configure the following code as .js file.

Below are the Steps :-

1) Open Selenium IDE as Mozilla Firefox Add on.
2) Copy & Paste below given code, save file with extension as .js
3) Go to options , Browse the saved .js file from selenium core extensions field.
Like this :- C:\Documents and Settings\goto_sel_ide.js
4) Now you have to reopen Selenium IDE to use of Labels & while loop
5) You can add code as :-

Selenium Pattern view :-

echo Login done
gotolabel test
echo Gaurav is doing practice
label test
store 20 a

store 25 b

while storedVars['a'] <= storedVars['b']
getEval storedVars['a'] = ${a}+1;
endWhile
getEval alert("Finished");
echo $a

Java language View :-

// selenium.gotolabel("test");
System.out.println("Gaurav is doing practice");
// selenium.label("test");
String a = "20";
String b = "25";
// selenium.while("storedVars['a'] <= storedVars['b']");
// selenium.endWhile();
System.out.println("$a");


------------------------------------------------------------------------------------------------
Code of .js 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 <>
var x = testCase.commands[i];
command_rows.push(x);
}
var cycles = [];
for( var i = 0; 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 <>
// 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 <>
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 );
}

Thursday, April 12, 2018

Why to go Robot Framework Tool for automation testing ...

Automation Testing with Robot Framework Tool:


  • Easy to learn, coding, scripts development style
  • Designed Fundamentals strong on Python lang
  • Fundamental of framework gets created so easy to design automation framework
  • Best reports of test suits
  • Helpful to customize the Automation Framework per project demand, COE designing for multiple projects in an organization
  • Quickly wrap- up the basic required functions
  • Ready Lib available and easily can extend as per project requirement
  • Comfortable with build-in and external lib support and gives scope to do innovation in framework
  • Support with Jenkins and Hudson for CI tool