我可以使用thetern js框架运行功能测试而无需设置独立的selenium服务器吗?

时间:2015-01-31 17:45:44

标签: selenium-webdriver selenium-chromedriver intern

我的html页面有一个有效的webdriver javascript测试脚本,使用ChromeDriver运行,无需启动selenium独立服务器:

test.js

'use strict';

var path = require('path');
var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');

var options = new chrome.Options();
var logging_prefs = new webdriver.logging.Preferences();
logging_prefs.setLevel(webdriver.logging.Type.BROWSER, webdriver.logging.Level.ALL);
options.setLoggingPrefs(logging_prefs);

var driver = new webdriver.Builder().withCapabilities(options.toCapabilities()).build();

driver.get('file://' + path.resolve('./index.html'));
// Do some testing
driver.quit();

我想将此测试移植到使用theintern.io,但我不想运行独立的selenium服务器。这可能吗?

[编辑:添加有关错误和内部配置的信息]

我看到错误[POST http://localhost:4444/wd/hub/session] connect ECONNREFUSED,我猜是因为我没有运行独立服务器。

我的theintern配置看起来像这样:

define({
  environments: [
    { browserName: 'chrome' }
  ],

  // Name of the tunnel class to use for WebDriver tests
  tunnel: 'NullTunnel',

  // Non-functional test suite(s) to run in each browser
  suites: [ /* 'myPackage/tests/foo', 'myPackage/tests/bar' */ ],

  // Functional test suite(s) to run in each browser once non-functional tests are completed
  functionalSuites: [ 'tests/functional/index' ],

  // A regular expression matching URLs to files that should not be included in code coverage analysis
  excludeInstrumentation: /^(?:tests|node_modules)\//
});

我的内部测试看起来像这样:

define([
  'intern!object',
  'intern/chai!assert',
  'require'
], function (registerSuite, assert, require) {
  registerSuite({
    name: 'index',

    'first test': function () {
      return this.remote
        .get(require.toUrl('index.html'))
        ... //more test logic
    }
  });
});

1 个答案:

答案 0 :(得分:1)

实习生使用标准的WebDriver协议,因此可以与任何实现规范的服务器一起使用,而不仅仅是Selenium。在这种情况下,如果您尝试连接ChromeDriver,请确保它首先运行(chromedriver --port=4444 --url-base=wd/hub),然后运行intern-runner config=mid/of/config,您应该选择目前的配置。< / p>