Skip to content

Commit

Permalink
Adapt to dialog changes in matrix-auth 3.2.3 (#1804)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Beck <[email protected]>
  • Loading branch information
daniel-beck and daniel-beck authored Oct 23, 2024
1 parent e031172 commit 122bbab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ public MatrixAuthorizationStrategy(GlobalSecurityConfig context, String path) {
* Adds a new user to this matrix.
*/
public MatrixRow addUser(String name) {
runThenHandleAlert(
runThenHandleInputDialog(
() -> this.table
.resolve()
.findElement(
by.xpath(
"../div/span/span/button[text()='Add user\u2026'] | ../div/button[text()='Add user\u2026']"))
.click(),
a -> {
a.sendKeys(name);
a.accept();
});
name,
"OK");
return getUser(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ public ProjectMatrixProperty(Job job) {
* Adds a new user/group to this matrix.
*/
public MatrixRow addUser(String name) {
runThenHandleAlert(
runThenHandleInputDialog(
() -> this.table
.resolve()
.findElement(
by.xpath(
"../div/span/span/button[text()='Add user\u2026'] | ../div/button[text()='Add user\u2026']"))
.click(),
a -> {
a.sendKeys(name);
a.accept();
});
name,
"OK");
return getUser(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,31 @@ public void runThenHandleDialog(Runnable runnable) {
}
}

/**
* Executes the runnable, then attempts to write {@code input} in a dialog's input field and click the button with the specified label {@code buttonLabel}.
* If an alert appears, instead the runnable is re-run, the input written to the alert, then the alert is submitted.
*
* @param runnable the runnable to run that causes a dialog to appear
* @param input the text to input into the dialog or alert
* @param buttonLabel the button of the dialog to click
*/
public void runThenHandleInputDialog(Runnable runnable, String input, String buttonLabel) {
try {
runnable.run();
waitFor(by.button(buttonLabel));
find(by.css("dialog input")).sendKeys(input);
clickButton(buttonLabel);
} catch (UnhandledAlertException uae) {
runThenHandleAlert(
runnable,
a -> {
a.sendKeys(input);
a.accept();
},
2);
}
}

public void handleAlert(Consumer<Alert> action) {
runThenHandleAlert(null, action);
}
Expand Down

0 comments on commit 122bbab

Please sign in to comment.