因此,这是我的问题,我想在运行测试或离线时模拟我的数据,但是在我可能/需要的时候通过使用npm run protractor和npm run protractor-mock调用extarnal。
我拼凑在一起的解决方案是有两个index.html文件,其中一个添加了模拟(index-mock.html)。
因此,我的问题是如何让安装程序protractor-mock加载index-mock.html
注意:正如代码中所述,GET('http://localhost:5000...是不好的,但并不是当前的问题。
到目前为止我的档案
index.html:
<!DOCTYPE html>
<html lang="en" ng-app="PCA" class="no-js">
...
<script src="bower_components/angular/angular.js"></script>
...
</html>index-mock.html:
<!DOCTYPE html>
<html lang="en" ng-app="PCA" class="no-js">
...
<script src="bower_components/angular/angular.js"></script>
...
</html>app.js:
'use strict';
angular.module('PCA', [
'ngRoute',
'chart.js',
'ngDialog',
'ngCsv'
]).config(function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: 'views/chartContainer.html',
controller: 'chartContainerCtrl'
}).otherwise({redirectTo: '/'});
}).constant('config', {
'apiUrl': 'http://localhost:5000'
});
//2nd app ->
angular.module('PCAMOCK', ['PCA', 'ngMockE2E'])
.run(function($httpBackend) {
$httpBackend.whenGET('http://localhost:5000/').respond({ //yes 'localhost:5000' this is bad but not the issues at hand
"defaults": {
"invURL": "http://www.invURL.com",
"accountURL": "http://www.accountURL.com"
}});
$httpBackend.whenGET('http://localhost:5000/accounts').respond(200, {ciao:'mamma'}, {'Content-Type':'application/json'});
$httpBackend.whenGET(/^/).passThrough();
//...
});package.json:
exports.config = {
allScriptsTimeout: 11000,
specs: [
'tests/*.js'
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:8000/app/',
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};发布于 2015-03-06 20:18:00
您可以在量角器中访问命令行参数。见How can I use command line arguments in Angularjs Protractor?。您应该能够使用它来区分两次运行,并更改传递给browser.get的URL。
不是直接问你的问题,但你可能想研究一下Protractor对模拟注射的支持。见 docs或http://eitanp461.blogspot.com/2014/01/advanced-protractor-features.html
您不需要有两个实现您的应用程序,它可以是不可知论的模拟-或不。
https://stackoverflow.com/questions/28896815
复制相似问题