The exponent map function returns undefined

Given an application with several widgets on it, each with its own name and much more, I would like to map each element of the widget to simplify their processing in tests.

For example, the page:

this.widgets = element.all(by.css('ul.widget-grid')).map(function(widget, index) {
    return {
        index: index,
        title: widget.element(by.css('div.title')).getText()
    };
});

And then in my specification:

expect(page.widgets[0].index).toBe(0);
expect(page.widgets[0].title).toBe('The Title');

Unfortunately, my expectations come back undefined.

What am I doing wrong? I am using Protractor 2.0.

+4
source share
4 answers

This confused me, so I thought I would add an answer to help others ...

, map() , expect, , , . . , , .

+2

, . -, , :

element.all(by.css('ul.widget-grid')).map(function(widget, index) {
    return {
        index: index,
        title: widget.element(by.css('div.title')).getText()
    }
}).then(function(map){
      this.widgets = map;
   });
+2

map() , .

, :

var widget = page.widgets[0];

expect(widget.index).toBe(0);
expect(widget.title).toBe('The Title');
+1

ElementArrayFinder.prototype.map .
, , for:

 var myElements = element.all(by.css('ul li')) - 1;
 var n = myElements.length - 1;

 for (var i = 0; i < n; i++) {
     var elem = myElements.get(i);
     var open = elem.element(by.css('.some-class'));
     open.click();
     var childElem = filter.element(by.css('[some-attribute]'));
     expect(childElem.isPresent()).toBe(true);
 }
0

Source: https://habr.com/ru/post/1584257/


All Articles