此测试代码:
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
出现两个问题:
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...
答案 0 :(得分:4)
功能测试在Node.js测试运行器中执行。它们无法在独立浏览器客户端中运行,因为根据定义,它们必须从浏览器沙箱外部驱动浏览器。这就是为什么它们与配置中的单元测试分开定义的原因。