使用intern.js和browserstack,访问远程浏览器环境

时间:2014-07-08 10:31:07

标签: intern browserstack

我正在尝试执行基本的功能测试:

define([
    'intern!object',
    'intern/chai!assert',
    '../Request',
    'require'
], function (registerSuite, assert, Request, require) {
    var request,
        url = 'https://github.com/theintern/intern';

    registerSuite({
        name: 'demo',

        'submit form': function () {
            return this.remote
                .get(require.toUrl('./fixture.html'))
                .findById('operation')
                    .click()
                    .type('hello, world')
                .end()
                .findById('submit')
                    .click()
                .end()
                .setFindTimeout(Infinity)
                .findById('result')
                .setFindTimeout(0)
                .text()
                .then(function (resultText) {
                    assert.ok(resultText.indexOf(
                        '"hello, world" completed successfully') > -1,
                        'On form submission, operation should complete successfully');
                });
        }
    });
});

(来自intern.js文档的示例) https://github.com/theintern/intern/wiki/Writing-Tests-with-Intern

我的intern.js配置文件如下:

define({


proxyPort: 9000,
    proxyUrl: 'http://localhost:9000/',
    capabilities: {
        'selenium-version': '2.41.0'
    },
    environments: [
        { browserName: 'chrome'}
    ],
    maxConcurrency: 3,
    tunnel: "BrowserStackTunnel",
    webdriver: {
        host: 'http://hub.browserstack.com/wd/hub',
        username: 'XXXXX',
        accessKey: 'XXXXX'
    },
    useSauceConnect: false,
    loader: {
        packages: [ 
        {
            name: "dojo",
            location: 'vendor/dojo'
        } 
        ]
    },
    suites: [ "tests/test" ],
    excludeInstrumentation: /^(?:tests|node_modules)\//
});

当我运行我的测试时,似乎正在与browserstack建立连接,但我的测试仍然失败:

-> ./node_modules/.bin/intern-runner config=tests/intern
Listening on 0.0.0.0:9000
Starting tunnel...
BrowserStackLocal v2.2
Ready
Initialised chrome 35.0.1916.114 on XP
Test main - index - test FAILED on chrome 35.0.1916.114 on XP:
TypeError: Cannot read property 'get' of null
  at Test.registerSuite.test  <tests/test.js:11:17>
  at Test.run  <__intern/lib/Test.js:154:19>
  at <__intern/lib/Suite.js:212:13>
  at signalListener  <__intern/node_modules/dojo/Deferred.js:37:21>
  at Promise.then.promise.then  <__intern/node_modules/dojo/Deferred.js:258:5>
  at <__intern/lib/Suite.js:211:46>

我认为没有加载WebDriver,我如何在功能测试中访问远程浏览器环境?

1 个答案:

答案 0 :(得分:1)

只有功能测试与WebDriver客户端交互并具有remote属性。在您的配置中,将测试套件包含在functionalSuites数组中,而不是suites

请注意,不再使用webdriver属性,因此如果您要在配置文件中指定用户名和访问密钥,则应使用tunnelOptions代替。

tunnelOptions: {
    username: <username>,
    accessKey: <accessKey>
}

隧道知道默认使用的正确主机名,因此您无需提供该名称。