From 6a18d4ce0fa938651c6ac564442a8b3fbd6f0f2b Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 11 Mar 2026 16:25:34 +0100 Subject: [PATCH] refactor(clickTtPlayerRegistrationService): enhance search form handling and error reporting - Updated the _fillSearchForm method to include trace logging and improved error handling for missing search forms, ensuring better feedback during the registration process. - Enhanced the _openApplicationEntry method to streamline application entry checks and improve error messaging for missing elements, contributing to a more robust registration flow. --- .../clickTtPlayerRegistrationService.js | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/backend/services/clickTtPlayerRegistrationService.js b/backend/services/clickTtPlayerRegistrationService.js index 763171a0..f2b24273 100644 --- a/backend/services/clickTtPlayerRegistrationService.js +++ b/backend/services/clickTtPlayerRegistrationService.js @@ -102,7 +102,7 @@ class ClickTtPlayerRegistrationService { await this._openAuthenticatedClickTt(page, { username, password, trace }); await this._selectClubContext(page, associationMemberNumber, trace); await this._openApplicationEntry(page, trace); - await this._fillSearchForm(page, memberJson); + await this._fillSearchForm(page, memberJson, trace); await this._clickByText(page, 'Personen suchen', trace); await page.waitForLoadState('domcontentloaded'); @@ -318,6 +318,10 @@ class ClickTtPlayerRegistrationService { async _openApplicationEntry(page, trace) { await this._dismissConsentOverlays(page, trace); + if (await page.locator('form.search-query').count()) { + return true; + } + const labels = [ 'Spielberechtigungen beantragen', 'Spielberechtigungen' @@ -326,11 +330,28 @@ class ClickTtPlayerRegistrationService { for (const label of labels) { if (await this._hasTextTarget(page, label)) { await this._clickByText(page, label, trace); - return true; + await page.waitForLoadState('domcontentloaded'); + await this._dismissConsentOverlays(page, trace); + break; } } - throw new HttpError('Click-TT-Element nicht gefunden: Spielberechtigungen', 500); + if (await page.locator('form.search-query').count()) { + return true; + } + + if (await this._hasTextTarget(page, 'Spielberechtigungen beantragen...')) { + await this._clickByText(page, 'Spielberechtigungen beantragen...', trace); + await page.waitForLoadState('domcontentloaded'); + await this._dismissConsentOverlays(page, trace); + return true; + } + + if (await page.locator('form.search-query').count()) { + return true; + } + + throw new HttpError('Click-TT-Element nicht gefunden: Spielberechtigungen / Spielberechtigungen beantragen...', 500); } async _selectClubContext(page, associationMemberNumber, trace) { @@ -356,13 +377,17 @@ class ClickTtPlayerRegistrationService { return false; } - async _fillSearchForm(page, member) { - await this._fillFirstAvailable(page, [ - 'input[name*=".1"]', - 'input[type="text"]' - ], member.lastName); - await this._fillNthTextInput(page, 1, member.firstName); - await this._fillNthTextInput(page, 2, formatGermanDate(member.birthDate)); + async _fillSearchForm(page, member, trace) { + const searchForm = page.locator('form.search-query').first(); + if (!(await searchForm.count())) { + throw new HttpError('Click-TT-Suchformular für Spielberechtigungen nicht gefunden', 500); + } + + this._trace(trace, 'step', { name: 'fill-search-form' }); + + await searchForm.locator('input[name$=".1"]').first().fill(member.lastName); + await searchForm.locator('input[name$=".3"]').first().fill(member.firstName); + await searchForm.locator('input[name$=".5"]').first().fill(formatGermanDate(member.birthDate)); } async _fillApplicationForm(page, member, email) {