如何用量角器比较不同windows(制表符)中的两个值?

How to compare two values in different windows (tabs) with protractor?

我有这个代码:

element.all(by.repeater('publication in newsPublications')).count().then(function (numNoticias) {

                for (var i = 6; i < numNoticias; i++) {

                    array[i] = element.all(by.repeater('publication in newsPublications')).get(i)
                 .element(by.tagName('a')).getText();

                    browser.ignoreSynchronization = true;
                    element.all(by.repeater('publication in newsPublications')).get(i)
                  .element(by.tagName('a')).click().then(function () {

                      browser.driver.getAllWindowHandles().then(function (handles) {

                          browser.wait(function () {
                              return handles.length > 1
                          }, espera);

                          browser.driver.switchTo().window(handles[1]).then(function () {

                              expect(element(by.css('#contenido .limpiar')).getText()).toEqual(array[i]); // IT FAILS!!!!!

                              browser.driver.close();
                              browser.driver.switchTo().window(handles[0]); 
                          });
                      });

                  });

但我不知道如何在打开的新选项卡中断言数组的值。期望失败......错误说:

Expected 'Text tab 1' to equal to undefined.

我认为您可以通过避免使用索引循环并切换到 .each() 来简化它。另外,我还将明确解析 getText() 以获取 link 文本:

element.all(by.repeater('publication in newsPublications')).each(function (publication) {
    var link = publication.element(by.tagName('a'));

    browser.ignoreSynchronization = true;
    link.getText().then(function (linkText) {
        link.click().then(function () {
            browser.driver.getAllWindowHandles().then(function (handles) {
                browser.wait(function () {
                    return handles.length > 1
                }, espera);

                browser.driver.switchTo().window(handles[1]).then(function () {

                    expect(element(by.css('#contenido .limpiar')).getText()).toEqual(linkText);

                    browser.driver.close();
                    browser.driver.switchTo().window(handles[0]);
                });
            });
        });
    });
});