Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I try to make simple app ..try to test using protractor ? I install every thing .and able to run protractor given example ..than I make my own example like this

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

when I run this example I got this error

[![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]

enter image description here

Update

r: Error: Cannot find module '/index.spec'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
share|improve this question
up vote 0 down vote accepted

In example.spec.js it should be:

var indexFunction = require('./index.spec');
share|improve this answer
    
ok i will try and update you – Pallavi Sharma 1 hour ago
    
stll same issue... can we include any module for require? – Pallavi Sharma 1 hour ago
    
please check update..got it soory ..got it – Pallavi Sharma 1 hour ago
    
got it ..thanks got it – Pallavi Sharma 1 hour ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.