手风琴里面有一个ul标签。如何使用量角器计算ul标签内的元素数量?另外我需要在ul标签内获取电影标题。任何人都可以建议我如何实现这个目标吗? 示例HTML文件:
<accordion close-others="oneAtATime" [showArrows]="true">
<accordion-group id="forth-coming" class="heading" heading="UPCOMING MOVIES" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled">
<ul class="movies">
<ul *ngFor="let movie of upcomingData">
<div class="results">
<!--Card content-->
<div class=movie-card>
<!--Card image-->
<div class="movie-poster">
<img class="poster lazyautosizes lazyloaded" data-sizes="auto" alt="It" sizes="185px" src="https://image.tmdb.org/t/p/w185_and_h278_bestv2{{movie.poster_path}}">
</div>
<div class="info">
<p class="flex">
<!--Title-->
<a id="movie_346364" class="movie-title" href="/movie/346364" title="It" alt="It">{{movie.title}}</a>
<!--Rating-->
<span class="movie-rating">{{movie.vote_average}}
<span class="glyphicon glyphicon-star star-rating"></span>
</span>
</p>
<!--Description-->
<p class="movie-description">{{movie.overview}}</p>
<button (click)="clickMe(movie,$event)">
<span *ngIf="!myRecommData[movie.title];" class="recommend">Recommend</span>
<span *ngIf="myRecommData[movie.title];" class="unrecommend">UnRecommend</span>
</button>
</div>
</div>
</div>
</ul>
</ul>
</accordion-group>
答案 0 :(得分:0)
let movies = element.all(by.css('.movie-card'))
expect(movies.count()).toEqual(<expected count>)
答案 1 :(得分:0)
ngFor
。
您可以/应该使用CSS选择器,例如:
var movieCards = $$("#forth-coming .movies ul");
// log to the console
movieCards.count().then(console.log);
expect(movieCards.count()).toEqual(2);
就电影片名而言,您可以进一步链接movieCards
以获得标题:
var movieTitles = movieCards.$$(".movie-title");
// log to the console
movieTitles.getText().then(console.log);
expect(movieTitles.getText()).toEqual(["Movie Title 1", "Movie Title 2"]);