我正在努力将我们的单元/功能测试框架切换到实习生,但我尝试的所有不同配置导致实习生只运行单元测试而根本没有完成功能测试。
Selenium Standalone和ChromeDriver确实在4444端口运行。
我的配置文件如下所示:
// Learn more about configuring this file at <https://github.com/theintern/intern/wiki/Configuring-Intern>.
// These default settings work OK for most people. The options that *must* be changed below are the
// packages, suites, excludeInstrumentation, and (if you want functional tests) functionalSuites.
define({
// The port on which the instrumenting proxy will listen
proxyPort: 9000,
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://localhost:9000/',
// Default desired capabilities for all environments. Individual capabilities can be overridden by any of the
// specified browser environments in the `environments` array below as well. See
// https://code.google.com/p/selenium/wiki/DesiredCapabilities for standard Selenium capabilities and
// https://saucelabs.com/docs/additional-config#desired-capabilities for Sauce Labs capabilities.
// Note that the `build` capability will be filled in with the current commit ID from the Travis CI environment
// automatically
capabilities: {
'selenium-version': '2.44.0'
},
// Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce
// OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other
// capabilities options specified for an environment will be copied as-is
environments: [
{ browserName: 'chrome' }
],
// Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service
maxConcurrency: 3,
// Name of the tunnel class to use for WebDriver tests
tunnel: 'NullTunnel',
// The desired AMD loader to use when running unit tests (client.html/client.js). Omit to use the default Dojo
// loader
useLoader: {
'host-node': 'requirejs',
'host-browser': '../../node_modules/requirejs/require.js'
},
reporters: ['pretty'],
// Configuration options for the module loader; any AMD configuration options supported by the specified AMD loader
// can be used here
loader: {
// Packages that should be registered with the loader in each testing environment
packages: [
{ name: 'controls', location: './js' },
{ name: 'jquery', location: './node_modules/jquery' }
]
},
// Turn off connection to Sauce Labs
useSauceConnect: false,
// Setup for Selenium Webdriver
webdriver: {
host: 'localhost',
port: 4444
},
// Non-functional test suite(s) to run in each browser
suites: [ 'intern-test/unit/_all' ],
// Functional test suite(s) to run in each browser once non-functional tests are completed
functionalSuites: [ 'intern-test/functional/_all' ],
// A regular expression matching URLs to files that should not be included in code coverage analysis
excludeInstrumentation: /^(?:test|intern-test|node_modules)\//
});
单元和功能测试套件(&#39; _all.js&#39;)基本上只是在一个地方加载所有单独的测试模块,如下所示:
define([
'./module-one-unit-tests',
], function () {
// This is just used for loading up all tests at once
console.log('loaded unit tests');
});
define([
'./module-one-functional-tests',
], function () {
// This is just used for loading up all tests at once
console.log('loaded functional tests');
});
我的单元测试看起来像这样:
define([
'require'
], function(require) {
var registerSuite = require('intern!object'),
expect = require('intern/chai!expect');
console.log('multiselect tests loaded');
registerSuite({
name: 'Multiselect (unit)',
'passing test': function() {
var str = '';
expect(str).to.equal('');
}
});
console.log('registered multiselect tests');
});
一个看起来像这样的功能测试:
define([
'require'
], function (require) {
var url = 'http://localhost:4000/tests/multiselect',
registerSuite = require('intern!object'),
expect = require('intern/chai!expect'),
Keys = require('intern/node_modules/leadfoot/keys');
function addIds() {
$('#states-multi-shdo').prev().attr('id', 'states-multi-textbox');
$('#towns-multi-optgroup-shdo').prev().attr('id', 'towns-multi-optgroup-textbox');
$('#fruits-multi-shdo').prev().attr('id', 'fruits-multi-textbox');
}
function getMultiSelectVal(selector) {
return $(selector).val();
}
var STATES = 'states-multi',
STATES_TEXTBOX = 'states-multi-textbox',
FRUITS_TEXTBOX = 'fruits-multi-textbox',
DDLIST = 'dropdown-list';
registerSuite({
name: 'Multiselect (functional)',
setup: function() {
return this.remote
.get(require.toUrl(url))
.setWindowSize(null, 1024, 768)
.execute(addIds)
.sleep(100);
},
'will not allow more than the "data-maxselected" attribute\'s specified number of selected options in the list': function () {
return this.remote
.findById(STATES_TEXTBOX)
.click()
.pressKeys([
Keys.SPACE, Keys.ARROW_DOWN,
Keys.SPACE, Keys.ARROW_DOWN,
Keys.SPACE, Keys.ARROW_DOWN,
Keys.SPACE, Keys.ARROW_DOWN,
Keys.SPACE, Keys.ARROW_DOWN,
Keys.SPACE, Keys.ARROW_DOWN,
Keys.SPACE, Keys.ARROW_DOWN,
Keys.SPACE, Keys.ARROW_DOWN,
Keys.SPACE, Keys.ARROW_DOWN,
Keys.SPACE, Keys.ARROW_DOWN,
Keys.SPACE, Keys.ARROW_DOWN,
Keys.SPACE, Keys.ARROW_DOWN,
Keys.ESCAPE
])
.end()
.findById(STATES)
.getProperty('selectedOptions')
.then(function (val) {
console.log(val);
expect(val.length).to.equal(10);
});
}
});
});
正如我所说,当我使用node_modules/.bin/intern-client config=intern-test/intern.local
解雇测试跑步者时,单元测试运行完全正常,但功能测试无处可寻。
我已经多次在Functional Testing和Common Configuration搜索了实习生文档,而我似乎无法弄清楚我可能会出错的地方。
有人能告诉我我是如何搞砸了这个吗?
答案 0 :(得分:7)
intern-client
是Node.js client,只在Node.js中运行单元测试。 intern-runner
是test runner,它将执行unit&amp;针对远程浏览器的功能测试。您需要使用intern-runner
,而不是intern-client
。