Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 量角器元素ArrayFinder.filter()是否只运行一次?_Javascript_Node.js_Protractor_Webdriverjs - Fatal编程技术网

Javascript 量角器元素ArrayFinder.filter()是否只运行一次?

Javascript 量角器元素ArrayFinder.filter()是否只运行一次?,javascript,node.js,protractor,webdriverjs,Javascript,Node.js,Protractor,Webdriverjs,我在页面对象中多次筛选元素的ElementArrayFinder时遇到问题。第二个过滤器在第一个过滤器之后被调用。在下面的代码中,我首先验证表中是否有数字,然后再次过滤以单击它。我之所以不将它们合并,是因为它们在依赖于函数参数batchNumber的函数中,并且可能不同 过滤器: function verifyBatchInList(batchNumber){ BATCH_LIST_TABLE.filter(function(elem, i){ return elem.e

我在页面对象中多次筛选
元素的ElementArrayFinder时遇到问题。第二个过滤器在第一个过滤器之后被调用。在下面的代码中,我首先验证表中是否有数字,然后再次过滤以单击它。我之所以不将它们合并,是因为它们在依赖于函数参数batchNumber的函数中,并且可能不同

过滤器:

function verifyBatchInList(batchNumber){
    BATCH_LIST_TABLE.filter(function(elem, i){
        return elem.element(by.xpath('./td[1]')).getText().then(function(text){
            text = text.trim();
            return text === batchNumber;
        });
    }).then(function(results){
        if(results.length < 1){
            throw new Error('Could not find batch "'+batchNumber+'" in batch list');
        }
    });
}
function editBatch(batchNumber){
    selectBatch(batchNumber);
    EDIT_BUTTON.click(); //this never happens
}
function selectBatch(batchNumber){
    BATCH_LIST_TABLE.filter(function(elem, i){ //this function never runs
        return elem.element(by.xpath('./td[1]')).getText().then(function(text){
            text = text.trim();
            return batchNumber === text;
        });
    }).then(function(results){ //this never runs either
        if(results.length < 1){
            throw new Error('Could not find batch "'+batchNumber+'" in batch list');
        }
        results[0].click();
    });

html只是一个表,第一个td是批号。

batchID
数组吗?是否在每个规范之前将其初始化为空数组?我的意思是,在您的第二个规范中,
batchId[0]
保留
未定义的
。不,batchId是在这两个函数之外定义的,它不是未定义的。我认为问题在于editBatch和Commit Batch函数,因为我删除了第一个过滤器,它仍然存在问题。我发现问题在别处。放弃这个问题
it('can commit batch', function(){
    page.addSpecimens.getBatchId().then(function(text){
        batchIds[0] = text.split(' ')[0];
        page.addSpecimens.commitBatch();
        page = new pages.batchList();
        browser.sleep(2000); //for page to load, just temporary
        page.verifyBatchInList(batchIds[0]); //this works fine
    });
});
it('can edit batch',function(){
    page.editBatch(batchIds[0]); //this runs, but never actually filters
});