How to loop chained calls elegantly in JavaScript/CoffeeScript?

偶尔善良 提交于 2019-12-04 19:16:39

There is a method called and for doing complicated things in the middle of a command 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.com/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')                                                  
}    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!