Skip to content

add method for switching to parent window #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Table extends Element {
protected String tableRowTag = "tr";
protected String tableCellDataTag = "td";
protected String tableDataCellLocator = "//" + tableCellDataTag;
protected String tableRowLocator = ".//tbody//" + tableRowTag;
protected String tableRowLocator = ".//tbody//" + tableCellDataTag + "/..";
protected String tableSiblingCellLocator = "//..//*";

/**
Expand Down Expand Up @@ -196,10 +196,9 @@ protected void createRowData(){
* @return int the number of row elements
*/
public int getNumberOfRows() {
//Selenium counts a <th> tag as a <td> tag and returns it.
final int numberOfRows = getOrCreateRowElements().size();
log.trace("Number of rows found: {}", numberOfRows);
return numberOfRows - 1;
return numberOfRows;
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/dougnoel/sentinel/pages/PageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,19 @@ private static void switchToNewWindow(String pageName, String index) throws Inte
*/
public static String closeChildWindow() throws InterruptedException {
WebDriverFactory.close();
return switchToParentWindow();
}

/**
* Switches to the parent window without closing the child window.
*
* @return String the handle of the parent window to which we are returning
* @throws InterruptedException
*/
public static String switchToParentWindow() throws InterruptedException {
driver().switchTo().window(parentHandle);
setPage(parentPage);
waitForPageLoad();
setPage(parentPage);
waitForPageLoad();
return parentHandle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class TableVerificationSteps {
* @param expectedNumberOfRows int The number of rows your are expecting.
* @param elementName String (Table name) This should be the name of the table element to count.
*/
@Then("^I see (\\d+) rows in the (.*)$")
@Then("^I see (\\d+) rows? in the (.*)$")
public static void verifyNumberOfTableRows(int expectedNumberOfRows, String elementName) {
int numberOfRows = getElementAsTable(elementName).getNumberOfRows();
var expectedResult = SentinelStringUtils.format("Expected {} rows, found {} rows.", expectedNumberOfRows, numberOfRows);
Expand Down