<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 中优雅地循环链接调用?

        How to loop chained calls elegantly in JavaScript/CoffeeScript?(如何在 JavaScript/CoffeeScript 中优雅地循环链接调用?)
      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 中优雅地循环链接调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  Rails 3.1 ajax:success handling(Rails 3.1 ajax:成功处理)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                  <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>

                            <tbody id='gLJVT'></tbody>

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