嗨,我想使用POM的概念,第一个文件basefile.JS我的代码是量角器中使用JavaScript原型(继承)的概念,用茉莉
var basefile = function() {
};
basefile.prototype.elementClick = function(locator) {
element(by.xpath(locator)).click();
};
//module.exports = new basefile();
此文件包含用户可以在任何执行的常见方法Web应用程序。 二js文件tempPageOne.js我的代码是
require("./basefile.js");
var tempPageOne = function(){
var BaseMethod = new basefile();
this.ddselection = function(locOne,locTwo){
BaseMethod.elementClick(locOne);
BaseMethod.elementClick(locTwo);
};
};
module.exports = new tempPageOne();
在这里,我打电话给我的basefile.JS和使用thirdd的js文件中定义的方法有我testMethod.js代码是
describe("sample to check inheritance",function(){
var testOne = require("./tempPageOne.js");
it("working with inheritance",function(){
browser.get("http://www.protractortest.org/#/");
testOne.ddselection("html/body/nav/div/div[2]/div/ul/li[3]/a","html/body/nav/div/div[2]/div/ul/li[3]/ul/li[4]/a");
console.log("Working fine");
});
});
这是我的规范文件的一个简单的测试,但得到错误不知道该怎么办 失败: 1)样本检查继承遇到声明异常 消息: ReferenceError:basefile未定义 堆栈: ReferenceError:未在基于对象的新tempPageOne(D:\ eclipseProject \ JavaScriptInheritance \ tempPageOne.js:4:23) 处定义basefile 。 (D:\ eclipseProject \ JavaScriptInheritance \ tempPageOne.js:10:18) at要求(module.js:385:17) at Suite。 (d:\ eclipseProject \ JavaScriptInheritance \ testMethod.js:3:16) 在addSpecsToSuite(C:\用户\ rajnish \应用程序数据\漫游\ NPM \ node_modules \量角器\ node_modules \茉莉\ node_modules \茉莉核\ lib中\茉莉-core \ jasmine.js:743:25)
感谢@Brine答案@卤水其工作 –