Install the GOTO extension and run the provided script that makes use of the extension.
Difficulty level: Easy
What you will learn?
Goto user extension
Tips:
- Ensure to install the user extension first before script execution
Pre-requisites:
- Firefox browser with Selenium IDE installed ,use link How to install Selenium IDE?
1. follow the instructions below to install the user extension in the IDE
2. copy and paste the script provided into the IDE.
3. run the goto script
Solution:
1. Click on 'Options' tab.
2. Select Options menu.
3. Open 'Selenium IDE Options' window frame.
4. Click on 'Browse' button.
5. Browse goto script file from your system path.
6. Click on "OK' button
7. Restart your firefox browser now in the command list you would see goto commands as well
Conclusions
Related Entries
Zip file location: ( download from here)
C:\FoundationSelenium\Ex12\Goto_sel_ide.js, C:\FoundationSelenium\Ex12\GotoScript.html.
Here is the contents of go to java script:
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 );
}Here is the script in text format:
-----------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://foundation.time2test.co.uk/" />
<title>GotoScript</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">GotoScript</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Log in</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Username</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Password</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=user_login</td>
<td>admin</td>
</tr>
<tr>
<td>type</td>
<td>id=user_pass</td>
<td>time4test</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=wp-submit</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[@id='user_info']/p/a[2]</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>storedVars['arrayElements']=new Array("edit.php","upload.php","link-manager.php","themes.php","plugins.php","options-general.php","edit-comments.php")</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>storedVars['y'] = storedVars['arrayElements'].length;</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>-1</td>
<td>x</td>
</tr>
<tr>
<td>label</td>
<td>top</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>storedVars['x'] = ${x} + 1 ;</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>storedVars['thisval'] = storedVars['arrayElements'][storedVars['x']];</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>http://foundation.time2test.co.uk/wp-admin/${thisval}</td>
<td></td>
</tr>
<tr>
<td>gotoIf</td>
<td>${x}<${y}-1</td>
<td>top</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Log Out</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>------------------------------------------------
Here is the embedded video file:
notes
ReplyDeleteadd the script for goto at html copy and paste
show where to store it and how to point to it in the video.
I have modified the solution as per your comments, please review.
ReplyDeletehi, you still need to add the goto script here as text and some instructions on how to install it.
ReplyDeletedoes the video now show how to install the goto script?
Yes video now shows how to install goto script, I have also added goto script here as text.Ok I add the instruction how to install it as well.
ReplyDeleteDone, I have also put how to install goto script in selenium IDE.
ReplyDeleteNotes for viresh:
ReplyDeletechange the steps so that it reads more like an exercise.
Notes for Vipin:
ReplyDeleteneed to make this like an exercise.
E.g. take an existing script and add some more values to the array and then run it so that it demonstrates iteration through the loop. This is then the aim of the exercise!