如何让Nightwatch.js在Internet Explorer上运行测试

时间:2017-09-21 14:37:53

标签: node.js selenium internet-explorer automated-tests nightwatch.js

我试图在Internet Explorer,Chrome和Firefox中运行一些基本的夜间测试。虽然我可以让chrome和firefox工作,但我无法让我的生活使Internet Explorer工作。我尝试过浏览这个网站,特别找到this回答,但没有任何帮助。当然,我也看了一下守夜人的文件无济于事

这是我的nightwatch.conf.js文件:

const BINPATH = './node_modules/nightwatch/bin/';

// we use a nightwatch.conf.js file so we can include comments and helper functions
module.exports = {
  "src_folders": ["test"],// Where you are storing your Nightwatch e2e tests
  "output_folder": "./reports", // reports (test outcome) output by nightwatch
  "selenium": { // downloaded by selenium-download module
    "start_process": true, // tells nightwatch to start/stop the selenium process
    "server_path": "./node_modules/nightwatch/bin/selenium.jar",
    "host": "127.0.0.1",
    "port": 4444, // standard selenium port
    "cli_args": { // chromedriver is downloaded by selenium-download (see readme)
      "webdriver.chrome.driver" : "./node_modules/nightwatch/bin/chromedriver",
      "webdriver.ie.driver": "C:/Users/[uname]/Develop/IEDriverServer.exe",
      "webdriver.gecko.driver": "C:/Users/[uname]/Develop/geckodriver.exe",
      "webdriver.firefox.profile": ""
    }
  },
  "test_runner": "mocha",
  "test_settings": {
    "default": {
      "screenshots": {
        "enabled": false,
        "path": './screenshots' // save screenshots here
      },
      "globals": {
        "waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
      },
      "desiredCapabilities": { // use Chrome as the default browser for tests
        "browserName": "ie"
      }
    },
    "chrome": {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true // turn off to test progressive enhancement
      }
    },
    "ie": {
      "desiredCapabilities": {
        "browserName": "internet explorer",
        "version": "11",
        "selenium_port"  : 4444,
        "selenium_host"  : "localhost",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "allowBlockedContent": true,
        "ignoreProtectedModeSettings": true
      }
    },
    "firefox": {
      "desiredCapabilities": {
        "browserName": "firefox",
        "javascriptEnabled": true // turn off to test progressive enhancement
      }
    }
  }
};
/**
 * selenium-download does exactly what it's name suggests;
 * downloads (or updates) the version of Selenium (& chromedriver)
 * on your localhost where it will be used by Nightwatch.
 /the following code checks for the existence of `selenium.jar` before trying to run our tests.
 */

require('fs').stat(BINPATH + 'selenium.jar', function (err, stat) { // got it?
  if (err || !stat || stat.size < 1) {
    require('selenium-download').ensure(BINPATH, function(error) {
      if (error) throw new Error(error); // no point continuing so exit!
      console.log('✔ Selenium & Chromedriver downloaded to:', BINPATH);
    });
  }
});

这是我不断接受测试的错误:

> nightwatch --config nightwatch.conf.js

Starting selenium server... started - PID:  7624


  Asset Library left hand nav
    1) "before all" hook

  0 passing (319ms)
  1 failing

  1) Asset Library left hand nav "before all" hook:
     Connection refused! Is selenium server started?






npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.11.1
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! ui-centre-tests@1.0.0 start: `nightwatch --config nightwatch.conf.js`
npm ERR! Exit status 10
npm ERR!
npm ERR! Failed at the ui-centre-tests@1.0.0 start script 'nightwatch --config nightwatch.conf.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ui-centre-tests package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     nightwatch --config nightwatch.conf.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs ui-centre-tests
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls ui-centre-tests
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\[uname]\Develop\HSBC\UICentre\npm-debug.log

Nightwatch设置为自己启动selenium服务器,并在开始测试后访问localhost:4444确实显示它已经启动。将浏览器更改为Chrome和Firefox也可以正常工作,只是IE就是问题所在。我尝试过使用64和32位版本的IEDriverServer,并将它们添加到我的PATH中,但仍然没有。任何帮助将不胜感激!

编辑:我更新了我的package.json,以便npm start运行nightwatch --config nightwatch.conf.js --env ie,chrome,firefox。有了这个,IE的一个实例现在打开,但实际上并没有运行测试

1 个答案:

答案 0 :(得分:1)

我终于得到了它的工作,这是我为使其工作而执行的步骤

  1. 手动 转到工具&gt;为每个环境设置尽可能低的安全设置。互联网选项&gt;安全&gt;自定义并自行设置单选按钮。
  2. 然后我将我的nighwatch.conf.js文件设置为使用标志--env ie,chrome,firefox,以便测试将在我所有的三个套件中运行,而不是默认情况下只是IE,这是以前配置的方式。当像这样运行时,我在一段时间内取得了进步的第一步:IE现在实际上打开了,但只会显示&#34;这是WebDriver服务器的初始启动页面&#34;但不会做任何其他事情
  3. 测试失败后(由于IE没有执行测试中的步骤),我确保在IE驱动程序打开的浏览器实例中将安全设置设置为最低可能
  4. 测试仍然无法运行,所以我采取的最后一步是手动将默认情况下在辅助监视器上打开的IE窗口移动到我的主监视器上,以便在测试运行时默认打开它,并且BOOM !在IE中工作的测试:D
  5. 祝其他人挣扎这一点好运,IE是一个可以开始工作的痛苦

相关问题