1

I dynamically generate a div string based of user selection from a set of drop down values and input boxes.

Based of these choices, a string is output to the screen via outerHTML.

Example:

<div data-aggiefeed class="aggiefeed-element edus edus-container" data-num-activities="1" data-activity-source="asucd-rss" data-activity-actions data-content-limit data-no-activities-message id="aggieFeedEmbed" data-activity-action-social='["facebook"]'></div>

I want to create a test that checks if the created div tag contains the correct attributes that were chosen. How can I extract attributes from my created div tag and check if the values are equal to its corresponding ng-model? For some attributes, they do not contain a value and I need to simply check if it exists.

I have tried to convert the string into a JSON object but have little success.

I also do not want to check if the string contains a substring since this leaves room for error.

I am running my test using protractor.js.

Thanks.

cching
  • 789
  • 1
  • 8
  • 17
  • FYI, if you are interested in getting all element attributes at once - keep track of http://stackoverflow.com/questions/27694570/get-all-element-attributes-using-protractor. Thanks. – alecxe Dec 29 '14 at 19:14

1 Answers1

1

Find an element and use getAttribute() to check the attribute values:

var div = element(by.id('aggieFeedEmbed'));
expect(div.getAttribute('data-activity-source')).toEqual('asucd-rss');
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195