Wednesday, February 13, 2008

Selenium IDE Flow Control - Goto and While Loops

tldr; https://github.com/darrenderidder/sideflow

This extension provides goto, gotoIf and while loop functionality in Selenium IDE. Selenium IDE is a plugin for Firefox that automates the testing of web-based applications. There is an excellent flow-control extension at wiki.openqa.org/display/SEL/flowControl for the Selenium RC and TestRunner components, but it does not work with Selenium IDE (the Firefox plugin) directly. This makes it difficult to develop controlled test cases within Selenium IDE, and there are times when the frame-based TestRunner cannot be used (such as when the website under test employs a frame-buster script).

I've ported the existing control-flow extension to work in the Selenium IDE Firefox add-on. The image below shows a sample test case using goto, gotoIf and a while loop, all running successfully in Selenium IDE.



The file can be downloaded from Github and should be saved as "sideflow.js" to your hard drive. Then the Options settings in Selenium IDE should set the Selenium Core extensions to include the path of this file, similar to the image below.

I've published the extension on github.  Go ahead and download it from there. 


github.com/darrenderidder/sideflow

Update 26 February, 2008:
This mod of the FlowControl extension works only with the Selenium IDE Firefox add-on. If you want to use the TestRunner component or Selenium RC, please use the original FlowControl extension.

Update 19 February 2011

I've moved the extension over to github


Update 7 July 2011
I've updated the example to use the newer syntax required in the latest versions of Selenium IDE.

Please note that if you are using Selenium RC, you should use the original flow-control plugin here: wiki.openqa.org/display/SEL/flowControl



Unfortunately I haven't had the time or the need to make this compatible with both Selenium RC and Selenium IDE.  Please feel free to fork the code on github and make a pull request if you would like to help out.

Update 24 July 2012
I added a "push" command to the plugin, with a simple example on the Github page. This allows you to easily create a collection of items and implement "for each"-style functionality to iterate over it. Here's the original announcement

191 comments:

Anonymous said...

Sorry for the dumb question - but how would you use this extension to compare 2 URL's (or page Titles) for example?

E.g. if you are keep trying to open the same URL1 until the response changes from URL2a to URL2b?

Darren De Ridder said...

Sounds like you're trying to poll a page until something in the response changes. I should point out though that if you query URL1, the response will always be for URL1. You could get an HTTP 304 response that would trigger a redirect, where the browser issues a new HTTP request. Anyway, if all you want to do is poll a page until the title changes, your test case would look something like this:

openAndWait | http://arstechnica.com/index.ars
storeTitle | pageTitle
storeTitle | newPageTitle
while | storedVars['pageTitle']==storedVars['newPageTitle']
pause | 1000
openAndWait | http://arstechnica.com/index.ars
storeTitle | newPageTitle
endWhile
getEval | alert("The title has changed");

Anonymous said...

this script throws:
"missing = in XML attribute"
in the IDE

this is with selenium 8.7
:(

Darren De Ridder said...

Hi anonymous,
Please see http://www.webmasterworld.com/forum89/13847.htm

The flow control extension doesn't throw this error message. This one is generated by the JavaScript engine and is reporting an error in the page under test.

The flow control extension throws only the following error messages:
- non-matching while/endWhile found
- invalid row)nim specified
- specified label xyz is not found
- corresponding 'endWhile' is not found
- Corresponding 'While' is not found

Cheers...
D

Anonymous said...

Yours flowControl extension block IDE start command or other command if any comments exists.

