全局变量文件阻止Nightwatch / BrowserStack集成运行

时间:2018-09-12 21:14:18

标签: javascript node.js nightwatch.js browserstack

我正在尝试使用本地浏览器集成和本地运行程序脚本对计算机上的VM运行Nightwatch测试。如果没有在browserstack.conf.js中指定全局变量文件,则测试将成功运行。

但是,当我在conf.js配置文件中链接我的全局变量文件时,我的测试抛出以下错误,指出我没有指定测试环境:

(注意:顶部JSON输出是我在globals.js文件中指定的自定义报告)

    [Local Runner] Test Suite
=============================

Bar?
{ passed: 0,
  failed: 0,
  errors: 0,
  skipped: 0,
  tests: 0,
  errmessages: [],
  modules: 
   { 'local.runner': 
      { completed: {},
        skipped: [],
        time: '0.000',
        timestamp: 'Wed, 12 Sep 2018 19:28:02 GMT',
        group: '',
        tests: 0,
        errmessages: [],
        failures: 0,
        errors: 0 } } }
Test report saved in /reports!
Connected. Now testing...
ERROR RangeError: Maximum call stack size exceeded
    at String.replace (<anonymous>)
    at CliRunner.replaceEnvVariables (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:118:37)
    at CliRunner.replaceEnvVariables (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:115:16)
    at CliRunner.replaceEnvVariables (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:115:16)
    at CliRunner.replaceEnvVariables (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:115:16)
    at CliRunner.replaceEnvVariables (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:115:16)
    at CliRunner.replaceEnvVariables (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:115:16)
    at CliRunner.replaceEnvVariables (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:115:16)
    at CliRunner.replaceEnvVariables (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:115:16)
    at CliRunner.replaceEnvVariables (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:115:16)
Error: No testing environment specified.
    at CliRunner.parseTestSettings (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:515:13)
    at CliRunner.setup (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:49:8)
    at /Users/matt.schlosser/dev/rba_test_automation/local.runner.js:19:18
    at Object.exports.cli (/Users/matt.schlosser/node_modules/nightwatch/lib/index.js:545:5)
    at /Users/matt.schlosser/dev/rba_test_automation/local.runner.js:17:20
    at /Users/matt.schlosser/node_modules/browserstack-local/lib/Local.js:62:11
    at ChildProcess.exithandler (child_process.js:267:7)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)

There was an error while starting the test runner:

Error: No testing environment specified.
    at CliRunner.parseTestSettings (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:515:13)
    at CliRunner.setup (/Users/matt.schlosser/node_modules/nightwatch/lib/runner/cli/clirunner.js:49:8)
    at /Users/matt.schlosser/dev/rba_test_automation/local.runner.js:19:18
    at Object.exports.cli (/Users/matt.schlosser/node_modules/nightwatch/lib/index.js:545:5)
    at /Users/matt.schlosser/dev/rba_test_automation/local.runner.js:17:20
    at /Users/matt.schlosser/node_modules/browserstack-local/lib/Local.js:62:11
    at ChildProcess.exithandler (child_process.js:267:7)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)

browserstack.conf.js:

var browserstack = require('browserstack-local');

