最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Nightwatch.js set testing environment via config file - Stack Overflow

programmeradmin3浏览0评论

Noob Node Warning: How do you programmatically set what config object to use when running a test?

Have been looking pretty hard for the definitive answer.

Setup:

/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 Overkill, and doesn't show implementation
  • productpage.notify.stock.js

var SITE_URL = '/', //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
};

Noob Node Warning: How do you programmatically set what config object to use when running a test?

Have been looking pretty hard for the definitive answer.

Setup:

/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 Overkill, and doesn't show implementation
  • 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
};

I have seen this method here by MateuszJeziorski but omits the means to get the process arguments. The examples provided with nightwatch don't answer this question either. I think the end result of the mand would look something like this:

nightwatch -somekindofparametertosetenvironment -t e2e-tests/product.page.notify.stock

Share Improve this question asked Oct 21, 2015 at 11:51 SimonSimon 2,6236 gold badges38 silver badges55 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

It sounds like you may be able to get what you need with multiple environments in the nightwatch.json file.

You can set up your test environments with something like this in 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 will let you pass in an environment with --env. Each environment can have unique global variables.

The 'default' properties are used in every environment unless they are specifically overridden.

Run a specific environment with a mand like nightwatch --env "other_environment". The environment will start up with the globals listed in nightwatch.json.

In addition to what @curtwphillips explained, you can also use nightwatch --config <config.file> to specify alternative configuration file.

发布评论

评论列表(0)

  1. 暂无评论