Skip to content
New issue

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

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

Already on GitHub? # to your account

Adapt to dialog changes in matrix-auth 3.2.3 #1804

Merged
merged 3 commits into from
Oct 23, 2024
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 @@ -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
Loading