我尝试使用量角器进行简单的app ..try测试?我安装了所有的东西。并且能够运行量角器给出的例子..我自己做这样的例子
Index.html ..
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Super</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js"></script>
<script src="app.js"></script>
</head>
<body ng-app ="app">
<div ui-view></div>
</body>
</html>
app.js
angular.module('app',['ui.router']).config(function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise("/state1");
//
// Now set up the states
$stateProvider
.state('state1', {
url: "/state1",
templateUrl: "partial/state1.html" ,
controller:function($scope){
$scope.clikme=function(){
$scope.message="hello"
}
}
})
})
example.spec.js
var indexFunction=require('/indexFunction');
describe('angularjs homepage', function() {
var page =new indexFunction();
beforeEach(function(){
page.getUrl()
})
it('should greet the named user', function() {
expect(page.getTitile()).toEqual('Super');
});
it('should update',function(){
page.clickMethod();
expect(page.getMessage()).toBe('hello')
})
});
index.spec.js
function indexFunction(){
this.button= element(by.id('clickme')) ;
this.message=element(by.binding('message')) ;
this.getUrl=function(){
browser.get('http://localhost:63342/example/index.html');
}
this.getTitile=function(){
return browser.getTitle();
}
this.getMessage=function(){
return this.message.getText();
}
this.clickMethod=function(){
this.button.click();
}
}
module.exports=indexFunction
当我运行此示例时,我收到此错误
[![MacBook-Pro:example naveenkumar$ protractor conf.js
Using ChromeDriver directly...
\[launcher\] Running 1 instances of WebDriver
\[launcher\] Error: Error: Cannot find module '/indexFunction'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/Users/naveenkumar/Desktop/example/example_spec.js:2:23)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:][1]][1]
更新
r: Error: Cannot find module '/index.spec'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
答案 0 :(得分:1)
在example.spec.js
中应该是:
var indexFunction = require('./index.spec');