<i id='zULW9'><tr id='zULW9'><dt id='zULW9'><q id='zULW9'><span id='zULW9'><b id='zULW9'><form id='zULW9'><ins id='zULW9'></ins><ul id='zULW9'></ul><sub id='zULW9'></sub></form><legend id='zULW9'></legend><bdo id='zULW9'><pre id='zULW9'><center id='zULW9'></center></pre></bdo></b><th id='zULW9'></th></span></q></dt></tr></i><div id='zULW9'><tfoot id='zULW9'></tfoot><dl id='zULW9'><fieldset id='zULW9'></fieldset></dl></div>

        <tfoot id='zULW9'></tfoot>

      1. <small id='zULW9'></small><noframes id='zULW9'>

      2. <legend id='zULW9'><style id='zULW9'><dir id='zULW9'><q id='zULW9'></q></dir></style></legend>
          <bdo id='zULW9'></bdo><ul id='zULW9'></ul>
      3. 如何在 JavaScript/CoffeeScript 中优雅地循环链接调用?

        时间:2024-04-19
      4. <legend id='jP4jz'><style id='jP4jz'><dir id='jP4jz'><q id='jP4jz'></q></dir></style></legend>
      5. <small id='jP4jz'></small><noframes id='jP4jz'>

      6. <tfoot id='jP4jz'></tfoot>

                  <tbody id='jP4jz'></tbody>
                  <bdo id='jP4jz'></bdo><ul id='jP4jz'></ul>

                  <i id='jP4jz'><tr id='jP4jz'><dt id='jP4jz'><q id='jP4jz'><span id='jP4jz'><b id='jP4jz'><form id='jP4jz'><ins id='jP4jz'></ins><ul id='jP4jz'></ul><sub id='jP4jz'></sub></form><legend id='jP4jz'></legend><bdo id='jP4jz'><pre id='jP4jz'><center id='jP4jz'></center></pre></bdo></b><th id='jP4jz'></th></span></q></dt></tr></i><div id='jP4jz'><tfoot id='jP4jz'></tfoot><dl id='jP4jz'><fieldset id='jP4jz'></fieldset></dl></div>
                  本文介绍了如何在 JavaScript/CoffeeScript 中优雅地循环链接调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Soda 在 Node.js 中编写 Selenium 测试,我有一种情况,我必须按几次向下键.

                  目前的代码是这样的:

                  浏览器.链.setSpeed(200).会议().打开('/').click("id=save").focus(编辑).keyDown(编辑器,'\40').keyDown(编辑器,'\40').keyDown(编辑器,'\40').keyDown(编辑器,'\40').keyDown(编辑器,'\40').keyDown(编辑器,'\40').keyDown(编辑器,'\40').keyDown(编辑器,'\40').keyDown(编辑器,'\40').keyDown(编辑器,'\40')...

                  我怎么能把它弄干?

                  仅使用这样的循环不适用于此库:

                  var b = browser.chain()for (var i = 0; i <10; i++) {b.keyDown(编辑器,'\40')}

                  好主意?

                  我可以使用 Soda 中的异步 API,例如 async-lib 来帮助我,但是这不是我在这里要问的.它使其他一些事情变得丑陋.

                  解决方案

                  在命令链的中间有一个方法叫做and 用来做复杂的事情:

                  浏览器.链.setSpeed(200).会议().打开('/').click("id=save").focus(编辑).and(函数(浏览器){for (var i = 0; i <10; i++) {browser.keyDown(编辑器,'\40')}})...

                  有关详细信息,请参阅自述文件:https://github.com/learnboost/sodap>

                  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.

                  解决方案

                  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

                  这篇关于如何在 JavaScript/CoffeeScript 中优雅地循环链接调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Ember.js RC1 获取路由名称 下一篇:使用 Remotipart 解析错误

                  相关文章

                  <i id='gLJVT'><tr id='gLJVT'><dt id='gLJVT'><q id='gLJVT'><span id='gLJVT'><b id='gLJVT'><form id='gLJVT'><ins id='gLJVT'></ins><ul id='gLJVT'></ul><sub id='gLJVT'></sub></form><legend id='gLJVT'></legend><bdo id='gLJVT'><pre id='gLJVT'><center id='gLJVT'></center></pre></bdo></b><th id='gLJVT'></th></span></q></dt></tr></i><div id='gLJVT'><tfoot id='gLJVT'></tfoot><dl id='gLJVT'><fieldset id='gLJVT'></fieldset></dl></div>
                  • <bdo id='gLJVT'></bdo><ul id='gLJVT'></ul>

                    <legend id='gLJVT'><style id='gLJVT'><dir id='gLJVT'><q id='gLJVT'></q></dir></style></legend>
                  1. <tfoot id='gLJVT'></tfoot>

                    1. <small id='gLJVT'></small><noframes id='gLJVT'>