8000 Improve Admin UI stability for Playwright E2E tests by edewit · Pull Request #52323 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d569d97
Improve Admin UI stability for Playwright E2E tests
edewit Sep 2, 2026
14d23d9
Address Copilot review feedback on Admin UI stability
edewit Sep 3, 2026
cb37beb
Fix Admin UI E2E regressions from simplified test helpers
edewit Sep 3, 2026
94c1b3b
Fix remaining Admin UI E2E helper and table loading issues
edewit Sep 3, 2026
7dc195b
Address Copilot review on loading overlays and table readiness
edewit Sep 3, 2026
e9e33f9
Fix table loading waits for hidden table-ready markers
edewit Sep 3, 2026
67f3015
Use switchOff helper for JWT grant JWKS URL toggle
edewit Sep 4, 2026
39754dd
Fix table-ready race in loading waits and switch clicks
edewit Sep 4, 2026
93193d4
Fix clickCreateUser wait before Users page is interactive
edewit Sep 7, 2026
9286dc9
Address ssilvert review feedback on Admin UI stability PR
edewit Sep 9, 2026
0c36adc
Address Copilot review on drag handles and loading waits
edewit Sep 9, 2026
e9f9ba5
Fix E2E regressions from oversimplified table and switch helpers
edewit Sep 9, 2026
df2e57b
Fix loading waits counting hidden spinners and refresh mappers list
edewit Sep 9, 2026
81c6079
Split loading test signals and wait for interaction targets
edewit Sep 9, 2026
2a871b9
Address Copilot review on table fetch races and test helpers
edewit Sep 10, 2026
c7d15fe
Fix table toolbar helper strict mode on group pages
edewit Sep 10, 2026
b6119d0
Address remaining PR review feedback on loading waits and flow reorder
edewit Sep 17, 2026
dc0d848
Harden table row and toolbar helpers against loading races
edewit Dec 4, 2026
8e30af3
Fix toolbar helper strict-mode failure in Admin UI E2E
edewit Dec 4, 2026
341247f
Address Copilot review on table reload races and flow reorder
edewit Dec 4, 2026
31be142
Address remaining ssilvert review on Admin UI stability PR
edewit Dec 4, 2026
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
43 changes: 43 additions & 0 deletions js/apps/admin-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,49 @@ The Playwright tests under `js/apps/admin-ui/test` accept these environment vari

These test-only variables are different from server bootstrap variables such as `KC_BOOTSTRAP_ADMIN_USERNAME` and `KC_BOOTSTRAP_ADMIN_PASSWORD`.

## Playwright loading conventions

Async UI in the admin console exposes two distinct loading signals for E2E tests:

- `data-testid="table-loading-overlay"` — visible while a `LoadingOverlay` table fetch is in progress (skeleton overlay). The container also sets `aria-busy="true"`.
- `data-testid="page-loading-spinner"` — visible while a full-page `KeycloakSpinner` placeholder is shown before a section mounts (for example the Users list before `UserDataTable`).

Prefer waiting for the **element you interact with** (row link, toolbar button, empty-state action) rather than polling spinners globally.

### Helpers

```ts
import {
waitForLoadingComplete,
waitForLoadingCycle,
waitForPageLoadingComplete,
waitForTableIdle,
} from "./utils/loading.ts";
```

| Helper | Use when |
|--------|----------|
| `waitForLoadingComplete` | After an action that triggers a `KeycloakDataTable` reload; waits for overlay absence |
| `waitForLoadingCycle` | After search Enter or refresh; tolerates a short delay before the overlay appears |
| `waitForPageLoadingComplete` | A page still shows `KeycloakSpinner` before its main content |
| `waitForTableIdle` | Both overlay and page spinner must clear (e.g. navigating to Users) |

```ts
await page.keyboard.press("Enter");
await waitForLoadingCycle(page);
await page.locator("table tbody").getByRole("link", { name: itemName }).click();
```

`clickTableRowItem` and `assertRowExists` wait directly on row/link locators. `clickTableToolbarItem` waits for the toolbar to appear (it is not rendered until the first table fetch completes on empty tables).

### Required test fallbacks (CI)

Some PatternFly and browser interactions still need fallbacks despite UI stability work:

- **Switches** — use `clickSwitch` / `switchOn` / `switchOff` from `form.ts` (label force-click), not raw `.click()` on the hidden input
- **Authentication flow drag** — `dragExecutionAboveExecution` tries pointer, `dragTo`, and keyboard paths; waits for `flow-order-stable` before and after a move
- **Table row names** — `clickTableRowItem` matches substring link text (disabled badges), exact names, and `provider-name-link` for draggable provider tables

