2

このテスト コード:

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

2 つの問題が発生します。

  • デフォルトでは、単体テストのみが実行されます (なぜですか?) - それらは見事に合格します。
  • 機能テストを (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...
4

1 に答える 1