I'm using Soda to write Selenium tests in Node.js and I have a situation where I have to press the down key several times.
The code currently looks like this:
browser
.chain
.setSpeed(200)
.session()
.open('/')
.click("id=save")
.focus(editor)
.keyDown(editor, '\\40')
.keyDown(editor, '\\40')
.keyDown(editor, '\\40')
.keyDown(editor, '\\40')
.keyDown(editor, '\\40')
.keyDown(editor, '\\40')
.keyDown(editor, '\\40')
.keyDown(editor, '\\40')
.keyDown(editor, '\\40')
.keyDown(editor, '\\40')
...
How could I DRY this up?
Just using a loop like this does not work with this lib:
var b = browser.chain()
for (var i = 0; i < 10; i++) {
b.keyDown(editor, '\\40')
}
Awesome ideas?
I could use the async API in Soda and for example async-lib to help me out, but that's not what I'm asking here. It makes some other things ugly.
You're close. You just have to change b in the loop so it chains correctly.
There is a method called
and
for doing complicated things in the middle of a command chain:See the README for more information: https://github.com/learnboost/soda
Did you try replacing the
b
variable in your loop?