## Building

To build a library instead of an app you need to add the `LIB=true` environment variable.
Expand Down
179 changes: 105 additions & 74 deletions js/apps/admin-ui/src/authentication/FlowDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ export default function FlowDetails() {
const { id, usedBy, builtIn } = useParams<FlowParams>();
const navigate = useNavigate();
const [key, setKey] = useState(0);
const refresh = () => setKey(new Date().getTime());
const refresh = () => setKey((current) => current + 1);

const [tableView, setTableView] = useState(true);
const [flow, setFlow] = useState<AuthenticationFlowRepresentation>();
const [executionList, setExecutionList] = useState<ExecutionList>();
const [liveText, setLiveText] = useState("");
const [isReordering, setIsReordering] = useState(false);

const [showAddExecutionDialog, setShowAddExecutionDialog] =
useState<boolean>();
Expand Down Expand Up @@ -93,13 +94,15 @@ export default function FlowDetails() {
({ flow, executions }) => {
setFlow(flow);
setExecutionList(new ExecutionList(executions));
setIsReordering(false);
Comment thread
edewit marked this conversation as resolved.
Resolved
Comment thread
edewit marked this conversation as resolved.
Resolved
},
[key],
);

const executeChange = async (
ex: AuthenticationFlowRepresentation | ExpandableExecution,
change: LevelChange | IndexChange,
options: { refresh?: boolean } = { refresh: true },
) => {
try {
let id = ex.id!;
Expand Down Expand Up @@ -127,13 +130,24 @@ export default function FlowDetails() {
type: "basic-flow",
});
id = result.id!;
ex.executionList?.forEach((e, i) =>
executeChange(e, {
parent: { ...ex, id: result.id },
newIndex: i,
oldIndex: i,
}),
);
// Recreate children sequentially so completion order cannot shuffle
// them, and skip nested refresh until the top-level call finishes.
if (ex.executionList?.length) {
for (let i = 0; i < ex.executionList.length; i++) {
const childSuccess = await executeChange(
ex.executionList[i],
{
parent: { ...ex, id: result.id },
newIndex: i,
oldIndex: i,
},
{ refresh: false },
);
if (!childSuccess) {
return false;
Comment on lines +146 to +147
}
}
}
} else {
const result =
await adminClient.authenticationManagement.addExecutionToFlow({
Expand Down Expand Up @@ -165,10 +179,14 @@ export default function FlowDetails() {
});
}
}
refresh();
addAlert(t("updateFlowSuccess"), AlertVariant.success);
if (options.refresh) {
refresh();
addAlert(t("updateFlowSuccess"), AlertVariant.success);
}
return true;
} catch (error) {
addError("updateFlowError", error);
return false;
}
};

Expand Down Expand Up @@ -409,74 +427,87 @@ export default function FlowDetails() {
</Toolbar>
<DeleteConfirm />
{tableView && (
<DragDrop
index }) => {
const item = executionList.findExecution(index)!;
setLiveText(t("onDragStart", { item: item.displayName }));
if (!item.isCollapsed) {
item.isCollapsed = true;
setExecutionList(executionList.clone());
}
return true;
}}
index }) => {
const dragged = executionList.findExecution(index);
setLiveText(t("onDragMove", { item: dragged?.displayName }));
}}
dest) => {
if (dest) {
if (source.index === dest.index) {
return false;
<div
data-testid={!isReordering ? "flow-order-stable" : undefined}
>
<DragDrop
index }) => {
const item = executionList.findExecution(index)!;
setLiveText(t("onDragStart", { item: item.displayName }));
if (!item.isCollapsed) {
item.isCollapsed = true;
setExecutionList(executionList.clone());
}

const dragged = executionList.findExecution(source.index)!;
const order = executionList.order().map((ex) => ex.id!);
return true;
}}
index }) => {
const dragged = executionList.findExecution(index);
setLiveText(
t("onDragFinish", { list: dragged.displayName }),
t("onDragMove", { item: dragged?.displayName }),
);
}}
dest) => {
if (dest) {
if (source.index === dest.index) {
return false;
}

const [removed] = order.splice(source.index, 1);
order.splice(dest.index, 0, removed);
const change = executionList.getChange(dragged, order);
void executeChange(dragged, change);
return true;
} else {
setLiveText(t("onDragCancel"));
return false;
}
}}
>
<Droppable hasNoWrapper>
<Table aria-label={t("flows")} isTreeTable>
<FlowHeader />
<>
{executionList.expandableList.map((execution) => (
<Tbody draggable key={execution.id}>
<FlowRow
builtIn={!!builtIn}
execution={execution}
=> {
execution.isCollapsed = !execution.isCollapsed;
setExecutionList(executionList.clone());
}}
>
type) =>
addExecution(execution.displayName!, type)
}
flow) =>
addFlow(execution.displayName!, flow)
}
=> {
setSelectedExecution(execution);
toggleDeleteDialog();
}}
/>
</Tbody>
))}
</>
</Table>
</Droppable>
</DragDrop>
const dragged = executionList.findExecution(
source.index,
)!;
const order = executionList.order().map((ex) => ex.id!);
setLiveText(
t("onDragFinish", { list: dragged.displayName }),
);

