使用量角器在ng-repeat中获取ng-model ng-repeat

时间:2016-01-07 17:55:43

标签: angularjs protractor bdd cucumberjs

如何使用量角器在ng-repeat中获得ng-repeat中的ng-model?

<div ng-repeat="field in master.linker | orderBy:'country.name'">
    <div>
        <p> {{ field.country_name }} </p>

            <label ng-repeat="user in user_list">
                <input type="checkbox" ng-model="selected_user">
                <span ng-bind="user.name"></span>
            </label>

    </div>
</div>

我使用filter()检查我的ng-repeat:

var fields = element.all(by.repeater('field in master.linker'));

fields.filter(function (field) {
    return field.element(by.binding("field.country_name")).getText().then(function (country) {
        return country === "en";
    });
}).then(function (filteredFields) {

    var fields2 = filteredFields[0].element.all(by.repeater('user in user_list'));

    return fields2.filter(function (field2) {
        return field2.element(by.binding('user.name')).getText().then(function (value) {
            return value === user;
        });
    }).then(function (filteredFields) {
        var myuser = filteredFields[0].element(by.model('user_name'));

        self.current_step.expect(input.getAttribute('value')).to.eventually.equal('');

    });

});;

我的控制台出现此错误:

TypeError: filteredFields[0].element.all is not a function

1 个答案:

答案 0 :(得分:2)

使用.element.all()代替filteredFields[0].all(by.repeater('user in user_list'));

first()

您还可以使用var fields = element.all(by.repeater('field in master.linker')); var filteredUser = fields.filter(function (field) { return field.element(by.binding("field.country_name")).getText().then(function (country) { return country === "en"; }); }).first().all(by.repeater('user in user_list')).filter(function (userField) { return userField.element(by.binding('user.name')).getText().then(function (value) { return value === user; }); }).first(); var myuser = filteredUser.element(by.model('user_name')); self.current_step.expect(myuser.getAttribute('value')).to.eventually.equal(''); 简化:

var request = require('request');
request('http://www.google.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Show the HTML for the Google homepage. 
  }
  else {
    console.log("Error "+response.statusCode)
  }
})

您也可以查看column() and row() repeater API