无法从元素的值量角器测试返回字符串 [英] Cannot return string from value of element in protractor test

查看:145
本文介绍了无法从元素的值量角器测试返回字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图得到一个字符串值从一个元素的这一承诺的分辨率返回的值。我想通过原始字符串值,我是一个量角器测试建筑物内的其它功能。

So I'm trying to get a string value to be returned from the value of an element on the resolution of this promise. I want to pass a raw string value to another function that I'm building inside a protractor test.

这是元素:

<div style='hidden' >
    <input id="group-sendgrid-hidden-input" ng-model='groupCode' value='dangyo' >
</div>

我正在寻找一种方式来获得在任模型值或属性值(将工作)。模型值甚至可能会更好。

I'm looking for a way to get at either the model value or the attribute value (either will work). Model value might even be better.

这是我试图在这里解决的承诺并返回结果:

This is my attempt to resolve the a promise here and return a result:

// first get the element driver object
var groupCode = element(by.id('group-sendgrid-hidden-input'));

// next resolve a promise provided by this element
groupCode.getAttribute('value').then(function(value){

    console.log( 'should be a string: ' + value);

    return value;
});

下面的的console.log('应当是一个字符串:'+值); 总是返回的在并没有什么我能做的似乎是解决这个问题。我敢肯定,我做错了什么,因为我是新来量角器,这似乎很简单。没有任何其他人遇到这种情况?

Here the console.log( 'should be a string: ' + value); always returns null for the value and nothing I can do seems to resolve this. I'm sure I'm doing something wrong because I am new to protractor and this seems simple. Does anyone else experience this behavior?

推荐答案

这是太大的意见,并仍然是一个猜测,但怎么样制作的自定义的条件等待输入元素的属性值不为 的:

It's too big for a comment and would still be a guess, but how about making a custom "Expected Condition" and wait for the input element's value attribute value not to be null:

var hasNotNullValue = function(elementFinder) {
    return function() {
        return elementFinder.getAttribute("value").then(function(value) {
            return !!value;  // is not null
        });
    }; 
};

var groupCode = element(by.id('group-sendgrid-hidden-input'));
browser.wait(hasNotNullValue(groupCode), 10000);

groupCode.getAttribute('value').then(function(value){
    console.log('should be a string: ' + value);
});


您也可以使用 评估( ) 检索模型值:


You can also use evaluate() to retrieve the model value:

groupCode.evaluate('groupCode').then(function(value) {
    console.log(value);
});

这篇关于无法从元素的值量角器测试返回字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