量角器 - 根据条件识别嵌套下拉元素时超时

Protractor- Timeout while Identifying a nested dropdown element based on a condition

本文关键字:元素 超时 嵌套 识别 条件 量角器      更新时间:2023-09-26

我正在尝试在我的应用程序中识别并选择具有以下结构的大量嵌套下拉列表(不完全是):

<tr>..</tr> 
<tr>
    <td>...</td>
    <td>
        <grid-field field-name="abc">
            <span>
                <span>
                    <span>
                        <select>
                            <option value="xyz">Some option</option>
                        </select>
                    </span>
                </span>         
            </span>
        </grid-field>
    </td>
    <td>
        <grid-field field-name="environment">
            <span>
                <span>
                    <span>
                        <select>
                            <option value="xyz">Some option</option>    /// Required Dropdown
                        </select>
                    </span>
                </span>         
            </span>
        </grid-field>
    </td>
    <td>
        <grid-field field-name="adasd">
            <span>
                <span>
                    <span>
                        <select>
                            <option value="xyz">Some option</option>
                        </select>
                    </span>
                </span>         
            </span>
        </grid-field>   
    </td>
</tr>
<tr>..</tr>

我已经编写了以下帮助程序函数来选择下拉列表,但出现超时错误。

this.selectValueFromDropDown = function(columnName,dropDownData){
    this.getDropDown(columnName).$("[value='".concat(dropDownData).concat("']")).click();
};
this.getDropDown = function(columnName){
    return element.all(by.tagName('tr')).filter(function(row){
        return row.all(by.tagName('grid-field')).each(function(gridField){
            gridField.getAttribute('field-name').then(function(attribute){
                return attribute === columnName;
            });
        });
    }).first().element(by.tagName('select'));
};

// Spec
gridObject.selectValueFromDropDown('environment','xyz');

错误信息

> Message:
>     Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.   Stack:
>     Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
>         at [object Object]._onTimeout (C:'Users'taaupsa1'AppData'Roaming'npm'node_modules'protractor'node_modules'jasmine-core'lib'jasmine-core'jasmine.js:1812:23)

谁能告诉我我做错了什么?谢谢

知道了,这是一个理论。您缺少each()调用中的return,使其"永远"执行并超过默认的 Jasmine 规范超时:

this.getDropDown = function(columnName){
    return element.all(by.tagName('tr')).filter(function(row){
        return row.all(by.tagName('plm-grid-field')).each(function(gridField){
            // v HERE
            return gridField.getAttribute('field-name').then(function(attribute){
                return attribute === columnName;
            });
        });
    }).first().element(by.tagName('select'));
};

而且,我也认为你的意思是使用filter()而不是each()..