[英]How can I use dijit/regisrty in an Intern functional test
我在使用任何 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)
我已經閱讀了有關使用dojo/text!
的先前問題dojo/text!
以類似的方式似乎表明實習生的geezer版本可以處理這個問題?
在沒有注冊表模塊的情況下,測試運行良好。
更新
好的,因此基於 C Snover 的響應,您不能在 webdriver execute()
方法之外利用諸如dijit/registry
類的任何東西,因為代碼需要在 Web 瀏覽器的上下文中,而不是在功能測試中。
功能測試在 Node.js 中運行,而不是在瀏覽器環境中運行。 如果你想訪問你正在測試的頁面中加載的dijit/registry
實例,你需要使用execute
在遠程環境中運行一個函數:
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);
});
您將無法從功能測試模塊中定義具有 DOM 要求(如dijit/registry
)的依賴dijit/registry
。 只有基於瀏覽器的單元測試模塊才能加載此類依賴項。
還有 dijit-intern-helper -> 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()
關於它的博客文章 -> https://www.sitepen.com/blog/simplified-dijit-functional-testing/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.