Wednesday, July 11, 2012

Selenium IDE Sideflow Update 2

I've updated the Sideflow (Selenium IDE Flowcontrol) plugin. You can download the latest version here: https://github.com/73rhodes/sideflow

The "gotolabel" command is renamed with camel-casing as "gotoLabel", so you may need to update your old Selenium tests if they use the old "gotolabel". Note that "goto" is a synonym for "gotoLabel", so if you wrote your tests using "goto" they should just keep working.

While I really appreciate contributions and suggestions, I've decided to remove the recent forEach additions. There were a few reasons for this.
  1. foreach functionality can be done with the existing while / endWhile commands.
  2. The implementation of foreach didn't actually provide a foreach command.
  3. Users reported errors in the new feature. Given (1) and (2) I wasn't really interested in debugging it.

To provide a simple way for users to build a collection, I added the "push" command. In Selenese, "push" works like you'd expect in JavaScript, except it will automatically create the array for you if it doesn't already exist.

So, to build up a collection, you can do this:

getEval | delete storedVars['mycollection']
push    | {name: 'darren', status: 'groovy'} | mycollection
push    | {name: 'basil', status: 'happy'}   | mycollection

Note the use of 'getEval' to clear the collection first. Unlike 'runScript', 'getEval' runs in the context of the Selenium object, allowing us to modify storedVars.

To do something with every item in the collection (like foreach), you can do this:

storeEval | storedVars['mycollection'].length | x
echo      | mycollection has ${x} items
while     | storedVars['x'] > 0
storeEval | storedVars.mycollection[${x}-1]   | temp
echo      | ${temp}
storeEval | ${x}-1                            | x
endWhile

10 comments:

Anonymous said...

Darren,
If you only wanted to pull part of the object, such as just the names, what would the syntax be?

storeEval | storedVars.mycollection[${x}-1].name | temp

This returns null.

Anonymous said...

Darren,
What would the syntax be if you only want to pull part of the object, such as the name?

storeEval | storedVars.mycollection[${x}-1].name | temp

This returns null.

Santeri said...

Hey!

I see that flow control doesn't handle spaces.

I need to get to specified label if specified variable contains specified text.

gotoIf | ${Variable} == "This text with space" | Thislabel

([error] Unexpected Exception: SyntaxError: missing ; before statement)

What can I do to make it work?

Darren said...

Hi Santeri, your problem has nothing to do with flow control, or spaces. The javascript you're using as a conditional isn't valid, so you're getting a syntax error. Try this:

gotoIf | storedVars['myVariable'] == "This text" | someTarget

Santeri said...

Thanks Darren!

Unknown said...

Hey Darren, thx for the guide. I wanted to ask how do i access an element on the array, like the name only?

Thx in advance

Darren said...

@Anonymous, try Object.keys

@Franco, the push command will just put things (objects, strings, etc) in an Array and to access them just use array indexes 0-n. for example echo | storedVars.myCollection[0].name | would print 'darren'

Anonymous said...

Thx for the answer.

echo | storedVars.myCollection[0].name |

only return
"storedVars.myCollection[0].name" as text.

I've tried other ways, but it always return a NULL value.

Check:
http://screencast.com/t/nM7FzWd4YRv

Im not a Java programer, so maybe I missing something basic.

Regards

Dano said...

Darren,
So we are not ready to use web driver so still using selenium-rc. I have been working with your selenium-ide flow control so i can do if...but I want to run my tests via seleniumHQ pugin in jenkins. This does not recognize any of the flow control statements. I can't seem to find the original flow control plugin for selenium-rc...can you help me find a verion of it so i can try to use this...we will probably move to web driver eventually, but for our basic tests, we are fine with RC...can you help me with this?
thanks
dan

Anonymous said...

Hi Darren,

I'm not able to access to name value on first element.

1) I've tried the line you suggested:

storedVars.myCollection[0].name

RESULT:
"storedVars.myCollection[0].name"

2) I've tried also with this:
javascript{storedVars['nameQuoteCollection'][0]}

RESULT:
"{name: 'darren', status: 'groovy'}.name"

Could you help me please?

Thanks in advance

Productivity and Note-taking

I told a friend of mine that I wasn't really happy with the amount of time that gets taken up by Slack and "communication and sched...