通过独立浏览器客户端运行的实习生错过了这一点.远程套房

Running The Intern via standalone browser client misses this.remote in suites

本文关键字:错过了 实习生 这一点 程套房 运行 独立 浏览器 客户端      更新时间:2023-09-26

此测试代码:

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测试运行器中执行。它们不能在独立的浏览器客户端中运行,因为根据定义,它们必须从浏览器沙箱外部驱动浏览器。这就是为什么它们在配置中与单元测试分开定义的原因。