The bugged row is #27
switch( command_rows[i].command.toLowerCase() ) {

Error message: command_rows[i].command has no properties

Anonymous said...

flowControl extensions seem doesn't work with xpath eval expression

count(//table//td) = 10
or
xpath=count(//table//td) = 10

Darren De Ridder said...

Anonymous #1

I've noted that the script doesn't handle comments as a feature request.

Anonymous #2
Your eval expression doesn't appear to be valid javascript. Note that the expression is passed directly to the eval() function and must be valid javascript / DOM code. This is not the same syntax that's used for Selenium locators.

The easiest solution is to set up your variables before a while or goto using the Selenium getEval command. The parameter to getEval is the Javascript needed to do your xpath lookup. For example:

getEval |
var currentWin = this.browserbot.getCurrentWindow(); storedVars['myLinks'] = new Array(); myLinks = document.evaluate("//a[starts-with(@href, '/mylink')]", currentWin.document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null); storedVars['myLinkCount'] = myLinks.length;

This can be followed by a conditional while or goto, ie:

gotoIf | ${myLinkCount} > 10 | myTarget

Hope that helps.

Also, please not that for support questions you should use the forums at http://www.openQA.org

Anonymous said...

to handle comments in Flow Control.
Add at line 27

if (command_rows[i].type == 'command') {
switch....
...
}

Darren De Ridder said...

anonymous, thanks for the tip, I've tested your patch and added it to the file linked here.

Zach said...

I'm sure I'm missing something basic here, but when I open Selenium after adding the extension, I get the following error:
Failed to load user-extensions.js!
files=C:\Documents and Settings\Administrator\Desktop\goto_sel_ide.js
error=SyntaxError: illegal character

This is with version 0.8.7. I've tried saving the file several ways, but always get the same error

Thanks!

Darren De Ridder said...

Zach,
There's something hokey about the way google docs saves a file. Just highlight the entire text of the file and copy-n-paste it into a new text file and save it as goto.js or whatever.
D

Zach said...

Darren, thanks for the tip. Turns out that I was saving in the wrong encoding. Switched to ANSI and it worked fine.

nothing said...

Hi,
I use Selenium Core with goto_sel_ide.js file. I added it to core\scripts and I have run my script with Tomcat. The 'while' loop in test script doesn't execute. And I change its name to user-extension.js. the error javascript is occurred. please help me

Darren De Ridder said...

This goto / flow-control script is only for Selenium IDE, the Firefox plugin. I know that it doesn't work with Selenium Core. For that, you need to use the original flow control extension (which you can find on the OpenQA website). Unfortunately I just haven't had the time (or the personal need) to modify my version of the code to work with both IDE and Core. Perhaps some L337 H4X0RZ out there will take up the challenge?

Anthony said...

Hi,
I'm trying to use this FlowControl extension for one of my tests and I'm running into problems.

Basically if my test is dependent on importing data. So, the first time I import the data I just hit next and proceed. But if for any reason I want to run the test again the first page is a replace page. Replace the existing data (yes/no). I want to set up my test to work either way so I don't have to code it to expect to say yes and replace like it is now.

Example.
First time it imports the data I want to execute this:
selenium.Click("ctl00_bottomButtons_lbNext");

Second time it imports the data I want to execute this:
selenium.Click("ctl00_contentHolder_lnkYes");
selenium.Click("ctl00_bottomButtons_lbNext");

I don't know how to get it to check and see if the yes control is there and if it is hit it else hit the next control. Make sense?

Darren DeRidder said...

Anthony,
Use any of the Selenium selectors to test for the presence of your reset element; assign the boolean result to a stored variable. Place a goto target in front of the "click next" line. Place an if statement in front of the "click yes" line, and use the boolean as the condition. See my Selenium Test Tips post for more information. What you're trying to do is fairly simple, I'm sure you'll get it going if you perservere... :-)

Anonymous said...

Is there a more complete syntax document for the conditions used by while and gotoIf? I'd like to:
|while|assertTextNotPresent|error
|click|//a[2]/img
|endwhile|

or something to that effect.

any suggestions?

Darren DeRidder said...

The conditions used by goto, if and while are simply snippets of JavaScript that get passed to eval() for execution and should return a value that can be interpreted as a boolean. Selenium itself provides a number of functions (eg. assertTextNotPresent, etc.) that return booleans and are documented on both the OpenQA website and within Selenium IDE itself. The underlying Prototype library provides syntax "shortcuts" like ${x}, although I recommend using the storedVars['x'] syntax (see my post on Selenium IDE test tips: http://51elliot.blogspot.com/2008/03/selenium-ide-test-tips.html .

AB1971 said...

Hi
Re: Selenium Flow Control

How can I create an Array and Iterate through it Selenium IDE or Core?

Thanks in advance

Darren DeRidder said...

Hi AB1971
If you use Selenium IDE, use my version of the goto extension, if you use Selenium core, use the original goto extension.

In Selenium IDE, to create and iterate over an array, you could do this:

getEval | delete storedVars['myarray']
storeEval | new Array('a','b','c') | myarray
store | 0 | x
while | storedVars['x'] < 3
getEval | alert(storedVars['myarray'][storedVars['x']])
getEval | tmp = storedVars['x'];tmp++;storedVars['x']=tmp
endWhile

Notice that I access the internal "storedVars" directly, rather than using the ${x} syntax, for reasons cited in my post "Selenium IDE Test Tips". Also note that you might want to grab an Array like document.images rather than the simple "abc" array I created in this example.

AB1971 said...

Hi Darren,
First, thanks for the quick respond. Second, your solution worked for me..THANK U SO MUCH, I AM MOST GRATEFUL !!!

AB1971 said...

Hi Darren

Just wonder, if you could tell what's wrong here, this loop works as expected in the selenium IDE, but when I try to run it in the selenium core. the first element is not pick up until the second loop. Also the If statement that pick up the desire html, appears to be picking up the wrong html (html A or htmlB or htmlC) . This is the skeleton step to test multilanguage website

Grateful for your insight..

storeEval | 0 | LoopCounter

storeEval | new Array('en','de','da','cs','fi','fr','it','ja','ko','nl','no','pl','pt','ru','sv','tr') | myarray

while | storedVars['LoopCounter'] < 10

storeEval | storedVars['myarray'][storedVars['LoopCounter']] | Lang

echo | ${LoopCounter
echo | ${Lang}

gotoIf | (storedVars['Lang'] || storedVars['LoopCounter'] )== " " | SkipLoop

store | | html

storeEval | if ( storedVars['Lang'] == "en" ) {html ='../tests/htmlA.html'} else if ( storedVars['Lang'] == "de ") {html ='../tests/htmlB.html'} else if ( storedVars['Lang'] == "da ") {html ='../tests/htmlC.html'} | html

echo | ${html} |

label | SkipLoop

store | javascript{storedVars.LoopCounter++}

endWhile

Darren DeRidder said...

ab1971,
I haven't tried running your script but the first thing that popped into my head was this sentence from my post on Selenium IDE test tips:

"Within a single Selenium command, if you modify storedVars['x'], the value of ${x} won't get updated until the next command."

I notice you're using a mix of the ${x} and "storedVars" ways of accessing variables -- try sticking with storedVars. Also, I'm not sure how Core uses storedVars; my version of the extension is for S-IDE, so if you need help with the Core version, please check out the OpenQA website forums.

Blake said...

Hi Darren

I would love to have flow control in the Selenium IDE but with 1.0b2 version, I get the following error after I load the goto_sel_ide.js extension:

"error loading Selenium IDE extensions: ReferenceError: Selenium is not defined"

Any ideas?

Darren DeRidder said...

Blake, please refer back to the original post and pay special attention to how you add the extension in the Selenium IDE Options panel. If you add it as an IDE extension rather than a Core extension, you will get the error you're seeing.

Dylan Hazlehurst said...

If you are getting an error you may need to add single quotes around your condition

e.g.
'storedVars{"companyRegisteredLegalNameVar"} = ""'


[error] Unexpected Exception: message -> missing ; before statement, fileName -> chrome://selenium-ide/content/tools.js -> file:///C:/selenium-extension/goto_sel_ide.js, lineNumber -> 82, stack -> (.....
, name -> SyntaxError

Dylan Hazlehurst said...

Actually you need to place the single quotes around any variables you are using in the condition check

e.g.
'${entityType}' == 'selectedType1'

Richard Foley said...

Brillian, Darren, just brilliant. Why this isn't in the core Selenium IDE is anyone's guess... Thanks for taking the trouble to make this work under the IDE!

Darren DeRidder said...

Thanks Richard. I think the webdriver team plans to integrate selenium into their work; maybe flow control will be part of it. Webdriver is geared towards coders, though, so we'll have to see if they get uptake.

Anonymous said...

Hi Darren
Thanks for a useful article.
I have had some success with your example, however the gotoIf does not find the second target, it reports [error] Unexpected Exception: message -> Specified label 'target2' is not found.
If the label is before the goto it works. Any advice please?
thanks
Mike (Poole, UK)

Darren DeRidder said...

Hi Mike,
I'd have to put your item in the "could not reproduce" category, since the example in the screen capture worked for me. You might want to check for typos, capitalized letters, or spaces in your label that you might not have noticed before. I really hope its just a typo and not really a bug, because furkelling around in the guts of Selenium isn't how I want to spend Christmas :-)

cheers

Mahesh said...

I have combined the Flow-Control extention (IDE and RC versions combined)) and Data-Driven extention and created a unified user-extentions.js. Now I'm trying to run a few data driven tests that are part of a test suite. The suite work perfectly in IDE. It is working perfectly in *chrome through RC.

java -jar D:\Selenium\selenium-server.jar -multiwindow -userExtensions "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\userExtentions\user-extensions.js" -htmlsuite *chrome http://www.google.com/ "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\Selenium IDE scripts\SuiteDataDriven.html" "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\Result\Result.html"



But when i try to run in *iehta with the following command




java -jar D:\Selenium\selenium-server.jar -multiwindow -userExtensions "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\userExtentions\user-extensions.js" -htmlsuite *iehta http://www.google.com/ "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\Selenium IDE scripts\SuiteDataDriven.html" "D:\MaheshN\Projects\LLP FTAF-Sel feasibility\Result\Result.html"



the following happens:

1) I get a dialog box with title "Internet explorer script error" and Message "error 'XML is undefined' do you want to continue running script on this page?" and buttons yes & no. I click the yes Button



2) It execute the open command (this happens to be the first command in my test) and then fails at the 'loadTestData' command. The result file contains the following error Unknown command: 'loadTestData'



Following is the content of the user-extentions.js file

//the content of the js is not accepted by the blog editor.

Am I doing anything wrong. It seems to work perfectly in *chrome.

Ibrahim Taha said...

Hi Daren,

I have added the *.js file to my hard drive and reflected in Selenium Options. When I try to run 'gotoif' command, i get the message:
[error] Unknown command: 'gotoif'

I'm running this on mac.

Any advise please?
Regards,
Abe

Darren DeRidder said...

Hi Abe,

This does work on a Mac, but your text-editing program might not save the code as plain ascii text. I opened up a terminal and used vi, but if you're not comfy in Unix-land, what I suggest is to take the CD of "extras" that came with your Mac and install the Developer Tools. Then under /Developer/Applications you can find Dashcode, a pretty decent text editor for coding. Btw I just tested out with Firefox 3, latest Selenium IDE, and Mac OS X 10, no problems.

The other thing to check is make sure you add the extensions under the Selenium Core section (see screenshot).

hope this helps,
Darren

jtbaca said...

I have a test in which I hit a URL that redirects to one of three pages.

After I get to one of those pages I want to assert of verify element on one of those pages. Can I use gotoIF to do that? The page I'm redirected to will be random.

Can you give me an example of selenium html code/syntax that will accomplish this task. Thanks

Abhishek said...

Hi,
I am new to Selenium IDE. I have to create a script for detecting cursor focus on any control when a page is visited. For that i have taken ID's of all controls into a variable using storeAllFields Command. I too have got length of that variable and using while loop, i have been able to move till the length of that variable.


Question is :- I am unable to get each value separately as we get in C or JAVA. How can i do that using Selenium IDE?

Darren DeRidder said...

jtbaca.

I'm not sure if I understand your question. I think what you want to do is jump to another section of your test if a certain element is on the page. For that, use "storeElementPresent" and use the result as the condition to "gotoIf".

Eg.
storeElementPresent|myElement|foundIt
gotoIf|foundIt|myTarget

Hope this helps,
Darren

Darren DeRidder said...

Abhishek,

You have to use Javascript syntax to access stored variables. I recommend using the storedVars['varibleName'] style of accessing stored variables. In your case you'll iterate as:
storedVars['myFields'][currentIndex]

That should give you access to each element in your array of IDs. Also see my post on Selenium IDE test tips for more info on variables.

Hope this helps.
Darren

Abhishek said...

Thanks Darren... it helped..... thanks a lot....

jtbaca said...

Hi Darren:
I have one of three pages that I will be randomly be redirected to as soon as I hit a URL for what I call a control page. THis page allows random redirection to any one of three pages.

When I get to one of those pages then I want to make many assertions on that page. I tried something like the following:

I want to do something like the following, but am not quite sure how to pull it off:

StoreLocation Store the URL's of all three possible pages that I could be redirected to as variables.

If redirected to page A assert elements on that page.
elseif redirected to page B assert elements on page B
elseif redirected to page C assert elements on page C

Then do it all over again a few times.

Thanks

swami said...

Hi D,

I'm a newbie to Selenium. Its been a couple of days since i made my hands wet in Selenium.

As you have mentioned in your other blog, Selenium does not have any kind of tech documentation so I'm finding it very very difficult to understand this tool.

Since I'm damn new I'm unable to say how great your tool is. But the comments from others makes me to give you 5 out of 5.

Great job...!!!!

Darren DeRidder said...

jtbaca,

You'll have to get the document.location to check the landing url against your stored URLs. Other than that, it sounds like your test is fairly straightforward. I you have questions related to Selenium syntax, check out the QA forums. They're a lot more active in answering questions than I am. :-)

