我正在使用以下代码运行我的实习生测试
node node_modules/intern/runner.js config=tests/intern在我的本地机器上。应用程序正在使用Dojo。基本上,我正在尝试覆盖window.alert函数,因为我的一个测试因意外警报而失败。
window.alert = function(msg) {
//override alert function
//...
}我试着把这个放在我的实习生测试中,得到了错误。经过一些搜索,我了解到窗口对象在节点环境中不可用。我可以在哪里覆盖警报?intern file看起来像这样
define(['intern/lib/args'], function(args) {
var DEFAULT_PORT = "8080";
var urlInfo = {
PORT: args.port || DEFAULT_PORT,
BASE_URL : "http://localhost:".concat(args.port || DEFAULT_PORT, "/webtest"),
};
var config = {
proxyPort: 9000,
proxyUrl: 'http://localhost:9000',
capabilities: {
'selenium-version': '2.45.0',
},
...
...
};
return config;
});实习生测试文件示例
define([
'intern!object',
'intern/chai!assert',
'intern/dojo/node!leadfoot/helpers/pollUntil',
'intern',
'intern/dojo/node!fs'
], function(registerSuite, assert, Pages, intern, fs) {
registerSuite ({
name: 'Tests',
setup: function() {
window.alert = function(msg){
console.log("Unexpected Alert: "+msg);
}
return this.remote.get(require.toUrl( intern.config.functionalInfo.BASE_URL)).maximizeWindow();
},
beforeEach: function() {
return
},
afterEach: function() {
return
},
'Test1' : function() {
this.timeout = 600000;
return this.remote
.setFindTimeout(5000)
....
},
}发布于 2015-10-06 04:14:57
node中不存在window,您必须从在浏览器上运行的代码(正在测试的代码)覆盖它的alert,而不是在节点本身上。我会在每个使用它的测试的设置代码中这样做。
https://stackoverflow.com/questions/32957089
复制相似问题