Reputation: 1336
I'm trying to use static method in order to use it externally.
utils file:
'use strict'
function utils(){}
utils.staticMethod1 = function(){
alert("foo");
};
module.exports = utils();
'use strict;'
let HomePage = require('../page/home_page.js');
let utilsPage = require('../utils/utils.js');
describe("login to website",function(){
let employeeId;
let employeeBday;
let home = new HomePage();
beforeEach(function(){
browser.driver.get("http://foo.com/");
});
it("should succees picking a present",function(){
utilsPage.staticMethod1();
});
});
But I'm keep getting an error says: Failed: utils is not defined
Upvotes: 0
Views: 1163
Reputation: 111
Your page file:
'use strict';
var Utils = function(){
this.methodTest = function(){
console.log("Something"); //alert(this);
};
};
module.exports = Utils;
Your Spec file:
'use strict;'
let Utils = require('../page/utils.Page.js');
describe("login to website",function(){
let employeeId;
let employeeBday;
let utils = new Utils();
beforeEach(function(){
browser.driver.get("http://foo.com/");
});
it("should success picking a present",function(){
utils.methodTest();
expect(browser.getTitle()).toEqual('SomethingToGetAnError');
});
});
You should peek a bit about using static methods in protractor, they would lead you to rough ends.
Better explanation about Page Objects Pattern in testing
Upvotes: 1