我正在使用以下代码运行我的实习测试
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)
....
},
}
答案 0 :(得分:1)
window
在节点中不存在,您必须从浏览器上运行的代码(正在测试的代码)覆盖其alert
,而不是在节点本身。我会在每个使用它的测试的设置代码中执行此操作。