输入搜索值后,如何验证网格显示的正确行?

时间:2019-01-04 10:50:45

标签: java search grid-layout

我正在尝试在网格中输入搜索值后验证是否显示了正确的行。我设法用下面的代码用随机值搜索网格:

Grid grid;
grid = runtimeState.allJobsPage.getGrid();
assertNotNull("Unexpected Null Grid", grid);
String[] headersAllJobs = { "Job reference", "Assignment status", "Site", "Asset subtype / classification", "Days outstanding" }; 
String randomHeader = headersAllJobs[RandomUtils.nextInt(0, headersAllJobs.length - 1)];
List<String> columnAllJobs = grid.getColumn(randomHeader); 

String searchString = columnAllJobs.get(RandomUtils.nextInt(0, columnAllJobs.size() - 2)); 
runtimeState.allJobsPage.searchJobs(searchString);
outputHelper.takeScreenshot();

但是,在尝试输入随机搜索值后验证是否显示正确的行时遇到一些问题。这是我当前拥有的代码:

runtimeState.scenario.write("Asserting All jobs table only displays rows with: " + searchString);
grid = runtimeState.allJobsPage.getGrid();

String cellText = "";
for (Row row : grid.getRows()) {
    for (Cell gridcell : row.getCells()) { 
        cellText = cellText + gridcell.getText() + " " + gridcell.getSubText() + " ";
    }
    assertTrue("Row that does not contain: " + searchString, cellText.contains(searchString));

我希望cellText变量存储每一行​​中每个单元格的文本和子文本,然后断言该行中的文本包括我最初搜索网格的内容。但是,由于此for循环cellText中的内容将文本存储在每一行的每个单元格中,因此断言将不起作用。我有更好的方法吗?

0 个答案:

没有答案