量角器:页面对象返回“承诺”而不是文本

时间:2019-03-25 14:46:32

标签: protractor

我有此页面对象方法:

swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if (navigationView.getMenu().getItem(0).isChecked()) {
                    if (Utils.hasNetworkAccess(MainActivity.this)) {
                        getData();
                    } else {
                        Toast.makeText
                                (MainActivity.this, R.string.SwipeRefreshLayout_connect_to_update
                                        , Toast.LENGTH_LONG).show();
                    }
                } else {
                    for (int i = 1; i < 7; i++) {
                        if (navigationView.getMenu().getItem(i).isChecked()) {
                            getItemsByLabel(navigationView.getMenu().getItem(i).getTitle().toString());
                        }
                    }
                }

                new Handler().postDelayed(() -> swipeRefreshLayout.setRefreshing(false), 2000);
            }

        });

运行脚本时,它将返回以下内容:

this.userName = async function(){
    if(environment === 'AWS'){
        return 'user1'
    }else{
        return'user2'
    }
};

有没有办法只返回文本“ user1”,而不是作为诺言?

1 个答案:

答案 0 :(得分:1)

将其重写为:

// option 1
this.userName = await async function(){

// option 2
this.userName = function(){

// and rest of the code
    if(environment === 'AWS'){
        return 'user1'
    }else{
        return'user2'
    }
};