@@ -53,27 +53,26 @@ export class HomePage extends BasePage {
5353 public constructor ( page : Page ) {
5454 super ( page ) ;
5555
56- // Stats section - using the heading text
57- this . statsSection = page . locator ( 'text="Stats"' ) . locator ( ".." ) . locator ( ".." ) ;
58-
5956 // Stats cards - using link patterns that match the StatsCard component
6057 this . failedDagsCard = page . locator ( 'a[href*="last_dag_run_state=failed"]' ) ;
6158 this . runningDagsCard = page . locator ( 'a[href*="last_dag_run_state=running"]' ) ;
6259 this . activeDagsCard = page . locator ( 'a[href*="paused=false"]' ) ;
6360 this . dagImportErrorsCard = page . locator ( 'button:has-text("DAG Import Errors")' ) ;
6461
65- // Health section - using text content matching
66- this . healthSection = page . locator ( 'text="Health"' ) . locator ( ".." ) . locator ( ".." ) ;
62+ // Stats section - using role-based selector
63+ this . statsSection = page . getByRole ( "heading" , { name : "Stats" } ) . locator ( ".." ) ;
64+ // Health section - using role-based selector
65+ this . healthSection = page . getByRole ( "heading" , { name : "Health" } ) . locator ( ".." ) ;
6766 this . metaDatabaseHealth = page . getByText ( "Metadatabase" ) . first ( ) ;
6867 this . schedulerHealth = page . getByText ( "Scheduler" ) . first ( ) ;
6968 this . triggererHealth = page . getByText ( "Triggerer" ) . first ( ) ;
7069 this . dagProcessorHealth = page . getByText ( "DAG Processor" ) . first ( ) ;
7170
72- // Pool Summary section
73- this . poolSummarySection = page . locator ( 'text=" Pool Summary"' ) . locator ( ".." ) . locator ( ".." ) ;
71+ // Pool Summary section - using role-based selector
72+ this . poolSummarySection = page . getByRole ( "heading" , { name : " Pool Summary" } ) . locator ( ".." ) ;
7473
75- // Historical Metrics section (recent runs)
76- this . historicalMetricsSection = page . getByText ( "History" ) . first ( ) . locator ( ".." ) . locator ( ".." ) ;
74+ // Historical Metrics section (recent runs) - using role-based selector
75+ this . historicalMetricsSection = page . getByRole ( "heading" , { name : "History" } ) . locator ( ".." ) ;
7776 this . dagRunMetrics = page . getByRole ( "heading" , { name : / d a g r u n / i } ) . first ( ) ;
7877 this . taskInstanceMetrics = page . getByRole ( "heading" , { name : / t a s k i n s t a n c e / i } ) . first ( ) ;
7978 }
@@ -169,13 +168,14 @@ export class HomePage extends BasePage {
169168 */
170169 // eslint-disable-next-line @typescript-eslint/class-methods-use-this
171170 private async getStatsCardCount ( card : Locator ) : Promise < number > {
172- try {
173- const badgeText = await card . locator ( "span" ) . first ( ) . textContent ( ) ;
174- const match = badgeText ?. match ( / \d + / ) ;
171+ await card . waitFor ( { state : "visible" } ) ; // Fail fast if card doesn't exist
172+ const badgeText = await card . locator ( "span" ) . first ( ) . textContent ( ) ;
173+ const match = badgeText ?. match ( / \d + / ) ;
175174
176- return match ? parseInt ( match [ 0 ] , 10 ) : 0 ;
177- } catch {
178- return 0 ;
175+ if ( ! match ) {
176+ throw new Error ( "Could not find count in stats card" ) ;
179177 }
178+
179+ return parseInt ( match [ 0 ] , 10 ) ;
180180 }
181181}
0 commit comments