Swami... good, hope it helps you out.

D.

Abhishek said...

are there any extension (js files) that deal with do-while loop or if statement or for loop.. in selenium ide???
Thanks,
Abhishek

Darren DeRidder said...

Abhishek - I'm not aware of any extensions that implement a do-while of foreach loop in Selenium IDE.

Toby said...

I think I've spotted a small bug in the javascript.

Line 98 reads:

var while_row = whileLabels.ends[ last_row ] - 1;

but I'm fairly sure the '- 1' is wrong, otherwise the flow is passed back to one line *before* the start of the while loop.

Otherwise, if you have a while loop starting on the first line (which is line 0 in in the whileLabels object created by initialiseLabels) then it tries to pass control back to line '-1' which fails, obviously.

At any rate, changing the line so that it reads just:

var while_row = whileLabels.ends[ last_row ];

gives the expected behaviour for me.

suraj said...

Hi,

I just started using Selenium and ran into your blog when I was looking for online help. Thank you for the information you have shared. It's a blessing for beginners like me.

The following question may be retarded but I am gonna ask you anyway...

I am trying to capture the (current) page title and compare it with a title I had captured earlier...

storeTitle||currentTitle
gotoIf|storedVars['currentTitle']==storedVars['classicTitle']|label1

WILL THIS WORK???

Also, How do I use the 'echo' command to make it print the value/text stored in the "currentTitle"???

Darren DeRidder said...

Hey Suraj, the only way to know if it'll work for sure is to try it and see! I also consider myself a beginner at Selenium, by the way. I used it for a few weeks and then moved on to other projects, so I'm probably not the best one to ask about all the various functions. What I've done in the past is use a Javascript alert call to pop up a message containing whatever text I wanted to see. You can find examples of that in my blog posts about Selenium.

Suraj said...

Darren,

Thank you for your response. The Javascript alert suggestion helped debug the issue I was facing.

Also, can you point me to any good online Selenium websites/ discussion forums??? [apart from your blog :)]

Thanks,
Suraj

Darren DeRidder said...

Visit openqa.org for Selenium related questions.

Winnie said...

I tried to use the gotoif command and it doesn't seem working for me. My Selenium IDE version is 1.0B2.

My issue is no matter the condition is met or not, Selenium keeps going to the step with the label "clickrenew".

Any help with this will be appreciated.

Here are the commands I have:
gotoIf |'${AutoRenew}' == true|clickrenew
label |clickrenew
click |CheckBox_RenewText

Darren DeRidder said...

${} is syntax from the Prototype library and doesn't return a boolean. See my other posts on Selenium as to why and how to use the stored variable cache instead.

M@rce said...

Excelente ayuda tanto para novatos como para expertos...gracias por compartir tus conocimientos y experiencia. Saludos desde Uruguay.

student said...

Hi,
First want to say thank you for your post and all comments. They are very helpful.
Could you please tell me where i'm wrong? I was trying to use one of your example from comments above to solve next problem:
I have an array with 3 link names
and i need to click them one by one

open| http://localhost/
storeEval| new Array('Worldwide','Asia','Europe')| myarray
store| 0| x

while| storedVars['x']<3| |

getEval| alert(storedVars['myarray'][storedVars['x']])|
store| storedVars['myarray'][storedVars['x']]| t
click| link=storedVars['t']|
getEval| tmp = storedVars['x'];tmp++;storedVars['x']=tmp|

endWhile|

Regards,
Oleg
Ukraine

Darren DeRidder said...

Hey Oleg

First of all, I would try to populate the array by looking up the items on the page (ie. by using XPATH) instead of hard-coding them.

Secondly, if you see an [error] link="Worldwide" no found, you have a problem with your locator. Google 'Selenium locator'.

Here's a suggestion: use the automatic recording feature on Selenium IDE to perform the actions you want to automate. Save the test and study it to see what kind of actions and locators you should be using in your hand-crafted testcase.

Keep working on it, you'll get it.

student said...

Hi Darren.
First whant to say thanks for quick reply.
I've resolved the problem in next way:

I was using:
click|link=storedVars['myarray'][storedVars['x']]
And it wasn't working.

Then I tried to use following:
click|javascript{'link='+storedVars['myarray'][storedVars['x']]}

And it works!

Apparently the problem was that Selenium didn't understand that storedVars['myarray'][storedVars['x']] is a variable and processed it as a text line.

Thanks a lot for your time.

Darren DeRidder said...

It seems strange to me that you had to use the javascript{} specifier. I've written a number of similar tests without it, but I didn't actually try to reproduce your test case. Maybe something has changed in the more recent versions of Selenium IDE. Thanks for sharing your solution.

Anonymous said...

I'm trying to get the IDE flow control code to work with the include code - includeCommand4IDE_1_1.zip (http://wiki.openqa.org/pages/viewpageattachments.action?pageId=283).
There are references to getting these to work together, but these seem to be for RC, not IDE - (http://wiki.openqa.org/display/SEL/flowControl) recommends:
if( htmlTestRunner.currentTest.initialiseLabels ) { htmlTestRunner.currentTest.initialiseLabels();
})

When running the test in IDE there is no htmlTestRunner.currentTest.initialiseLabels.

Is there an IDE equivalent reference I can use?

Thanks!
Brian

Darren DeRidder said...

Brian, welcome to the world of Selenium hacking ;-)

Anonymous, check openqa.org for intros and tutorials.

Anonymous said...

Yeah, the hacking part is alright - it's just tough to find stuff in the doc. I would think (and maybe it's there and I'm missing it) that it should be simple to find the equivalent IDE call for the RC "htmlTestRunner.currentTest.[whatever]", but I can't seem to find it anywhere. I've tried removing the htmlTestRunner. and added this. or Selenium. but to no avail...
I'll keep searching. Thanks,
Brian

Darren DeRidder said...

See my post on Selenium IDE tricks; there are a few scripts to expose S-IDE internals there.

Anonymous said...

Finally figured it out. As you've referred to in the past, documentation...there was a post in the wiki that had the call in the wrong function so this.initialiseLabels() call wasn't working. Thanks for the help. Time for a hair transplant since I just pulled out all of mine.

Brian

sow said...

I currently started using Molybdenum. Can I use this user-extension in Molyb. I tried but it is not working. any idea??

Darren DeRidder said...

No.

Anonymous said...

hey,
would someone tell me where the default commands in selenium ide are stored? if at all i have to modify them, how do i go about it?
thanks.

Darren DeRidder said...

See the post "selenium IDE tricks". There's some information on Selenium internals.

