Skip to content

Commit f8667a7

Browse files
committed
feat: Add host-details workflow test with dynamic host ID lookup
1 parent 8865773 commit f8667a7

2 files changed

Lines changed: 39 additions & 14 deletions

File tree

e2e/src/pages/HostManagementPage.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export class HostManagementPage extends BasePage {
1616
}
1717

1818
protected async verifyPageLoaded(): Promise<void> {
19-
await expect(this.page.getByRole('heading', { name: /host management/i })).toBeVisible({ timeout: 10000 });
19+
// Check for either "Host management" heading or "Host setup and management"
20+
const heading = this.page.getByRole('heading', { name: /host.*management/i }).first();
21+
await expect(heading).toBeVisible({ timeout: 10000 });
2022
this.logger.success('Host management page loaded');
2123
}
2224

@@ -47,21 +49,33 @@ export class HostManagementPage extends BasePage {
4749
// Wait for host table to load
4850
await this.page.waitForLoadState('networkidle');
4951

50-
// Look for host IDs in the table
51-
// Host IDs are typically displayed in a column or as links
52-
const hostIdElement = this.page.locator('[data-field="aid"], [data-field="device_id"]').first()
53-
.or(this.page.locator('td').filter({ hasText: /^[a-f0-9]{32}$/i }).first());
52+
// Wait for the hostname column to appear
53+
await this.page.getByText('Hostname').first().waitFor({ state: 'visible', timeout: 10000 });
5454

55+
// Look for any text content matching the 32-character hex ID pattern
5556
try {
56-
const hostId = await hostIdElement.textContent({ timeout: 5000 });
57+
// Use evaluate to search the DOM for text matching host ID pattern
58+
const hostId = await this.page.evaluate(() => {
59+
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
60+
const pattern = /^[a-f0-9]{32}$/i;
5761

58-
if (hostId && hostId.trim()) {
59-
this.logger.success(`Found host ID: ${hostId.trim()}`);
60-
return hostId.trim();
61-
} else {
62-
this.logger.warn('No host ID found in the table');
62+
let node;
63+
while (node = walker.nextNode()) {
64+
const text = node.textContent?.trim() || '';
65+
if (pattern.test(text)) {
66+
return text;
67+
}
68+
}
6369
return null;
70+
});
71+
72+
if (hostId) {
73+
this.logger.success(`Found host ID: ${hostId}`);
74+
return hostId;
6475
}
76+
77+
this.logger.warn('No valid host ID found on page');
78+
return null;
6579
} catch (error) {
6680
this.logger.warn(`Failed to find host ID: ${error.message}`);
6781
this.logger.info('This may indicate no hosts are available in the CID');

e2e/tests/foundry.spec.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,20 @@ test.describe('Functions with Python - E2E Tests', () => {
1818
await workflowsPage.executeAndVerifyWorkflow('Test log-event function');
1919
});
2020

21-
test('should execute Test host-details function workflow', async ({ workflowsPage }) => {
22-
// Skip - requires actual host ID which needs additional implementation
23-
test.skip(true, 'Skipping: Requires host ID implementation');
21+
test('should execute Test host-details function workflow', async ({ workflowsPage, hostManagementPage }) => {
22+
// Get first available host ID
23+
const hostId = await hostManagementPage.getFirstHostId();
24+
25+
if (!hostId) {
26+
test.skip(true, 'Skipping: No hosts available in CID');
27+
return;
28+
}
29+
30+
// Execute workflow with host ID parameter
31+
await workflowsPage.navigateToWorkflows();
32+
await workflowsPage.executeAndVerifyWorkflow('Test host-details function', {
33+
'Host ID': hostId
34+
});
2435
});
2536

2637
test('should render Test servicenow function workflow (without execution)', async ({ workflowsPage }) => {

0 commit comments

Comments
 (0)