所以很容易实现。您只需要
1/ 安装业力
npm install -g 业力
2/ 安装 ng-scenario 和 karma-ng-scenario 的依赖项
npm install ng-scenario
npm install karma-ng-scenario --save-dev
3/ 如果需要代理,则创建/修改 karma e2e 配置。通常是这种情况,因为 dojo 运行在与 karma 不同的服务器上。因此,您为 karma 指定特定端口并代理到您的服务器。这是我的配置示例:
module.exports = function(config) { config.set({ // 基本路径,将用于解析文件并排除 basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['ng-scenario'],
// list of files / patterns to load in the browser
files: [
'https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js',
'test/e2e/**/*.js'
],
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8033,
runnerPort : 9100,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Chrome'],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
// Uncomment the following lines if you are using grunt's server to run the tests
proxies: {
'/': 'http://localhost:8080/'
}, // URL root prevent conflicts with the site root
urlRoot: '_karma_' }); };
- 您使用端到端配置运行业力
karma start karma-e2e.conf.js
魔术,以下代码有效 - 快乐测试:)
describe ( 'Publications', function ()
{
beforeEach (
function ()
{
console.log ( "before each" );
browser ().navigateTo ( "yourPageToTestUrl" );
}
);
it ( 'should filter results', function ()
{
expect ( repeater ( '.Publication' ).count () ).toEqual ( 4 );
} );
} );