2014-10-10 61 views
0

我用這樣讓我的頭周圍pageobjects:如何在單獨的js文件中指定量角器pageobject?

https://github.com/angular/protractor/blob/master/docs/page-objects.md 

嘗試使用一個單獨的js文件的angularHomepage(pageobject)代碼做一些重構:

var AngularHomepage = function() { 
    this.nameInput = element(by.model('yourName')); 
    this.greeting = element(by.binding('yourName')); 

    this.get = function() { 
     browser.get('http://www.angularjs.org'); 
    }; 

    this.setName = function(name) { 
     this.nameInput.sendKeys(name); 
    }; 
}; 

spec文件長相像現在這樣:

var angularHomepage = require('/angularjs_homepage.js'); 

describe('angularjs homepage', function() { 

    it('should greet the named user', function() { 

     angularHomepage.get(); 

     angularHomepage.setName('Julie'); 

     expect(angularHomepage.greeting.getText()).toEqual('Hello Julie!'); 
    }); 
}); 

當我運行規範時,我得到一個錯誤? :

Message: 
     Error: Cannot find module '/angularjs_homepage.js' 
     Stacktrace: 
     Error: Cannot find module '/angularjs_homepage.js' 
     at require (module.js:380:17) 
     at Object.<anonymous> (c:\ptor_testing\example_spec.js:1:85) 

回答

1

它需要在pageobjects文件一個額外的行:

module.exports = new AngularHomepage(); 
相關問題