How to locate [(ngModel)] for protractor tests

我是研究僧i 提交于 2019-12-22 13:08:05

问题


<span class="selector-label">Team: </span>
<select class="selector-component" [(ngModel)]="selectedTeamId">
  <option *ngFor="#team of teams" [value]="team.id">{{team.name}}</option>
</select>

I am trying to add protractor tests for the selectedTeamId which is the first one sorted alphabetically if one user assigned to multiple teams. I think I should use [(ngModel)]="selectedTeamId", but not sure how to do it. thanks. I know how to get all teams, but I need to get the first one which is the logical implemented in selectedTeamId method.


回答1:


The idea would be to locate the select element (by the preceding label, for example), evaluate teams, sort it alphabetically by name, get the first team and check that this is the same as the selectedTeamId model value:

var select = element(by.xpath("//span[starts-with(., 'Team')]/following-sibling::select"));

select.evaluate("teams").then(function(teams) {
    teams.sort(function(a, b) {
         return a["name"].localeCompare(b["name"])
    });
    var firstTeam = teams[0];

    expect(select.evaluate("selectedTeamId")).toEqual(firstTeam);
});


来源:https://stackoverflow.com/questions/36378343/how-to-locate-ngmodel-for-protractor-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!