Noob Node 警告:如何在运行测试时以编程方式设置要使用的配置对象?

一直在努力寻找确定的答案。

设置:

/e2e-tests
    |-globals.js
    |-product.page.notify.stock.js
|-nightwatch.json
|-nightwatch
  • nightwatch.json = setup
  • nightwatch = #!/usr/bin/env node require('nightwatch/bin/runner.js');
  • e2e-tests/globals.js过度杀伤,并且不显示实现
  • productpage.notify.stock.js


  • var SITE_URL = 'http://dev.local/', //this needs to be set somehow production||dev
      AJAX_URL = 'ajaxproc/getrandomoutofstock', //relative so this doesn't need to change
      select = '#mysize',
      emailError = '.error-message',
      outOfStockItem = {
        id: false,
        url: false
      };
    
    module.exports = {
      'Get backorder stock url': function(browser) {
        browser.url(SITEURL + AJAX_URL)
          // ommitted for brevity
      },
      'Check notify stock on product page': function(client) {
    
        client.url(SITE_URL + outOfStockItem.url);
        // ommitted for brevity
      },
    
      // remaining test stuff - not needed
    };


    我有seen this method here by MateuszJeziorski ,但是省略了获取过程参数的方法。夜视仪随附的examples也不回答此问题。
    我认为命令的最终结果将如下所示:
    nightwatch -somekindofparametertosetenvironment -t e2e-tests/product.page.notify.stock

    最佳答案

    听起来您可以在nightwatch.json文件中的多个环境中获得所需的内容。

    您可以使用nightwatch.json中的类似内容来设置测试环境:

    "test_settings" : {
            "default" : {
                "launch_url" : "some_url",
                "selenium_port"  : 4444,
                "selenium_host"  : "localhost",
                "silent": true,
                "screenshots" : {
                "globals" : {
                    "site_url" : "some_site"
                },
                "desiredCapabilities": {
                   "browserName": "chrome",
                   "javascriptEnabled": true,
                   "acceptSslCerts": true
               }
            },
            "other_environment" : {
                "globals" : {
                    "site_url" : "some_other_site"
                }
            },
            "one_more_environment" : {
                "globals" : {
                    "site_url" : "one_other_site",
                    "other_var" : "this env needs a different variable"
                }
            }
        }
    

    Nightwatch将让您在--env的环境中通过。每个环境可以具有唯一的全局变量。

    除非明确覆盖了“默认”属性,否则将在所有环境中使用它们。

    使用nightwatch --env "other_environment"之类的命令运行特定的环境。该环境将使用nightwatch.json中列出的全局变量启动。

    关于javascript - Nightwatch.js通过配置文件设置测试环境,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33258577/

    10-09 21:21