Anonymous said...

hi darren
would you tell me how can we generate random numbers in seleium IDE. actually I want to create unique Mail Id's to test a site. and give me an example of For loop in selinum IDE..

Regards
Suruchi

Darren DeRidder said...

Hi Suruchi,
If you haven't found a solution already, you'll just need to run a javascript statement to generate the random number. There's not Selenium command for it, per se. You can use eval or storeEval though, with the random-number generating script as a paramter.
cheers,
Darren

Syco54645 said...

Hello,

This was a great extension but we are trying to implement our test cases in selenium-rc and we are wondering if it is possible to use the while loops and gotos still. Please let us know if this is possible.

Darren DeRidder said...

Please visit the openqa site for the original flow control extension, which works with Selenium RC. My port of the extension is just for Selenium IDE (the Firefox plugin).

janet said...

Thank you - this is great!

When I store javascript{category} cat
I can then reference the variable and add additional text to it like this:

${cat} is the description of this item

But if I use getEval category=categoryName[index], as in the example, it won't resolve the variable and I get this:

javascript{category} is the desc...

Interesting and I'd love to know why.

Jonathan Brinkman said...

Darren - in your Selenium IDE hacks do you have a way to click Javascript links? standard "click" does in fact click the link, but then it sits there waiting for acknowledgment that apparently never arrives. I found the beatnikClick method but it doesn't always work, esp where the javascript link destination is written dynamically on pageload (so i don't know the ID until after the page is loaded). This is a Selenium bug. any work arounds?

sampablokuper said...

What license is goto_sel_ide.js available under?

If you haven't announced the license yet, might I ask that you do it under GPL, CC-SA, LGPL, Apache or something else that's compatible with the Selenium codebase and which also allows commercial use. The latter's important because of course most testers don't just test websites for fun; they do it for money too!

Thanks for the useful script!

Sam

Darren DeRidder said...

Selenium IDE is available under the Apache License. I'm not the original author of the FlowControl extension, which is a great extension except that it doesn't work in S-IDE. The original flow control extension, like almost every other extension for Selenium, doesn't specify licensing information. The copyright is owned by the original author so it's not my prerogative to specify an new or alternative license. The modifications I made to it are freely contributed back to the community in they spirit of open source software and collaboration. I haven't added any conditions on it's use beyond what may already have existed. Enjoy.

Anonymous said...

this script throws:
"missing = in XML attribute"
in the IDE



FWIW, this is exactly what you get on startup of selenium IDE if you blindly save the script directly with right click "Save link as" rather than following the link and cutting and pasting into a fresh .js file, since it is wrapped in html blurb due to google docs.

Dumb, but caught me out.

James O said...

Wonder if anyone is going to read this...
I tried to load this add-on, but got the following error message:

Failed to load user-extensions.js!
files=/root/my-documents/selenium automation files/goto_sel_ide.js
lineNumber=103
error=SyntaxError: missing ; before statement

Could my OS (Puppy linux) be the problem?

Michael said...

Would labels be recognized in other test cases within a suite?

i.e.

testcase1
label l1
gotoif true l2


testcase2
label l2


would testcase1 jump over to testcase2? I'll be testing this theory shortly, but thought I'd ask. I'll post my results.

myk

Anonymous said...

hi darren
i have gone through all the blogs...
i have been using selenium from since 5 days and i have a query when i try to execute the html suite from rc i get the following error

The error message is: No while statements found

i have generated a data driven script using while loop

Darren DeRidder said...

Hey Anonymous, you're going to have to use the original flow control extension for RC. The SIDE and RC versions aren't compatible. See the openqa site for the download.

Darren DeRidder said...

If you've got questions about how to use Selenium in general, check out the forums at openqa.org.

Ragavendra said...

thanks for the script Sir. Can stay with IDE itself..........:)

Shaila said...

Hi,Darren. I'm using Selenium IDE 1.0.4. I have used goto_sel_ide.js (downloaded from http://wiki.openqa.org/pages/viewpageattachments.action?pageId=407&metadataLink=true). I can run while loop without any error.

Problem is that I'm getting error msg while using 'gotoIf'.

Error msg:
[error] Unexpected Exception: message -> Specified label 'male' is not found., fileName -> chrome://selenium-ide/content/tools.js -> file:///E:/Salanium%20IDE/goto_sel_ide.js, lineNumber -> 81, stack -> Error("Specified label 'male' is not found.")@:0 ("male")@chrome://selenium-ide/content/tools.js -> file:///E:/Salanium%20IDE/goto_sel_ide.js:81 ("1<5","male")@chrome://selenium-ide/content/tools.js -> file:///E:/Salanium%20IDE/goto_sel_ide.js:90 ("1<5","male")@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 ([object Object],[object Object])@chrome://selenium-ide/content/selenium/scripts/selenium-commandhandlers.js:310 ()@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:112 (21)@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:78 (21)@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 , name -> Error

I'm using following code:

Open|http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_label

store|1|var_no1

gotoIf|${var_no1}<5|male

Would you please help me to get the issue resolved?

Anonymous said...

Forgive my ignorance but how do I just rerun a simple test. I am completing a series of web pages and inputting that data into a database. I would like to enter run that script 50 times how do i tell Selenium to do that?

Anonymous said...

Getting error message when I uploaded the .js file to Selenium IDE...
"Failed to load user-extensions.js!
files=D:\abcdefg\Automation\Selenium tool\datadriven\goto_sel_ide.js
lineNumber=103
error=SyntaxError: missing ; before statement". Please reply....

Anonymous said...

Hi Darren,
I am very new to Selenium IDE and have just figured out some basic and created simple tests. I need to do multiple iterations by passing different value to a particular field on the page. I am not sure how this can be done by using a file. Please guide me through.

Darren DeRidder said...

If you don't write your values in the test itself, and you want to pull them from a file, the only way I know of to do that in S-IDE is to write your own include file, like an extension. If you know JavaScript, it shouldn't be too hard. But you might want to consider Selenium RC, it's a more robust approach if you need to pull in external files and such.

Blake said...

Hi Darren,

At the top of the Selenium goto post you mention two extension files (one for RC/test runner, the other for IDE only). However, I see a link to only one file. Maybe I missed something?

BTW, nice pics at the top of your blog. I sail a Laser near San Francisco, and my son sails an Opti (http://www.blakeelder.com/opti-sailor/). That's a pretty sloop you have.

Thanks much!

Blake Elder

Darren DeRidder said...

Hi Blake,
Thanks. My version of the script is a hacked version of the original that you can find on openqa.org. The original one works in Selenium RC and TestRunner but I needed something to use in Selenium IDE (the Firefox plugin), so I ported it over. Unfortunately my version doesn't work with both RC and IDE.
cheers,
D

Anonymous said...

The IDE Flow control content was very helpful... Thanks a lot for sharing

I need urgent help regarding 2 things:

1. Is there a way i can parameterize my values for a script and run the scripts for multiple rows as provided by the Parameters/DataTable concept in QTP.


2. How can i create a batch script for a specific test case and a test suite.

Anonymous said...

Hi Darren,
In Selenium IDE I can save and open later individual test cases but not test suite. What I did before:
1) I click on Record and ran test scripts.
2) Save it as Test Suite (html format)
3) Opened SIDE 1.0.7 and File >Open Test Suite --> no Command list display


I have also tried to open New Test Suite before and create scripts and save them under the Test Suite with the same result >> NO COMMAND list displays.

Please help.

Thank you!

Alex.

manavK said...

Darren,

I am a little stuck in using the flow control in IDE. Any help will be appreciated.

I am trying to use it to check if a user is logged in to the website or not. If logged in then click on the link 'Sign Out' and then carry on with the test. If link 'Sign Out' is not present then it should carry on with the test as normal.

First I am running storeLocation|activeURL
this stores the URL.
The I am trying to use the following:

gotoIf | '${activeURL}'!='${baseURL}${indexPage}' | Sign Out |

