我在功能测试中使用任何dojo模块时遇到问题,我不断看到window
未定义错误或document
未定义。
我目前正在尝试像这样使用dijit/registry
(到目前为止仅导入其模块)。
define([
'intern!object',
'intern/chai!assert',
'require',
'dijit/registry'
], function (registerSuite, assert, require, registry) {
registerSuite({
name: 'login',
'load and login': function () {
return this.remote.get(require.toUrl('http://application.co.uk/'))
.elementById('input1')
.click()
.type("username")
.end()
.elementById('input2')
.click()
.type("password")
.end()
.elementById('rememberMe')
.click()
.end()
.elementByName('Login.Submit')
.click()
.end()
.wait(5000)
.title()
.then(function (title) {
assert.strictEqual(title, 'Application title');
});
}
});
});
...并且正在从节点获取以下错误...
$ ./libs/intern/bin/intern-runner.js config=test/intern
Defaulting to "runner" reporter
Listening on 0.0.0.0:9000
c:/.../libs/dojo/_base/unload.js:6
var win = window;
^
ReferenceError: window is not defined
at c:/.../libs/dojo/_base/unload.js:6:11
at execModule (c:\...\libs\intern\node_modules\dojo\dojo.js:512:54)
at c:\...\libs\intern\node_modules\dojo\dojo.js:501:12
at Array.map (native)
at execModule (c:\...\libs\intern\node_modules\dojo\dojo.js:496:17)
at c:\...\libs\intern\node_modules\dojo\dojo.js:501:12
at Array.map (native)
at execModule (c:\...\libs\intern\node_modules\dojo\dojo.js:496:17)
at c:\...\libs\intern\node_modules\dojo\dojo.js:501:12
at Array.map (native)
我已经阅读了先前的问题about using dojo/text!
in a similar way,似乎表明Intern的geezer版本可以解决这个问题?
没有注册表模块,测试运行正常。
更新
基于C Snover的响应,您不能在webdriver dojo/text!
方法之外利用dijit/registry
之类的东西,因为代码需要位于Web浏览器的上下文中,而不是功能测试之内。
功能测试从Node.js而不是浏览器环境中运行。如果要访问正在测试的页面中加载的execute()
实例,则需要使用dijit/registry
在远程环境中运行功能:
execute
您将无法从功能测试模块中定义具有DOM要求(例如return this.remote
.get('http://application.co.uk')
.execute(function () {
// this function runs in the browser!
var registry = require('dijit/registry');
// ... do things with registry
return something;
})
.then(function (something) {
// this function runs inside the test runner!
assert.isTrue(something);
});
)的依赖项。仅基于浏览器的单元测试模块将能够加载此类依赖项。
还有dijit-intern-helper-> dijit/registry
所以这个
https://github.com/SitePen/dijit-intern-helper
成为
executeAsync(function (done) {
require(['dijit/registry'], function (registry) {
done(registry.byId('titlePane').titleBarNode);
});
})
.then(function (node, setContext) {
setContext(node);
})
.click()
关于它的博客文章-> .then(dijit.nodeById('titlePane', 'titleBarNode'))
.click()