如何从所有行中获取文本使用量角器在无限滚动ng-grid中的列? [英] How to getText from all rows & columns in an infinite scrolling ng-grid using protractor?
问题描述
我正在尝试编写一个函数,该函数在数组中返回完整的网格内容.我们的ng-grid可以无限滚动行,也可以无限滚动列.
I am trying to write a function which returns the complete grid content in an array. Our ng-grid has infinite scrolling through the rows and also have scrolling through the columns.
我找到了在此处滚动的答案量角器:滚动表格并测试无限滚动
I have found an answer for scrolling here Protractor: Scrolling a table and testing for infinite scroll
但是我希望在网格中完全滚动并获取数据,以便在将过滤器应用于网格时可以验证数据.
But I am looking to scroll through the grid fully and get the data, So that I can validate the data when I apply filters to the grid.
对此非常感谢,谢谢
示例行的HTML代码
<div class="ag-body" style="padding-top: 25px; padding-bottom: 30px;">
<div class="ag-pinned-left-cols-viewport" style="display: inline; height: 245px;">
<div class="ag-pinned-left-cols-container" style="width: 480px; height: 1830px; top: 0px;">
<div class="ag-row ag-row-no-focus ag-row-even ag-row-level-0 ag-row-id-111 ag-row-index-10" style=" top: 300px; height: 30px;" row-id="111" row="10" v_element_id="19490">
<div class="ag-cell ag-cell-no-focus ag-cell-value" style=" left: 0px; width: 35px;" colid="id" v_element_id="19491">
<div class="ag-cell ag-cell-no-focus ag-cell-value" style=" left: 35px; width: 245px;" colid="title" v_element_id="19492">June12-AA-3</div>
<div class="ag-cell ag-cell-no-focus ag-cell-value" style=" left: 280px; width: 200px;" colid="operation_status_enum" v_element_id="19493">INVALID</div>
</div>
<div class="ag-row ag-row-no-focus ag-row-odd ag-row-level-0 ag-row-id-110 ag-row-index-9" style=" top: 270px; height: 30px;" row-id="110" row="9" v_element_id="20136">
<div class="ag-row ag-row-no-focus ag-row-even ag-row-level-0 ag-row-id-109 ag-row-index-8" style=" top: 240px; height: 30px;" row-id="109" row="8" v_element_id="20153">
<div class="ag-row ag-row-no-focus ag-row-even ag-row-level-0 ag-row-id-107 ag-row-index-6" style=" top: 180px; height: 30px;" row-id="107" row="6" v_element_id="20170">
<div class="ag-row ag-row-no-focus ag-row-odd ag-row-level-0 ag-row-id-108 ag-row-index-7" style=" top: 210px; height: 30px;" row-id="108" row="7" v_element_id="20187">
<div class="ag-row ag-row-no-focus ag-row-even ag-row-level-0 ag-row-id-105 ag-row-index-4" style=" top: 120px; height: 30px;" row-id="105" row="4" v_element_id="20204">
<div class="ag-row ag-row-no-focus ag-row-odd ag-row-level-0 ag-row-id-106 ag-row-index-5" style=" top: 150px; height: 30px;" row-id="106" row="5" v_element_id="20221">
<div class="ag-row ag-row-no-focus ag-row-odd ag-row-level-0 ag-row-id-104 ag-row-index-3" style=" top: 90px; height: 30px;" row-id="104" row="3" v_element_id="20238">
<div class="ag-row ag-row-no-focus ag-row-odd ag-row-level-0 ag-row-id-102 ag-row-index-1" style=" top: 30px; height: 30px;" row-id="102" row="1" v_element_id="20255">
<div class="ag-row ag-row-no-focus ag-row-even ag-row-level-0 ag-row-id-103 ag-row-index-2" style=" top: 60px; height: 30px;" row-id="102" row="1" v_element_id="20258">
推荐答案
我能够通过以下方式滚动浏览网格并从所有行中获取数据.我从量角器:滚动一个表并测试无限滚动(感谢@alecxe)
I am able to scroll through the grid and get the data from all rows in the following way. I got the scrollDown code from Protractor: Scrolling a table and testing for infinite scroll (thanks @alecxe)
for循环中几乎没有硬编码.我应该找到一种方法来知道我应该向下滚动表格多少次.而且最终结果中有些重复项需要清理.
There is little hard coding in the for loop. I should find out a way to know how many times I should scrollDown the table. Also the final result have some duplicates will need to clean it up.
scrollDown() {
return browser.executeScript("return arguments[0].offsetTop;", this.lastRow.getWebElement()).then((offset) => {
browser.executeScript("arguments[0].scrollTop = arguments[1];", element(by.className("ag-body-viewport")).getWebElement(), offset);
});
}
getRows() {
return this.pinnedRows.getText();
}
getTotalRows() {
const defer = Promise.defer();
let allRows = [];
for (let i = 0; i < 3; i++) {
this.getRows().then((rows) => {
allRows = allRows.concat(rows);
this.scrollDown();
this.waitToLoad();
if (i === 2) {
defer.resolve(allRows);
}
});
}
return defer.promise;
}
waitToLoad() {
waitFor.elementToBeVisible(this.pinnedRows.get(15));
browser.waitForAngular();
}
在规格中:
getTotalRows().then((data) => {
log.info(`TOTAL ROWS: ${data}`);
log.info(`TOTAL NUMBER OF ROWS : ${data.length}`);
expect(data.length).toBeGreaterThan(50);
});
这篇关于如何从所有行中获取文本使用量角器在无限滚动ng-grid中的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!