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

标签 javascript selenium intern

此测试代码:

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/functioning/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/

相关文章:

javascript - 如何在实习生js中打开新的浏览器窗口?

Javascript 'this' 返回未定义的内部对象

Java-为什么 Selenium Chrome Webdriver 使用我的真实 IP 地址而不是代理

Javascript 将链式函数包装在单个函数中

python - 如何使用 Selenium 和 Python 定位具有多个类名的元素

java - 在chrome最新版本中使用selenium处理打印预览窗口

javascript - intern.js 重构到 block 行为不一致之前

javascript - 使用 javascript 正则表达式查找不在引号内的注释

javascript - jQuery 精确数字匹配表排序

javascript - Semantic-UI:如何更改较暗的背景颜色?