now the label I am using here is the 'Sign Out' link. I learnt that i have to specify the label using the command 'label|Sign Out', before I can use it in the gotoif. Why do we do this and how can I use the label name? In my case the 'Sign Out' is a link and not a label. How do I specify the target location so that it clicks on 'Sign Out' when the activeURL does not match the storedURL (${baseURL}${indexPage} in this case).

If I specify the variables as:
gotoIf | 'storedVars['activeURL']'!='storedVars['baseURL']storedVars['indexPage']'; | Sign Out |
it gives me a message saying "Unexpected Exception: message -> missing ; before statement"

I hope I made sense.

Thanks in advance..
Manav

Darren DeRidder said...

Alex
Your question doesn't seem to be related to flow control. Visit the openQa forums for questions on using Selenium in general.

Darren DeRidder said...

Manav, in Selenese, a label has nothing to do with the content of the page. It's merely a text string that identifies a line in the test case that can be used by the goto command to tell Selenium which line of the test case to jump to. Your problem seems to be that you're confusing a label in a selenium testcase with a link in your page. They are not related in any way.

The goto label command will make selenium jump to the line with that label. It doesn't perform any actions at that line. It simply continues running the test case starting on the next line after the label. Which, in your case should be a click link command.

Carson said...

Daren,

I really appreciate all the help.

I recently started using the S-IDE client to verify links on my website.

I've tried implementing the techniques you've suggested, but keep getting the following error-

[error] Unknown command: 'while'

It seems that selenium doesn't recognize my while statement.

while | storedVars['index'] < storedVars['linkCount']

Every time I run the test, I get stopped at this step. It might be because I have stored all the link on the page into an array incorrectly.

Any suggestions to what might be happening?

Thanks a lot!
-Carson

Darren DeRidder said...

Carson,
It looks like you might not have loaded the extension properly. Otherwise, the while instruction would be recognized. Check the illustrations for comparison.

test said...

Hi I am Navdeep

I need a help on using a WHILE loop. In my application we have more than 60 links and I want to click on all those links using WHILE

dheer said...

Hi All,

May i know how you use If condition in case -

If logout link exits then click on the logout else click on the login link.

I am trying to use gotoIf, but could not get it working.

Please help!

Cheers,
DB

Anonymous said...

Hi,

I get the error :
Unknown command: 'gotoIf'
when i run the script from the command line as:
"C:\Program Files\Mozilla Firefox\firefox.exe" -chrome "chrome://selenium-ide-testrunner/content/selenium/TestRunner.html?baseURL=http://localhost&test=file:///C:\new.html&auto=true&resultsUrl=http://localhost:8080/results.html&save=true"

I have the user-extensions.js on the same folder with the suite

When i run the script from the bowser it is working ok.

Any help is highly appreciated

Darren DeRidder said...

Anonymous, there are two verions of the flow-control extension. This one is specifically for the Selenium Firefox Plugin (S-IDE). To use with the command line tools / testrunner you need to grab the original version (which unfortunately doesn't work with the Firefox plugin).

Sam Hasler said...

This doesn't seem to work with the include extension. If an include has happened before the goto it seems to jump to a row after the label, and if the number of lines in the include is more than the number of lines between the goto and label then the label will not be found at all.

Sam Hasler said...

Nevermind, I've found the problem and updated the include plugin's page.

Sam Hasler said...

Sorry, it was the flowControl wiki page I updated, not the include extension. The fix was to add:

if( this.initialiseLabels )
{ this.initialiseLabels(); }
at the end of doEnd$Template$ so that goto's after includes work.

Gabe said...

Sam,

I am wondering if you can clarify the solution for getting flow control and includes to play nice in the Selenium IDE... I have been pooring through forums all afternoon and am having trouble figuring out what I change where. Is there a way to get a download of the include extension that works with flow control in the IDE?

Any clarification would be much appreciated!

Gabe

sindu said...

Hi Darren,

Your posts on Selenium IDE have given lot of info. Thanks!

I am trying to loop through all links[around 200] in one webpage and see if each page has any errors. I use storeAllLinks which returns all Link ID's though when I want to loop through each I am unable to access each ID to be able to make it to click. Any inputs would be of great help!! Thanks

Matt Di Pasquale said...

Bug Report

Mac OSX 10.6.6
Firefox 3.6.13

You must be logged into https://www.facebook.com/ and have the always use SSL when possible account option selected for this to work.

This is to remove old Facebook events and (WARNING) is probably against their terms.

testCase:

<?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="https://www.facebook.com/" />
<title>facebook-remove-event</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">facebook-remove-event</td></tr>
</thead><tbody>
<tr>
<td>while</td>
<td>true</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>/?sk=pe</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=#contentArea li:first a</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Remove from My Events</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>remove</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>remove</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>

</tbody></table>
</body>
</html>


LOG:

* [info] Executing: |while | true | |
* [info] Executing: |open | /?sk=pe | |
* [info] Executing: |clickAndWait | css=#contentArea li:first a | |
* [info] Executing: |click | link=Remove from My Events | |
* [info] Executing: |waitForElementPresent | remove | |
* [info] Executing: |click | remove | |
* [info] Executing: |endWhile | | |
* [error] Unexpected Exception: message -> Invalid row_num specified., fileName -> chrome://selenium-ide/content/tools.js -> file:///Users/example/Documents/Selenium/selenium-ide-flow-control.js, lineNumber -> 62, stack -> Error("Invalid row_num specified.")@:0 (-1)@chrome://selenium-ide/content/tools.js -> file:///Users/example/Documents/Selenium/selenium-ide-flow-control.js:62 ("","")@chrome://selenium-ide/content/tools.js -> file:///Users/example/Documents/Selenium/selenium-ide-flow-control.js:100 ("","")@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 ([object Object],[object Object])@chrome://selenium-ide/content/selenium/scripts/selenium-commandhandlers.js:310 ()@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:112 (2)@chrome://selenium-ide/content/selenium/scripts/selenium-executionloop.js:78 (2)@chrome://selenium-ide/content/selenium/scripts/htmlutils.js:60 , name -> Error

Darren DeRidder said...

Matt,

I wouldn't be surprised if a good number of people are using Selenium to automate actions on third party sites, but you do have to be careful not to violate terms of use, which I'm SURE we all are! ;-)

Thanks for posting the issue, and by the way, I'll be moving the source file over to github shortly, where it should become a lot easier to pull in patches.

Anonymous said...

hi,

thank you for your post.
Very usefull :)

BR

Tarun K said...

Thanks for sharing this. Though I use Selenium RC, I would definitely use this plug-in for assisting me in manual testing of website.

Tarun K said...

