我正在将 Protractor 与 PageObject astrolabe 一起使用,如下所示
CampaignPage.js
module.exports = Page.create({
defaultCheckpoint: {
get: function () {
return {
giName: "auto",
giType: "auto",
}
}
},
getDefaultValue: {
value: function (campaignCode) {
var page = this;
var checkpoint = page.defaultCheckpoint;
/* #Tab General Info */
page.getTabByName(page.informationTabs.generalInfo);
page.giName.getAttribute("value").then(function (value) {
checkpoint.giName = value; //value 1
});
page.giType.findElement(this.by.selectedOption("field.value")).getText().then(function (value) {
checkpoint.giType = value; //value 2
});
return checkpoint;
} }});
CampaignTest.js
describe('Campaign Management - ', function () {
var loginPage = require('../pages/login.js');
var navigatorPage = require('../pages/navigator.js');
var campaignPage = require('../pages/campaign.js');
beforeEach(function () {
loginPage.loginAs();
navigatorPage.get("a", "b");
});
it('Default - AB_LF_FBX', function () {
var campaignCode = "AB_LF_FBX";
campaignPage.createCampaign(campaignCode); //AB_LF_FBX
var actualResult = campaignPage.getDefaultValue(campaignCode);
console.log("giName3:" + actualResult.giName);
console.log("giType3:" + actualResult.giType);
});
afterEach(function () {
});
});
当我运行这个测试时,控制台打印输出 giName3: auto giType3: auto,
而不是 giName3: value1 giType3: value2
你能纠正我做错的地方吗?
我找到了解决方案
在页面中
getDefaultValue: {
value: function (campaignCode) {
var page = this;
var checkpoint = page.defaultCheckpoint;
/* #Tab General Info */
page.getTabByName(page.informationTabs.generalInfo);
page.giName.getAttribute("value").then(function (value) {
checkpoint.giName = value; //value 1
page.giType.findElement(this.by.selectedOption("field.value")).getText().then(function (value) {
checkpoint.giType = value; //value 2
return checkpoint;
});
});
}
}
测试中
campaignPage.getDefaultValue(campaignCode).then(function (actualResult) {
console.log("giName: " + actualResult.giName);
console.log("giType: " + actualResult.giType);
});