量角器 - 星盘 - 无法设置数组值

时间:2014-04-03 06:45:50

标签: arrays promise protractor astrolabe

我使用带有PageObject astrolabe的Protractor,如下所示

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);
    });

1 个答案:

答案 0 :(得分:1)

我找到了解决方案

在页面

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);
    });