I want to use the Lodash find function to make my Protractor tests more robust.
Instead of
element.all (by.repeater ('topic in topics')).then (function (topics) {
expect (topics[1].element (by.binding ('topic.name')).getText()).toEqual ('Maths');
expect (topics[1].element (by.binding ('topic.description')).getText()).toEqual ('2 + 2 = 4');
});
Something like
element.all (by.repeater ('topic in topics')).then (function (topics) {
var mathsTopic = _.find (topics, 'topic.name', 'Maths');
expect (mathsTopic.element (by.binding ('topic.description')).getText()).toEqual ('2 + 2 = 4');
});
My reasoning is so that, if the order of items in the page changes, the test does not break as it can still find the element with the data it is looking for.
Aucun commentaire:
Enregistrer un commentaire