nightwatch_config = {

    src_folders: ["tests"],
    globals_path: "globals.js",

  selenium : {
    "start_process" : false,
    "host" : "hub-cloud.browserstack.com",
    "port" : 80
  },

  test_settings: {
    default: {},
      firefox: {
          desiredCapabilities: {
              'build': 'nightwatch-browserstack-ff',
              'browserstack.user': process.env.BROWSERSTACK_USERNAME || 'KEY_VALUE',
              'browserstack.key': process.env.BROWSERSTACK_ACCESS_KEY || '1y3RMCxHWCBvJ5pehrHz',
              'browserstack.debug': true,
              'browserstack.local': true,
              'acceptSslCerts': true,
              'os': 'OS X',
              'os_version': 'High Sierra',
              'browser': 'Firefox',
              'resolution': '1024x768'
          }
      },

      chrome: {
        desiredCapabilities: {
            'build': 'nightwatch-browserstack-chrome',
            'browserstack.user': process.env.BROWSERSTACK_USERNAME || 'KEY_VALUE',
            'browserstack.key': process.env.BROWSERSTACK_ACCESS_KEY || '1y3RMCxHWCBvJ5pehrHz',
            'browserstack.debug': true,
            'browserstack.local': true,
            'acceptSslCerts': true,
            'os': 'OS X',
            'os_version': 'High Sierra',
            'browser': 'Chrome',
            'browser_version': '69.0 beta',
            'resolution': '1024x768'
        }
      },

      safari: {
        desiredCapabilities: {
            'build': 'nightwatch-browserstack',
            'browserstack.user': process.env.BROWSERSTACK_USERNAME || 'KEY_VALUE',
            'browserstack.key': process.env.BROWSERSTACK_ACCESS_KEY || '1y3RMCxHWCBvJ5pehrHz',
            'browserstack.debug': true,
            'browserstack.local': true,
            'acceptSslCerts': true,
            'os': 'OS X',
            'os_version': 'High Sierra',
            'browser': 'Safari',
            'resolution': '1024x768'
        }
      },

      edge: {
        desiredCapabilities: {
            'build': 'nightwatch-browserstack-edge-current',
            'browserstack.user': process.env.BROWSERSTACK_USERNAME || 'KEY_VALUE',
            'browserstack.key': process.env.BROWSERSTACK_ACCESS_KEY || '1y3RMCxHWCBvJ5pehrHz',
            'browserstack.debug': true,
            'browserstack.local': true,
            'acceptSslCerts': true,
            'os': 'Windows',
            'os_version': '10',
            'browser': 'Edge',
            'browser_version': '17.0',
            'resolution': '1024x768'
          }
      },

      ie11: {
        desiredCapabilities: {
            'build': 'nightwatch-browserstack-ie11',
            'browserstack.user': process.env.BROWSERSTACK_USERNAME || 'KEY_VALUE',
            'browserstack.key': process.env.BROWSERSTACK_ACCESS_KEY || '1y3RMCxHWCBvJ5pehrHz',
            'browserstack.debug': true,
            'browserstack.local': true,
            'acceptSslCerts': true,
            'os': 'Windows',
            'os_version': '10',
            'browser': 'IE',
            'browser_version': '11.0',
            'resolution': '1024x768'
        }
    }
  }


};

// Code to copy seleniumhost/port into test settings
for(var i in nightwatch_config.test_settings){
var config = nightwatch_config.test_settings[i];
config['selenium_host'] = nightwatch_config.selenium.host;
config['selenium_port'] = nightwatch_config.selenium.port;
}

module.exports = nightwatch_config;

globals.js:

///// REPORTING LOGIC

var fs = require('fs');



///// URLS

var pmSite = {
    url: "urlvalue.com"
};


///// LOGIN CREDS

var loginAccount = {
    loginEmail: "value",
    loginPass: "value"
};


///// REPORTER CALLBACK

function fileWriteErrorCallback(err) {
    if(err) {
        return console.log(err);
    }

    console.log("Test report saved in /reports!");
}


///// REPORT NAMING

function reportNaming() {
    var timeStamp = Math.floor(Date.now() / 1000);
    return "reports/test_run - " + timeStamp + ".json";
}

///// STRINGIFY JSON

function makeJsonString(results) {
    return JSON.stringify(results, null, 2);
}

module.exports = {

    loginAccount: loginAccount,
    pmSite: pmSite,

///// CUSTOM REPORTER
    reporter: function (results, done) {
        try {
            fs.writeFile(reportNaming(), makeJsonString(results), fileWriteErrorCallback);
            console.log('Bar?');
            console.log(results);
            done();
        } catch(err) {
            console.log('Foo');
            console.log(err);
        }

    }
};

local.runner.js:

#!/usr/bin/env node

var Nightwatch = require('nightwatch');
var browserstack = require('browserstack-local');
var bs_local;

try {
    process.mainModule.filename = "./node_modules/.bin/nightwatch"

    // Code to start browserstack local before start of test
    console.log("Connecting local");
    Nightwatch.bs_local = bs_local = new browserstack.Local();
    bs_local.start({'key': 'key_value', 'force': 'true'}, function(error) {
        if (error) throw error;

        console.log('Connected. Now testing...');
        Nightwatch.cli(function(argv) {
            Nightwatch.CliRunner(argv)
                .setup(null, function(){
                    // Code to stop browserstack local after end of parallel test
                    bs_local.stop(function(){});
                })
                .runTests(function(){
                    // Code to stop browserstack local after end of single test
                    bs_local.stop(function(){});
                });
        });
    });
} catch (ex) {
    console.log('There was an error while starting the test runner:\n\n');
    process.stderr.write(ex.stack + '\n');
    process.exit(2);
}

0 个答案:

没有答案