mercredi 1 juin 2016

getText() on items ng-repeat returns empty string

Currently our team is writing tests using Protractor for our software project written in AngularJS. For a specific test, we have to retrieve the values from a dropdown button to see if a previous saved value has actually been saved.

The code is as follows:

this.Then(/^the profile is saved under the name (.*)$/, function (presetName, callback) {
    element.all(by.repeater('preset in dropDown.presets')).each(function(element, index){
        console.log("Index: ", index);
        element.getText().then(function(name){
            console.log("Text of element: ", name);     //name is empty string
        });
    });
    callback("Error, presetName was not found!");
});

The corresponding HTML:

    <div class="btn-group" uib-dropdown>
        <button id="presetList" type="button" class="btn btn-primary" uib-dropdown-toggle
                style="min-width:100px" ng-disabled="presets.length == 0">
            
            <span class="caret"></span>
        </button>
        <ul uib-dropdown-menu role="menu" class="listOfPresets">
            <li role="menuitem" ng-repeat="preset in dropDown.presets">
                <a href ng-click="setSelected(preset)">
                    
                </a>
            </li>
        </ul>
    </div>

As we have already seen in previous posts (here), this does not work. We have tried element.getAttribute('value') but this does not work either, although this is suggested on the FAQ. We know for sure the element is there (count prints 1), and we can even see the element after the test ends, but we are still having problems retrieving the names for those entries.

Any help is appreciated!

Aucun commentaire:

Enregistrer un commentaire