const [removed] = order.splice(source.index, 1);
order.splice(dest.index, 0, removed);
const change = executionList.getChange(dragged, order);
setIsReordering(true);
void executeChange(dragged, change).then((success) => {
if (!success) {
setIsReordering(false);
}
Comment thread
Copilot marked this conversation as resolved.
Resolved
});
return true;
} else {
setLiveText(t("onDragCancel"));
return false;
}
}}
>
<Droppable hasNoWrapper>
<Table aria-label={t("flows")} isTreeTable>
<FlowHeader />
<>
{executionList.expandableList.map((execution) => (
<Tbody draggable key={execution.id}>
<FlowRow
builtIn={!!builtIn}
execution={execution}
=> {
execution.isCollapsed = !execution.isCollapsed;
setExecutionList(executionList.clone());
}}
>
type) =>
addExecution(execution.displayName!, type)
}
flow) =>
addFlow(execution.displayName!, flow)
}
=> {
setSelectedExecution(execution);
toggleDeleteDialog();
}}
/>
</Tbody>
))}
</>
</Table>
</Droppable>
</DragDrop>
</div>
)}
{flow && (
<>
Expand Down
70 changes: 36 additions & 34 deletions js/apps/admin-ui/src/clients/authorization/Scopes.tsx
10BC8
Original file line number Diff line number Diff line change
Expand Up @@ -265,40 +265,42 @@ export const AuthorizationScopes = ({
<Td />
<Td colSpan={4}>
<ExpandableRowContent>
{isExpanded(scope.id) && scope.isLoaded ? (
<DescriptionList
isHorizontal
className="keycloak_resource_details"
>
<DetailDescriptionLink
name="resources"
array={scope.resources}
convert={(r) => r.name!}
link={(r) =>
toResourceDetails({
id: clientId,
realm,
resourceId: r._id!,
})
}
/>
<DetailDescriptionLink
name="associatedPermissions"
array={scope.permissions}
convert={(p) => p.name!}
link={(p) =>
toPermissionDetails({
id: clientId,
realm,
permissionId: p.id!,
permissionType: p.type!,
})
}
/>
</DescriptionList>
) : (
<KeycloakSpinner />
)}
{isExpanded(scope.id) ? (
scope.isLoaded ? (
<DescriptionList
isHorizontal
className="keycloak_resource_details"
>
<DetailDescriptionLink
name="resources"
array={scope.resources}
convert={(r) => r.name!}
link={(r) =>
toResourceDetails({
id: clientId,
realm,
resourceId: r._id!,
})
}
/>
<DetailDescriptionLink
name="associatedPermissions"
array={scope.permissions}
convert={(p) => p.name!}
link={(p) =>
toPermissionDetails({
id: clientId,
realm,
permissionId: p.id!,
permissionType: p.type!,
})
}
/>
</DescriptionList>
) : (
<KeycloakSpinner />
)
) : null}
</ExpandableRowContent>
</Td>
</Tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export default function DetailSettings() {
const navigate = useNavigate();
const { realm, realmRepresentation } = useRealm();
const [key, setKey] = useState(0);
const refresh = () => setKey(key + 1);
const refresh = () => setKey((current) => current + 1);
const [orgSubTab, setOrgSubTab] = useState("org-list");
const { hasAccess } = useAccess();

Expand Down Expand Up @@ -540,6 +540,9 @@ export default function DetailSettings() {

const result: IdPWithMapperAttributes = {
...mapperType,
// Override the mapper-type id from the spread with the unique instance id
// so table row keys / selection stay stable across reloads.
id: loaderMapper.id!,
name: loaderMapper.name!,
type: mapperType?.name!,
mapperId: loaderMapper.id!,
96AF Expand Down Expand Up @@ -860,8 +863,7 @@ export default function DetailSettings() {
}
/>
}
loader={loader}
key={key}
loader={{ signal: key, loader }}
Comment thread
edewit marked this conversation as resolved.
Resolved
ariaLabelKey="mappersList"
searchPlaceholderKey="searchForMapper"
toolbarItem={
Expand Down
Loading
Loading
0