【问题标题】:How can we execute a query only one time for all browsers while doing parallel execution我们如何在并行执行的同时对所有浏览器只执行一次查询
【发布时间】:2018-10-11 21:13:22
【问题描述】:

我正在使用量角器 5.2.2 和 cucumber 3.2.0。我正在通过指定以下给出的多种功能进行并行执行。

multiCapabilities: [
{
browserName: 'chrome',
},
{
browserName: 'chrome',
}],

我只需要为所有浏览器执行一次查询。但是现在该查询正在为每个浏览器执行。我怎样才能将此查询设置为仅在通过命令“量角器”运行脚本时执行一次conf.js'。

【问题讨论】:

    标签: protractor cucumber cucumberjs


    【解决方案1】:

    你可以试试protractor conf.js的beforeLaunch()

      /**
       * A callback function called once configs are read but before any
       * environment setup. This will only run once, and before onPrepare.
       *
       * You can specify a file containing code to run by setting beforeLaunch to
       * the filename string.
       *
       * At this point, global variable 'protractor' object will NOT be set up,
       * and globals from the test framework will NOT be available. The main
       * purpose of this function should be to bring up test dependencies.
       */
      beforeLaunch?: () => void;
    

    conf.js

      exports.config = {
    
          multiCapabilities: [],          
    
          specs:[],
    
          beforeLaunch: function(){
               // execute query at here
          }
          ...
      };
    

    【讨论】:

    • 非常感谢 yong ..它对我有用。但是如果我在 beforeLaunch 函数中有一个参数并且如果我需要在我的配置文件或其他一些火灾中使用它,我如何从 beforeLaunch 访问它功能。
    • 如何指定参数值?从 cmd 行或配置文件中的硬编码传入某处。请出示。
    • 我将通过在 beforeLaunch 函数中执行查询来获取该参数或变量。我的目标是通过此参数或 beforeLaunch 函数中的变量动态设置 multiCapabilities。我已在此链接“@ 987654322@"
    • 年轻..这样可以吗?
    • 您是否要查询该问题中发布的数据库:stackoverflow.com/questions/52754976/… 以获取线程值,然后根据线程值生成多重功能?如果是这样,我可以将这 3 个问题混合在一起给出解决方案。
    猜你喜欢
    • 2019-08-13
    • 1970-01-01
    • 2020-06-26
    • 2014-02-27
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 2014-03-06
    相关资源
    最近更新 更多