Hit a blocker :-(,
I have selenium IDE 1.0.10 and having added the plug-in and restarted the Selenium IDE. I encountered the following exception -

"error loading Selenium IDE extensions: ReferenceError: Selenium is not defined"

Not sure if it is because of selenium IDE version which I am using but this is the latest version available SeleniumHQ -

http://seleniumhq.org/download/

Darren DeRidder said...

Tarun, tested in Se-IDE 1.0.10 on Mac OS X, Firefox 3.6.13, sideflow extension from github (as link in the blog post). Works okay.

Please use the above script linked to on my github page. I understand a plugin was made from this script. If you're having an issue with that plugin, you'll need to follow up with it's maintainer.

Anonymous said...

Hi
I have downloaded the .js file and saved in my disk then i have included the path in the selenium core extension. Then i reopened and
started testing.
without any conditional command it is working, but when i use while command, and execute my test cases then the entire test cases are not running.(i.e) when i press the play button it is not at all running.Please May i know what is the reason for this.

Darren DeRidder said...

Hi Anonymous,
What OS, Browser version and S-IDE versions are you using? BTW, you can head over to my Github page to get help with issues.
cheers,
Darren

Anonymous said...

Thanks
My browser version is 3.6.16
OS-XP service pack 2
selenium ide-1.0.10

ElsE said...

Hello Darren!

I've tried the next case on Selenium IDE.

store | 0 | i |
store | 6 | countryCounter |
while | storedVars['i']<=storedVars['countryCounter'] | |
getEval | storedVars['i']=${i} + 1; | |
echo | ${i} | |
endWhile | | |


I exepect 'echo' will prints a numbers 1-6.
Unfortunately it doesnt work. Stop executing on 'while' command with succes and commands in while block do not executing.
what is wrong?
will be very appreciated you for help.

R. M. Shiblee Mehdi said...

Is there a updated version of flow control for selenium ide 1.0.12 (which supports firefox-4 and firefox-5)?

Piyush said...

I had some trouble getting the array example posted on September 12, 2008 10:38 AM to work on my most recent install of the Selenium IDE (1.0.12)

Here is the original posting:

getEval | delete storedVars['myarray']
storeEval | new Array('a','b','c') | myarray
store | 0 | x
while | storedVars['x'] < 3
getEval | alert(storedVars['myarray'][storedVars['x']])
getEval | tmp = storedVars['x'];tmp++;storedVars['x']=tmp
endWhile


The biggest challenge was getting getEval to work. It is not offered as one of the commands in the Selenium IDE. runScript is the equivalent I found. I have not looked at the Selenium RC (or what is now called the Selenium Server). In any case, I got the equivalent example to work as follows:

storeEval | new Array('a','b','c') | myarray
store | 0 | x
while | storedVars['x'] < 3
runScript | javascript{alert(storedVars['myarray'][storedVars['x']]);1;} | 1
runScript | javascript{tmp = storedVars['x'];tmp++;storedVars['x']=tmp;}
endWhile

Note the use of javascript (referenced in post dated July 10, 2009 5:34 AM). I have needed to use that together with runScript.

Note also the trailing 1; in the javascript alert message and the 1
in the value field. Without that, the Selenium IDE shows the alert box - then logs the following type error:
[error] Unexpected Exception: message -> eval(match[1]) is undefined, fileName -> chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js, lineNumber -> 2530, stack -> ("javascript{alert(storedVars['myarray'][storedVars['x']]);}")@chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js:2530 ()@chrome://selenium-ide/content/selenium-core/scripts/selenium-executionloop.js:109 (0)@chrome://selenium-ide/content/selenium-core/scripts/selenium-executionloop.js:78 (0)@chrome://selenium-ide/content/selenium-core/scripts/htmlutils.js:60 , name -> TypeError

I believe the evaluation of the javascript result is being compared with the value field and a type mismatch is reported with just the alert (without the 1;) and the value field being left blank.

One last note to the newbie:
to download sideflow, from the Firefox browser, when I clicked on https://github.com/darrenderidder/sideflow and then right clicked on sideflow.js and then Save Link as, the sideflow.js itself did not get saved but sideflow.js.htm. This however is not the sideflow.js javascript and not surprisingly, the
extension would not work (for instance, while would not be offered in the list of commands in the IDE). I had to click on the sideflow.js link at https://github.com/darrenderidder/sideflow and then copy and paste the javascript form the browser to a text editor and save as sideflow.js

Darren DeRidder said...

Hey R.M

The extension is okay, but I updated the demo test and the image in this post to show the "new" Selenese commands. getEval has been deprecated, and you now have to use the "store" command with some funky casting instead of accessing "storedVars" directly. I never really liked accessing Selenium internals directly, so this is better now.

cheers
Darren

Darren DeRidder said...

Hey Piyush,
Thanks for the comments. I updated the demo test. Also, for downloading and working with github code repos, I'd definitely recommend using "git" or one of the graphical git clients. Github <3 git!

cheers,
Darren

sanju said...

Superb job done. Just adding one more thanks in the "infinite loop" of thank you message.
-Cheers

Darren DeRidder said...

Hi Sanju,
Andrey Yegorov is the original author of Selenium RC flow control; I merely ported it to the Selenium IDE plugin. Appreciate your comment, though.

Scott O said...

Is exporting to any language other than HTML supported? I'm having a problem, and would appreciate any input from the audience. I need to export to C# in order to integrate my Selenium tests into my software release process, the problem is all of the commands that are added thanks to this extension get commented out. For example, choosing the option to export to "C# (Remote Control)" for the test case included in the zip file results in a lot of lines of commented out C# code. I'm using Selenium v1.1.0 and I've downloaded the latest version of the IDE flow control extension. Thanks in advance!

Output code:

// selenium.Label("This is a test");
// selenium.Goto("label1");
// selenium.Label("label1");
String x = "1";
// selenium.While("${x} < 10");
// selenium.Label("loop");
// selenium.GotoIf("${x}==5", "got5");
// selenium.EndWhile();
// selenium.Goto("end");
// selenium.Label("got5");
// selenium.Goto("loop");
// selenium.Label("end");

Darren DeRidder said...

Hi Scott, I'm not sure why you're getting that. You probably want to check on the seleniumhq.com forums. Check out http://seleniumhq.org/docs/05_selenium_rc.html#from-selenese-to-a-program for an example of what the output should look like.
cheers
Darren

Rahul said...

I am getting same problem as Scott,
I had installed the plugin for Selenium IDE Flow Control
Extension.from: https://github.com/darrenderidder/sideflow
and restarted the firefor version5.
then when i started IDE the gotoIF command was available for use. I
did used it also. but when I exported the Code as c#(Remotecontrol)
format.and opened it in Microsft visual studio 2010. All the gotoIF
statements are not recognized by the Microsft visual studio 2010. all
statements are commented out.
and
code looks like this when opened in studio:

selenium.Click("css=input[type=submit]");
Boolean TP = selenium.IsTextPresent("User name already exists");
System.Threading.Thread.Sleep(sleeptime);
// selenium.GotoIf("${TP}==false", "target1");
System.Threading.Thread.Sleep(sleeptime);
// selenium.Label("target1", "UseName");
System.Threading.Thread.Sleep(sleeptime);

How can i fix this issue?If i remove the comments// then it says: you
are missing a directive or assembly reference.

And if i try to add reference to the sideflow.js file it is not
detected.because it is not a .DLL file.
Anyone knows how to fix this?

Darren DeRidder said...

Rahul,

Someone needs to patch the various code exporters to support the flow control commands, I guess. Really they should have been part of the core, but they're not. And that probably means you won't be able to export the control flow commands to C# without some tinkering in the Selenium source code itself.

Darren

Active Object said...

Hi

I am using selenium command Gotoif in Firefox Selenium IDE, and could able to run test suite, but when run the same test suite with selenium RC it fails showing "unknown command gotif" is there any way to solve this problem, selenium ide 1.1.0 version and jar for for selenium server is "selenium-server-standalone-2.0.0.jar"

can some one suggest how to solve this problem or i am doing any thing wrong

Thanks & Regards,
Sairam

Darren DeRidder said...

Sairam,
There is a flow control plugin for Selenium RC. You will need to use that in Selenium RC. It can be downloaded from the Selenium website, which lists plugins for Selenium RC. The flow control syntax should be identical.
Darren

Active Object said...

Thank you darren for the reply,

But i could not find the plug in for Selenium RC what ever the plug in it has it was for Selenium IDE,

Request you to provide the link, or path where it exists,

Thanks & Regards,
Sairam

Darren DeRidder said...

Hello Active Object
I've updated the article with a link to the original flowControl plugin for Selenium RC.
cheers,
Darren

Jay said...

Hi Darren,
I have a scenario where I need to click on a link in the dynamically created row.

1. Create a new user.(e.g., Testuser)
2. In the home page, the users are listed but the list is not sorted.
3. Now I need to click on delete link in row. After adding the new user, the page looks like below.

Newuser Edit Delete
Testuser Edit Delete
Realuser Edit Delete

The Delete link has ID which is GUID and none of the link's attribute contain Testuser.

Now, how to delete Testuser by clicking the delete link present in the same row?

Thanks in Adv

Darren DeRidder said...

Hi Jay,
You can do that with XPATH. XPATH is a pretty broad topic in itself. You can get started using Firebug to look up the XPATH syntax for the element you want to select, although in your case you'll probably need to modify it to reference the element that contains the "TestUser" text.

Hope that helps.
Darren

Jay said...

Hi Darren,
Yes I did it. Thanks a lot for your suggestion
Cheers
Jay

Marius said...

Hi Darren,

I am new to Selenium, and to this extension, but i cannot find anywhere on the net some explanations about how it works. Can you please give me some details, or direct me to the correct place.
What does "label", "gotolabel", "gotoif", "while" ? And how it works ? Just need to understand the principle behind.

Darren DeRidder said...

Marius, you are looking for http://seleniumhq.org

Happy reading!

Anonymous said...

When I try to include it (restarting the selenium ide):
Failed to load user-extensions.js!
files=/home/bla/data/selenium_extension/sideflow.js
lineNumber=6
error=SyntaxError: missing = in XML attribute

Anonymous said...

Fantastic plug in. I've used it to do some really tricky tests.

Currently it doesn't work with Firefox 7. Any plans to update it?

Regards,
Simon

Darren DeRidder said...

Simon
On my Firefox 7 / Ubuntu setup it does work, but the "runScript" command fails with the sample test case. By replacing "runScript" with "getEval" everything works again.

Thanks for the heads up, not sure what is going on here exactly but will look into it and patch up the testcases as needed on github.

Darren

Simon said...

Thanks for the tip.

When I used the link below it refused to let me add it.
https://addons.mozilla.org/en-US/firefox/addon/flow-control/

I'll just add the javascript reference instead.

Andrew said...

Hi, everyone.
I've a problem with selenium IDE.
So I must to some names from the page and put them into the array.
I take them from the page without any problems by storeText|xpath=//div[@id='main']/div[3]/ul/li[${i}]
but don't know how to put them into the array.
Help please.

Andrew said...

Hi,everyone.
I have a such problem: I take some names from the page by
while|condition
storeText|locator|variable
but I can't to put them into the array.
Help me please.
I work with selenium IDE.

Murugan said...

Can any one tell me how use selenium IDE for data driven testing

Nicholasjh said...

Hello Murugan, Here is a page explaining data driven set up for IDE:: http://wiki.openqa.org/display/SEL/datadriven Works quite well, I'm not sure if the datadriven commands (namely importing the xml as variables) will transfer to RC code if that is your intent. Note after setting up the data variables in xml you can import to excel and add more iterations there. Note the comments section it includes xml formatting:

tdata>

Shane said...

Is this now gone? trying to read up on data-driven testing using IDE but every page takes me here but i cant find the needed download lol

Nicholasjh1 said...

@shane , no datadriven is not gone. as it says you do need to install sideflow and include, but on the datadriven page is also the datadriven.js it is in the paperclip link with the 2 by it (2 files). Don't worry, I don't always find the download links on these sites to be easy to find either.

Anonymous said...

@Shane Oops I see what you mean, the blog indicates where the sideflow extension now resides... which is https://github.com/darrenderidder/sideflow

Anonymous said...

@Shane github.com/darrenderidder/sideflow
lol

Lee said...

Hi Darren, First I want to say thanks for taking the time to create these tips and answer questions. Like many here I am new to Selenium (and relatively new to scripting). Your array example from Sept. 12, 2008 was a revelation to me. But I am missing a key part. I need to be able to dynamically enter values into an array and I just can't seem to find the combination. I tried modifying your example so that instead of printing out values I was storing values but no luck. Is there an example of populating an array in a loop?

Lee said...

Hi Darren, First I would like to say thank you for taking the time to post these tips and answer questions. Your array example posted Sept. 12, 2008 (but found by me much later) was a revelation. I am extremely grateful for it. Now I need to populate an array in a loop. I tried to use your example but modify is to store the value into an array. I am having absolutely no luck. Do you have an example of populating an array?

Darren DeRidder said...

Hi Lee, glad if this was helpful. You should easily be able to populate an array within a while loop. Evidently the getEval command has been replaced with a runScript command (as noted here: http://51elliot.blogspot.com/2011/07/selenium-ide-sideflow-update.html ). Anyway, the basic idea is to make a while loop, and then use snippets of native javascript within the loop to do whatever you want, such as populating an array. If I have time I'll try to post an updated example.

Lee said...

Hi Darren, again thanks for all your time and effort on this blog and for the response. It's incredible and incredibly nice to share your experience. I have muddled through and found a way to populate the array. I would still love to see an example if you would happen to get the time but it's not as urgent as it was when I initially posted. THANK YOU SO MUCH!

LearningSelenium said...

How to get no of rows/column in a table via selenium IDE commands?
I used "storeXpathCount" but did not get the correct answer.

Please help me in getting the same.

Darren DeRidder said...

LearningSelenium, I'd craft a small script to count rows/columns in your table first (try it using firebug console). In your script, once you've selected your table element you might try using the getElementByTagName to collect all the TR's, rinse and repeat for TD's. Once you have the code to return the number of rows and columns, incorporate it into your selenium test using the runScript command.

Darren DeRidder said...

Actually there's an easier way:

Using Base URL http://www.tizag.com

open /htmlT/tables/php

storeXpathCount /html/body/table[3]/tr rows

getEval alert(${rows})

Darren Woodall said...

Sorry for such a basic question but how the hell do I get If... elseIf to work via selenium-server-standalone-n.nn.n.jar using -htmlsuite?

All I get is "Unknown command: 'if'".

I've been searching for hours and hours and hours to no avail - please help before I go insane!

Is it maeant to be part of Core or via a User Extension?

Darren DeRidder said...

Hey Darren, that's a pretty common question actually. This extension for the Selenium IDE firefox plugin is a port of the original control flow extension that can be used with the selenium server. You can find that extension on the OpenQA / Selenium website.

heli2reg said...

Hi Darren - I am somewhat surprised that I haven't found this question here before - or maybe I am missing something: Apparently, nested while is not supported at this time.
Have you ever attempted to add this feature? Any ideas in terms of level of effort? - Thank you!

aditi said...

Hi, not able to open the "github.com/darrenderidder/sideflow" link. please help me out.

Darren DeRidder said...

I updated the links; they should work now. Or, just copy and paste the link into your browser's location bar.

Jake said...

Hi Darren,

I downloaded sideflow and placed the file path in options. However, I'm such a novice I am at a "Now what" moment.

I have an asp app that has dynamic buttons. If the Expand button (id=submit8)is pressed, the page sections expand and the Collapse button (id=submit9) is displayed in the same place.

Likewise, when the Collapse button (id=submit9)is pressed, the page sections collapse and the Expand button (id=submit8) is displayed.

I need the test to evaluate the the button and if the Expand button (id=submit8) is displayed, press it; otherwise goto the next command.

Can I do this with sideflow? If so, how best to format the test?

Thanks in advanced,
Jake

Darren DeRidder said...

Hey Jake
I think you should definitely be able to do what you're describing. The trick will be to figure out the condition for the gotoif command. I think you will just need to make sure that the button is present and visible. It depends on how your page is structured and whether the buttons are dynamically added and removed from the DOM or merely hidden. To start out you can try recording a simple test case by right clicking on the buttons and using Selenium IDE's built-in assert commands. The resulting test case should give you some ideas about how SIDE identifies the elements in question. You can also use Firebug and/or FIrepath to figure out the XPATH for the elements in question and use that to identify the buttons in your test case. Evidently Selenium also now supports CSS selectors, which most people find a lot easier to use. Anyhow, some combination of CSS selector, gotoif and voodoo magic will undoubtedly lead to success...

Nelson said...

I am newbe to Selenium.

I can’t figure out why the last two lines are false. I think they should be true.

Using the datadriven extension:
SSNNeeded = “1”

echo javascript{storedVars.SSNNeeded=="1"} gives true
echo javascript{storedVars.SSNNeeded}
gives 1
gotoIf b=(storedVars.SNNNeeded=="1") next gives false
echo javascript{b}
gives false

ravi teja said...

hi,i have an application in which i need to select all the options in the dropdown , can i implement loop to select all the options in application using selenium ide ? do i need to write java script coding for that ?
Please advise me.
Thanks & Regards.
Ravi Teja

Darren DeRidder said...

Ravi
It depends on what you're trying to do. Generally, if you need flow control for you test case, it should be obvious. In your case, you can probably just select items serially, performing validation after each selection. Iteration makes sense when there is variability in the data set or you don't want to keep repeating the same commands manually.
Darren

Anonymous said...

To the above comment with the error message "missing = in XML attribute": that happens if the js-file contains wrong content (e.g. html-code). Open the js-file and make sure that the content is just js-code.

Anonymous said...

Hi Darren,

I am unable to download the Sideflow extension. Is it not a free download?

Darren DeRidder said...

Anon. It's available for download from the github link at both the top and bottom of the post. Follow the instructions in the article regarding how to load this extension.

Nacho said...

I have Selenium IDE 1.10.0 in Firefox Win 7 x64... and I have this error:

[error] Unknown command: 'while'

I downloaded the file from github.. and nothing..

Anonymous said...

I've downloaded the file, and followed your instructions. When I launch IDE, the following message when I launch the IDE via Firefox:

-----------
Failed to load user-extensions.js!
files=C:\Users\eh\Desktop\sideflow.js.htm, C:\Users\eh\Desktop\sideflow.js.htm
lineNumber=4
error=SyntaxError: missing = in XML attribute
-----------

Can this error be resolved? How?

Hideki said...

Seems that I am experiencing the exact same issue that Nacho has. None of the sideflow commands are working for me. I've consulted with a few others that I know that use it and don't see anything I might be doing wrong.
I am using Selenium IDE 1.10.0 as well in the most recent version of Firefox (18.0) but running Ubuntu 10.04.4
Also downloaded the file from github. Just in case, I'll denote that I tried the demo file and that didn't work either, which wasn't surprising for me as none of the sideflow specific commands have been working.

Michael Reid said...
This comment has been removed by the author.
Michael Reid said...
This comment has been removed by the author.
Darren DeRidder said...

Use a valid JavaScript expression as your conditional.

Michael Reid said...
This comment has been removed by the author.
Darren DeRidder said...

Anonymous, looks like you tried to save the html page off github. Get the actual js file and load that instead.

Aleksandra C said...

Hi,
Is there a FlowControl version which works with Selenium RC 2 (added as an extension in start cmd)?
I get the test hang and in IE I have an error about testCase which is not defined.

James said...

I'm using Selenium IDE 1.10.0, and have added the sideflow.js to my extensions, but when I try to execute a "while" command, I'm getting a "[error] unknown commend : 'while'".

Any ideas?

[info] Executing: |while | ${index} < ${fVals}.length | |

[error] Unknown command: 'while'

Darren DeRidder said...

Make sure you add sideflow.js to your Selenium Core extensions, not the Selenium IDE extensions. It's a common mistake, but this script actually extends the core functions.

Cody Echtermeyer said...

I am trying to verify some static content on a page. I want to selenium test to repeat the test until the value is present. How would this be done?

Darren DeRidder said...

As far as I know you can't repeat a test case but you can loop within the test case and poll like in the first question posted in the comments. Just use a while loop, query, pause and set a conditional to break out of the loop.

Anonymous said...

Hi Darren,

first of all I'd like to thank you for the incredible amount of efforts you have put into your work to the benefit of quite a lot of people.

Now, here's my question.
As an exprienced tester and with some knowledge around scriptingand automation, I seem to got confused with all the IDE vs. core vs. RC vs. Webdriver talk in the Selenium microcosmos.

What I am looking for is a solution that allows me to do conditional flows and loops in Selenese and being able to use that while working inside the IDE as well as when the Selenese scripts are processd against the "standalone server".

What is the right selection of plugins, scripts, etc. and where/how do I have to install them?

From my understanding, when you say it is an extension of the IDE but needs to be installed as a core extension, I assume that it exactly does what I need:
Provide me with "functions" that will run both in the IDE as well as when used with the standalone server jar of Selenium.

TIA for any pointers, cheers,
Thomas

Darren DeRidder said...

Hi Thomas,

Selenium IDE settings has a place to add core extensions but sadly the original flow control extension did not work in Selenium IDE, which is why I needed to port it. It still needs to be added as a core extension in S-IDE; if you're running Selenium RC you need to use the original flow control extension. I'd like to support both but it just hasn't been a priority. Maybe somebody else would like to contribute code via GitHub for that? I doubt we will see flow control natively in Selenium because the original authors seem to think that flow control in test cases is just plain wrong. I don't think they envisioned a lot of the use cases people are doing with it today.

D

Anonymous said...

Hi Darren,

thanks a lot for the fast response!

My intention is to have easy-to-maintain scripts, as most of my peers are junior testers with almost no exposure to scripting, automation or programming. Selenese scripts are fine for that.
However, equally important is the reusability of the scripts in nightly runs, thus "unattended" mode to put it that way.

So far, what we are doing is to run the Selenese scripts (used in the IDE) against the "standalone-server" jar.

(I call it "standalone-server" jar because I have no clue if this is the "RC" or "core" or whatever name it was given... just making sure I don't mess up things.)

If I get you correctly, this means that a Selenese script that uses e.g. "gotoIf" will run just fine in the IDE but not when the Selenese is used for execution with the standalone-server jar?

Cheers,
Thomas

The Whitsitt's said...

I have about 100 scripts in S-IDE that use GoToIf to determine if the user is logged in before a case begins. All was working splendidly for many months until Firefox updated, and I updated Selenium IDE to 2.0.0.

Now, after adding sideflow.js the GoToIf command is not shown. The test case fails on that step with [error] Unknown command: 'gotoIf'.

I've tried all kinds of variations, including goto_sel_ide.js. Is GoToIf and the sideflow.js just not supported in IDE 2.0.0?

Preeti Valand said...

Hiya,

I've parametrized all the variables. However, When I run it in from a batch file, I get a message stating: Threw an exception: AdminEmailAddress is not defined.
(tryin to enter an email add from the .js file)

It runs fine on firefox when I have selenium loaded and running, but only hit the problem when running the suite through a batch file.

Any help on this matter will be appreciated.

Jaime S.G. said...

Hi, is there any posibility of cut a string? I mean, if a value is stored and only a part of it is needed. I tried with the "substring" function of xpath but didn't work. I'll appreciate any help.

Regards

Jaime S.G. said...

Hi, is there any posibility of cut a string? I mean, if a value is stored and only a part of it is needed. I tried with the "substring" function of xpath but didn't work. I'll appreciate any help.

Regards

Jaime S.G. said...

I've just found a solution:

http://stackoverflow.com/questions/12537620/is-there-a-way-to-split-a-string-into-an-array-in-selenium-ide

Thanks

Anonymous said...

Howdy. Long time lurker, big time S-IDE fan. Is there a way to use a variable within a Label name? Thanks!
El Gato

Francois Attadedji said...

Hi Darren,
I am learning Selenium IDE and have got to the flow control part. I couldn't make it work. Do you have any videos that might help me understand how this work? Thanks.

edszr said...

Hi there,

We typically use Selenium IDE to build our tests and run them in firefox. The we use webdriver to run our tests in chrome, IE and safari. I've seen that the flow control commands don't work in webdriver...is there a get around for this? Flow control has been really useful for us :) Thanks for all your hard work on this.

Ed

Darren said...

Sideflow is a port of the original flow control extension for Selenium RC. I haven't used webdriver but you can find the original plugin on seleniumhq.com.

Alisson said...

Hello Darren..

I'm getting a issue to use the "gotoIf" option.

How can I use it to jump to another line if a element is/isn't there??
What I'm doing is:

|storeText | id=formCadastroOfertaLance:data:0:j_id222 | lance |
[info] Executing: |gotoIf | "${lance}"=="Lance Livre" | label1 |

the problem is: when (...):j_id222 doesn't exist, I got an error and the script stops.


How can I do that "gotoIf" using as parameter if this element exists or not??

Darren said...

Alisson, use storeTextPresent | id=foo | bar to create a true/false boolean, then use gotoIf | storedVars['bar'] | target.

Although, if your application has scenarios where sometimes things are present and sometimes not, maybe it is too complicated. Or maybe you should have different test suites and not try to cover too many scenarios in the same test suite.