gpt4 book ai didi

javascript - 通过独立浏览器客户端运行 The Intern 会在套件中错过 this.remote

转载 作者:行者123 更新时间:2023-11-29 18:16:53 25 4
gpt4 key购买 nike

这个测试代码:

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'))
}
});
})

在运行器中完美运行(所有测试通过,selenium 日志显示请求正常):

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...

最佳答案

功能测试在 Node.js 测试运行器中执行。它们不能在独立的浏览器客户端中运行,因为根据定义它们必须从浏览器沙箱外部驱动浏览器。这就是它们在配置中与单元测试分开定义的原因。

关于javascript - 通过独立浏览器客户端运行 The Intern 会在套件中错过 this.remote,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22449235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com