In my Angular application, I have implemented a timeline that displays event dates with their respective descriptions. Below is the HTML source code for this feature:
<!-- timeline -->
<h4 class="font-thin m-t-lg m-b-lg text-primary-lt">Historical Timeline</h4>
<p></p>
<div id="timeline"class="timeline m-l-sm m-r-sm b-info b-l">
<div ng-repeat = "timeline in formattedTimelineData | orderBy : '-eventDate'">
<div class = "tl-item">
<i class="pull-left timeline-badge {{timeline.class}} "></i>
<div class="m-l-lg">
<div id="eventDate{{$index}}" class="timeline-title">{{timeline.eventDate}}</div>
<p id="eventDescription{{$index}}" class="timeline-body">{{timeline.description}}</p>
</div>
</div>
</div>
</div>
<!-- / timeline -->
I am currently utilizing Protractor to verify that each event date corresponds correctly to its description. To achieve this, I decided to use a map function in my test script. The challenge I encountered was determining how many events there are since they are dynamically generated based on the HTML code provided above. Here's the test code snippet I wrote:
it('FOO TEST', function(){
var x = 0;
while(x<4){
var timeline = element.all(by.css('#timeline')).map(function (timeline) {
return {
date: timeline.element(by.css('#eventDate'+x)).getText(),
events: timeline.element(by.css('#eventDescription'+x)).getText()
}
});
x++
}
timeline.then(function (Value) {
console.log(Value);
});
});
The issue I am facing is that when I run the test in the command line, it only prints the details of the last event out of multiple events (5 in this case). It fails to display information about other events. As I am new to working with promises, any suggestions or advice regarding this problem would be greatly appreciated. My goal is to conduct individual tests for each event within the timeline.