从另一个 JS 文件访问 java 对象时出错。this.firstinput=element(by.model( "first" ));元素未定义


//Jsobjectdemo.js:
function  car() {


this.firstinput=element(by.model("first"));
this.secondinput=element(by.model("second"));
this.goButton=element(by.id("gobutton"));
this.result=element(by.css("h2[class='ng-binding']"));
this.color="red"; this.engine="turbo"; this.brand="BMW";
this.search="by.css('input')";

this.getURL=function() {

browser.get('http://juliemr.github.io/protractor-demo/'); };

};  
module.exports= new car();

//JsAccess.js:
```var obj=  require("./Jsobjectdemo.js");      
obj.getModel();
console.log(obj.search);
//Jsobjectdemo
const car = {
firstinput :element(by.model("first")),
secondinput : element(by.model("second")),
goButton : element(by.id("gobutton")),
result : element(by.css("h2[class='ng-binding']")),
color : "red", engine : "turbo", brand : "BMW",
search : "by.css('input')",
getURL : function () {
browser.get('http://juliemr.github.io/protractor-demo/')
}
}
exports.car = car;
//JsAccess.js:
const {car} = require(`./Jsobjectdemo`)
console.log(car.search)

注意:element和by必须从pages文件

中的protractor中导入
const {by, element, browser} = require('protractor');

最新更新