Protractor 如何阻止执行直到函数返回值?

Protractor 如何阻止执行直到函数返回值?,protractor,angularjs-e2e,Protractor,Angularjs E2e,在量角器中,我试图从按钮集合中获取按钮的文本,并根据返回的按钮对返回的项目执行一些操作 /** * Function to return the element button with matching text * @param {buttonsObject} element which matches multiple button objects. * @param {buttonTextToSearch} button text which can be found in a colle

在量角器中,我试图从按钮集合中获取按钮的文本,并根据返回的按钮对返回的项目执行一些操作

/**
* Function to return the element button with matching text
* @param {buttonsObject} element which matches multiple button objects.
* @param {buttonTextToSearch} button text which can be found in a collection of button objects.
* @return {buttonObject} this will retrun the button object which matches the text being searched for.
*/
var buttons = function(buttonsObject, buttonTextToSearch) {
        var obj = buttonsObject.then(function(buttonElements) {
            //Iterate each button object and populate the array with the resulting object
            var foundbuttons = buttonElements.map(function(item) {
                return item.getText().then(function(text) {
                    if(text.length > 0 && text.charCodeAt(0) !== 32 && text == buttonTextToSearch) {
                        console.log('new text: '+ text);
                        return item;
                    }
                });
            });
            //Wait until var foundbuttons is populated
            return protractor.promise.all(foundbuttons).then(function(allButtons){
                return allButtons.reduce(function(all, item, index) {
                    if(item !== undefined && item !== '' && item !== ' ') {
                        console.log('item !== undefined '+ item);
                        item.getText().then(function(text) {
                            console.log('REDUCE '+ text);
                        });
                        all.push(item);
                    }
                    return all;
                }, []);
            });
        });

        //Wait until var obj is populated and return the element at 0th index.
        return protractor.promise.all(obj).then(function(obj1) {
            return obj1[0];
        });
    }

    var BTN_OBJS = element.all(by.css('[ng-hide=multiEditMode] [class*=button]'));
    //Get element matching button text 'My Order'
    var btn = buttons(BTN_OBJS, 'My Orders'); 

    btn.then(function(args) {
        console.log('args '+ args);
    });
现在,当我执行上面的代码片段时,下面一行

buttons(BTN_OBJS, 'My Orders');
甚至在下面的函数返回任何值之前执行

    btn.then(function(args) {
        console.log('args '+ args);
    });
PS:我对量角器是新手,因此忽略了我的贫乏知识和任何打字错误