如何获取Nightwatch.js在Internet Explorer上运行测试
问题描述:
我试图在Internet Explorer,Chrome和Firefox中运行一些基本的夜间测试。尽管我可以使用Chrome和Firefox来工作,但我无法让Internet Explorer工作。我试过通过这个网站搜索,发现this尤其是答案,但它没有帮助。当然,我也通过夜巡文档无济于事如何获取Nightwatch.js在Internet Explorer上运行测试
这里看着我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);
});
}
});
这是我不断从我的测试recieving错误:
> 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! [email protected] start: `nightwatch --config nightwatch.conf.js`
npm ERR! Exit status 10
npm ERR!
npm ERR! Failed at the [email protected] 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设置为自己启动硒服务器,并在启动测试后访问localhost:4444确实显示它已启动。将浏览器更改为Chrome和Firefox也可以正常工作,但这只是IE的问题。我试过使用64位和32位版本的IEDriverServer,并且将它们添加到我的PATH中,但仍然没有。任何帮助将非常感激!
编辑:我更新了我的package.json,以便npm开始运行nightwatch --config nightwatch.conf.js --env ie,chrome,firefox
。有了这个地方,IE的一个实例现在这样开放,但它实际上并没有运行测试
答
我终于得到它的工作,这里是我进行的得到它的工作
- 步骤手动通过转到工具> Internet选项>安全性>自定义设置每个环境的最低可能安全设置,并自行设置单选按钮。
- 然后我将nighwatch.conf.js文件设置为使用标记
--env ie,chrome,firefox
,以便测试可以在我所做的所有三个套件中运行,而不是默认情况下的IE,这是它之前的配置。当我这样运行时,我在一段时间内完成了我的第一步:IE现在实际打开,但只显示“这是WebDriver服务器的初始起始页”,但不会执行任何操作。 - 测试失败(因为IE不执行测试中的步骤),然后我确保安全设置被设置为由IE驱动程序打开的浏览器的这个实例中最低的可能性
- 测试将仍然不运行,所以我采取的最后一步是手动将辅助监视器上默认打开的IE窗口移动到主监视器上,以便在测试运行时默认打开此处,然后BOOM!测试工作在IE:d
好运别人苦苦这个,IE是一个痛苦得到工作