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

      • <bdo id='Q5NZW'></bdo><ul id='Q5NZW'></ul>

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

        <legend id='Q5NZW'><style id='Q5NZW'><dir id='Q5NZW'><q id='Q5NZW'></q></dir></style></legend>

        在 selenium 中加载包含有用测试功能的外部 js 文件

        时间:2023-09-06
          <tbody id='4Xd2U'></tbody>

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

                  <legend id='4Xd2U'><style id='4Xd2U'><dir id='4Xd2U'><q id='4Xd2U'></q></dir></style></legend>

                1. 本文介绍了在 selenium 中加载包含有用测试功能的外部 js 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  selenium 中的 runScript 命令真的很有用,我用它来汇总表中的值,然后像这样存储值

                  The runScript command in selenium is really useful, and I'm using it to total values in a table and then store the value like this

                  <tr>
                      <td>runScript</td>
                      <td>var cumulative = 0.0; $('table.quote-review-group-component').eq(0).find('tr').each( function( i,el ){var singleStackTotal = $(el).find('td').eq(4).html();if( singleStackTotal ){cumulative += parseFloat( singleStackTotal.substring(1) );} }); cumulative = cumulative.toFixed(2)</td>
                      <td></td>
                  </tr>
                  <tr>
                      <td>storeEval</td>
                      <td>selenium.browserbot.getUserWindow().cumulative</td>
                      <td>cumulative</td>
                  </tr>
                  <tr>
                      <td>echo</td>
                      <td>${cumulative}</td>
                  
                      <td></td>
                  </tr>
                  <tr>
                      <td>verifyEquals</td>
                      <td>£${cumulative}</td>
                      <td>${total}</td>
                  </tr>
                  

                  理想情况下,我希望能够指向外部 js 文件,而不是将命令中的 javascript 作为字符串,这样我就可以加载一些测试函数并使用 storeEval 来获取函数的返回

                  Ideally I'd like to be able to point to an external js file rather than have the javascript in the command as a string, so that I can load in some test functions and use storeEval to get the return of the function

                  所以我们有

                  <tr>
                      <td>runExternalScript</td>
                      <td>/path/to/external/extra-tests.js</td>
                      <td></td>
                  </tr>
                  <tr>
                      <td>storeEval</td>
                      <td>selenium.browserbot.getUserWindow().getCumulative(0)</td>
                      <td>cumulative0</td>
                  </tr>
                  <tr>
                      <td>verifyEquals</td>
                      <td>£${cumulative}</td>
                      <td>${total}</td>
                  </tr>
                  

                  外部脚本看起来像这样

                  function checkSingleGroupListTotal( index ){
                      if ( index == "undefined" ){
                          index = 0;
                      }
                      var cumulative = 0.0; 
                      $('table.quote-review-group-component').eq(index).find('tr').each( function( i,el ){
                          var singleStackTotal = $(el).find('td').eq(4).html();    
                          if( singleStackTotal ){         
                              cumulative += parseFloat( singleStackTotal.substring(1) );     
                          } 
                      }); 
                      return cumulative.toFixed(2);
                  }
                  

                  考虑一个插件,它添加一个 loadScript 动作来检查外部 js 文件,然后将文件内容传递给 runScript 就可以完成这项工作.但我不想重新发明轮子,而且我之前从未构建过插件.

                  Thinking about it a plugin which adds a loadScript action which checks for the external js file and then passes the file contents to runScript would do the job. But I don't want to reinvent the wheel, and I've never built a plug in before.

                  推荐答案

                  runScript 命令只是将包含脚本的 <SCRIPT> 元素添加到 DOM 并让浏览器运行它.你可以自己做同样的事情,而不是使用内嵌脚本,使用 SRC= 属性来告诉浏览器要加载什么文件.您可能必须从 Web 服务器加载文件,因为某些浏览器不允许从网络加载的页面访问 file: URL.

                  The runScript command merely adds a <SCRIPT> element containing the script to the DOM and lets the browser run it. You can do the same yourself, and instead of an in-line script, use the SRC= attribute to tell the browser what file to load. You may have to load the file from a web server, because some browsers won't allow page loaded from the net to access a file: URL.

                  这篇关于在 selenium 中加载包含有用测试功能的外部 js 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Jquery 中正确使用 .on 方法 下一篇:量角器,我什么时候应该在 click() 之后使用 the

                  相关文章

                  最新文章

                    <small id='g96uQ'></small><noframes id='g96uQ'>

                  1. <tfoot id='g96uQ'></tfoot>
                  2. <legend id='g96uQ'><style id='g96uQ'><dir id='g96uQ'><q id='g96uQ'></q></dir></style></legend>
                      • <bdo id='g96uQ'></bdo><ul id='g96uQ'></ul>
                      <i id='g96uQ'><tr id='g96uQ'><dt id='g96uQ'><q id='g96uQ'><span id='g96uQ'><b id='g96uQ'><form id='g96uQ'><ins id='g96uQ'></ins><ul id='g96uQ'></ul><sub id='g96uQ'></sub></form><legend id='g96uQ'></legend><bdo id='g96uQ'><pre id='g96uQ'><center id='g96uQ'></center></pre></bdo></b><th id='g96uQ'></th></span></q></dt></tr></i><div id='g96uQ'><tfoot id='g96uQ'></tfoot><dl id='g96uQ'><fieldset id='g96uQ'></fieldset></dl></div>