2016-12-05 120 views
0

Nightwatchjs elementIdText功能有困難,從多個IDNightwatchjs返回文本,使用elementIdText功能,不妨來自異步功能。在一個循環

我發現了一個陣列的Web元素ID,並試圖使文本它們所包含的數組。

我這樣做,因爲原始的getText函數不會遍歷所有元素,但只是第一次出現。

我的常用功能:

module.exports = { 
    'ChildOf' : function(browser, path, callback) { 
    browser 
    .elements('css selector', path, function(elements) { 
     var array = []; 
     elements.value.forEach(function(element) { 
     array.push(element.ELEMENT); 
     }) 
     //console.log(array); out: Final array filled; Works great 
     callback(array); 
    }) 
    }, 

    'getText' : function(browser, elements, callback) { 
    var array = []; 
    elements.forEach(function(element) { 
     browser.elementIdText(element, function(result) { 
     array.push(result.value); 
     //console.log(array); out: Multiple incremented arrays; Need the final array :\ 
     }) 
     //console.log(array); out: Multiple empty arrays; Doesn't work 
    }) 
    //console.log(array); out: Single empty array; Doesn't work 
    callback(array); 
    } 
] 

我的呼叫:

module.exports = { 
    'myStep' : function(browser, expect) { 
    common.ChildOf(browser, '.txt', function(elements) { 
     common.getText(browser, elements, function(result) { 
     //browser.verify.equal(result, expect) 
     }) 
    }) 
    } 
}; 

我需要得到的字符串從我的自定義的getText功能正在添加的全滿陣,我可以比較到另一個陣列(數據驅動測試),有什麼想法?

回答

0

使用promise(Q),添加了4行,這要歸功於this Nightwatchjs Github問題。