Nightwatch.js installs a test environment through a configuration file

Noob Node Warning. How to programmatically establish which configuration object to use when starting a test?

It was quite difficult to find the final answer.

Setup:

/e2e-tests
    |-globals.js
    |-product.page.notify.stock.js
|-nightwatch.json 
|-nightwatch 

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
};
Run codeHide result

I saw this method here MateuszJeziorski , but omits the means to get the process arguments. The examples provided by the night review also do not answer this question. I think the end result of the command would look something like this:

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

+4
1

, , , 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.

+4

Source: https://habr.com/ru/post/1612580/


All Articles