Skip to content

Commit

Permalink
Fix Table.getRows() with Selectors.isVisible()
Browse files Browse the repository at this point in the history
  • Loading branch information
jreznot committed Jan 16, 2018
1 parent e026b47 commit 8b7f146
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

## Unreleased

## 1.0.2 - 2018-01-16

### Fixed

- Table.getRows() with Selectors.isVisible()

### Added

- Table.getCell() with Selectors.byRowColIndexes(r, c)

## 1.0.1 - 2018-01-09

### Added
Expand Down
37 changes: 35 additions & 2 deletions modules/web/src/main/java/com/haulmont/masquerade/Selectors.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public static By byRowIndex(int index) {
return new ByRowIndex(index);
}

public static By byRowColIndexes(int rowIndex, int colIndex) {
return new ByRowColIndexes(rowIndex, colIndex);
}

public static By byText(String cellText) {
return new ByTargetText(cellText);
}
Expand Down Expand Up @@ -268,12 +272,41 @@ public ByVisibleRows() {
@Override
public List<WebElement> findElements(SearchContext context) {
throw new RuntimeException(
"BySelected must be checked ony in Component implementations");
"ByVisibleRows must be checked ony in Component implementations");
}

@Override
public String toString() {
return "By.visibleRows";
}
}

public static class ByRowColIndexes extends By {
private int rowIndex;
private int colIndex;

public ByRowColIndexes(int rowIndex, int colIndex) {
this.rowIndex = rowIndex;
this.colIndex = colIndex;
}

@Override
public List<WebElement> findElements(SearchContext context) {
throw new RuntimeException(
"ByRowColIndexes must be checked ony in Component implementations");
}

@Override
public String toString() {
return "By.allRows";
return "By.colRowIndexes";
}

public int getRowIndex() {
return rowIndex;
}

public int getColIndex() {
return colIndex;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public interface Table extends Component<Table> {
* <li>{@link Selectors#withText(String)}</li>
* <li>{@link Selectors#byClassName(String)}</li>
* <li>{@link Selectors#byRowIndex(int)}</li>
* <li>{@link Selectors#byRowColIndexes(int, int)}</li>
* </ul>
*
* @param cellBy cell selector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public SelenideElement getRow(By rowBy) {

return $(byChain(by, byClassName("v-table-table"), byXpath(trsXpath)));
})
.when(hasType(ByVisibleRows.class)).get(by -> {
.when(hasType(ByVisibleRows.class)).get(byVisibleRows -> {
return $(byChain(by, byClassName("v-table-table"), byXpath(".//tr")));
})
.getMatch();
Expand Down Expand Up @@ -180,7 +180,7 @@ public ElementsCollection getRows(By rowBy) {

return $$(byChain(by, byClassName("v-table-table"), byXpath(trsXpath)));
})
.when(hasType(ByVisibleRows.class)).get(by -> {
.when(hasType(ByVisibleRows.class)).get(byVisibleRows -> {
return $$(byChain(by, byClassName("v-table-table"), byXpath(".//tr")));
})
.getMatch();
Expand Down Expand Up @@ -213,6 +213,14 @@ public SelenideElement getCell(By cellBy) {

return $(byChain(by, byXpath(tdXpath)));
})
.when(hasType(ByRowColIndexes.class)).get(byColRow -> {
int rowIndex = byColRow.getRowIndex() + 1;
int colIndex = byColRow.getColIndex() + 1;

String tdsXpath = "(.//tr)[" + rowIndex + "]//td[" + colIndex +"]";

return $(byChain(by, byClassName("v-table-table"), byXpath(tdsXpath)));
})
.getMatch();
}

Expand Down

0 comments on commit 8b7f146

Please sign in to comment.