此测试代码:
define([
'intern!object',
'intern/chai!assert',
'require'
], function (registerSuite, assert, require) {
registerSuite({
name: 'index',
'greeting form': function () {
return this.remote
.get(require.toUrl('index.html'))
}
});
})
在跑步者中完美工作(所有测试都通过,硒日志显示请求很好):
intern-runner config=tests/local.intern.js
但是当我尝试从独立客户端使用它时,在浏览器中通过
http://localhost/intern-tutorial/node_modules/intern/client.html?config=tests/local.intern
出现两个问题:
- 默认情况下,只运行单元测试(为什么?)——它们以优异的成绩通过;
- 显式请求功能测试(通过 suites=tests/functional/index)返回以下错误:
Error: Cannot call method 'get' of undefined TypeError: Cannot call method 'get' of undefined at Test.registerSuite.greeting form [as test] (http://localhost/intern-tutorial/tests/functional/index.js:20:18) at Test.run (http://localhost/intern-tutorial/node_modules/intern/lib/Test.js:154:19) at http://localhost/intern-tutorial/node_modules/intern/lib/Suite.js:210:13 at signalListener (http://localhost/intern-tutorial/node_modules/intern/node_modules/dojo/Deferred.js:37:21) at Promise.then.promise.then (http://localhost/intern-tutorial/node_modules/intern/node_modules/dojo/Deferred.js:258:5) at http://localhost/intern-tutorial/node_modules/intern/lib/Suite.js:209:46
我从错误日志中假设没有加载 WebDriver。因此,Selenium 在运行此功能测试期间没有收到任何请求。在 registerSuite 函数中的“this”对象有这样的内容:
registerSuite({
name: 'index',
'greeting form': function () {
// assert.strictEqual(this, {});
console.log(JSON.stringify(this));
},
});
{"name":"greeting form","sessionId":null,
"id":"main - index - #greeting form", "timeout":30000, "timeElapsed":null, "hasPassed":false,"error":null} this.remote is missing...