admin管理员组文章数量:1335380
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.
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.
Share Improve this question asked Sep 26, 2011 at 14:59 esamattiesamatti 19k11 gold badges81 silver badges83 bronze badges 2- What does the loop actually do? One keydown? – Robert Harvey Commented Sep 26, 2011 at 15:01
-
Try moving
chain
inside the loop, as inb.chain.keyDown
– Robert Harvey Commented Sep 26, 2011 at 15:02
3 Answers
Reset to default 4There is a method called and
for doing plicated things in the middle of a mand chain:
browser
.chain
.setSpeed(200)
.session()
.open('/')
.click("id=save")
.focus(editor)
.and(function (browser) {
for (var i = 0; i < 10; i++) {
browser.keyDown(editor, '\\40')
}
})
...
See the README for more information: https://github./learnboost/soda
Did you try replacing the b
variable in your loop?
var b = browser.chain()
for (var i = 0; i < 10; i++) {
b = b.keyDown(editor, '\\40')
}
You're close. You just have to change b in the loop so it chains correctly.
var b = browser.chain()
for (var i = 0; i < 10; i++) {
b = b.keyDown(editor, '\\40')
}
本文标签: How to loop chained calls elegantly in JavaScriptCoffeeScriptStack Overflow
版权声明:本文标题:How to loop chained calls elegantly in JavaScriptCoffeeScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742227012a2436510.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论