我像这样运行量角器
protractor --params.env=q
q表示质量保证。这个量角器conf
var CommonPageObject = require('./e2e/commonPageObject');
suites: {
login: './e2e/account/login/*.js'
},
//for console params. example console command: protractor --params.env=q
params: {
env: 'qa',//can be local, prod or qa default is qa for environment
},
onPrepare: function () {
var commonPageObject = new CommonPageObject();
commonPageObject.prepareVariables();
}
这是常见页面
this.prepareVariables = function () {console.log("xx",browser.params.env);
var env = browser.params.env;
this.setEnvironment(env);
this.setBaseUrl(env);
};
//can be local, prod or qa. local = 2, qa = 0, prod=1
this.setEnvironment = function (env) {
if(env.includes("l")){
environment = 2;
}
else{
if(env.includes("p")){
environment = 1;
}
else{// qa
environment = 0;
}
}console.log("environment",environment);
};
//to get enviroment qa=0, prod=1, local=2 default=qa
this.getEnvironment = function () {
return environment;
};
this.setBaseUrl = function (env) {
if(env.includes("q")){
baseUrl = "http://xxxx.qa.xxx.com:8080";
}
else{
if(env.includes("p")){
baseUrl = "https://xxxxx.com";
}
else{
baseUrl = "localhost:8080";
}
}console.log("baseUrl",baseUrl);
};
this.getBaseUrl = function () {console.log("getBaseUrl",baseUrl);
return baseUrl;
};
当我运行
时,输出是protractor --params.env=q
xx q
environment 0
baseUrl http://xxx.qa.xxxx.com:8080
Started
getBaseUrl undefined
FgetBaseUrl undefined
F
测试开始时它变为未定义。这是什么意思?为什么commonpage对象页面变量不能保持在堆栈中?那么,我应该在每个测试之前为每个测试调用这些方法吗?或者我做错了什么?
答案 0 :(得分:2)
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
//code
replyHandler (answer as [String : Any])
}
的范围仅存在于commonPageObject
方法的上下文中。这不会转移到其他spec文件。你应该做的是将你的onPrepare
绑定到一个全局变量。量角器有一个内置的:browserUrl
browser.baseUrl
设置browser.baseUrl后,在规范文件中,您现在可以执行this.setBaseUrl = function (env) {
if(env.includes("q")){
browser.baseUrl = "http://xxxx.qa.xxx.com:8080";
}
else{
if(env.includes("p")){
baseUrl = "https://xxxxx.com";
}
else{
baseUrl = "localhost:8080";
}
}console.log("baseUrl",baseUrl);
};
this.getBaseUrl = function () {console.log("getBaseUrl",browser.baseUrl);
return browser.baseUrl;
};
,该browser.get('/some/path');
应解析为browser.baseUrl + '/some/path'
。