diff --git a/src/kleinanzeigen_bot/__init__.py b/src/kleinanzeigen_bot/__init__.py index b116bdc..5099c55 100644 --- a/src/kleinanzeigen_bot/__init__.py +++ b/src/kleinanzeigen_bot/__init__.py @@ -540,11 +540,18 @@ class KleinanzeigenBot(WebScrapingMixin): async def is_logged_in(self) -> bool: try: + # Try to find the standard element first user_info = await self.web_text(By.CLASS_NAME, "mr-medium") if self.config["login"]["username"].lower() in user_info.lower(): return True except TimeoutError: - return False + try: + # If standard element not found, try the alternative + user_info = await self.web_text(By.ID, "user-email") + if self.config["login"]["username"].lower() in user_info.lower(): + return True + except TimeoutError: + return False return False async def delete_ads(self, ad_cfgs:list[tuple[str, dict[str, Any], dict[str, Any]]]) -> None: diff --git a/tests/unit/test_extract.py b/tests/unit/test_extract.py index b382de5..272dc72 100644 --- a/tests/unit/test_extract.py +++ b/tests/unit/test_extract.py @@ -151,7 +151,7 @@ class TestAdExtractorShipping: @pytest.mark.asyncio # pylint: disable=protected-access - async def test_extract_shipping_info_with_all_matching_options(self, test_extractor: AdExtractor) -> None: + async def test_extract_shipping_info_with_all_matching_options(self, test_extractor:AdExtractor) -> None: """Test shipping info extraction with all matching options enabled.""" shipping_response = { "content": json.dumps({ @@ -185,7 +185,7 @@ class TestAdExtractorShipping: @pytest.mark.asyncio # pylint: disable=protected-access - async def test_extract_shipping_info_with_excluded_options(self, test_extractor: AdExtractor) -> None: + async def test_extract_shipping_info_with_excluded_options(self, test_extractor:AdExtractor) -> None: """Test shipping info extraction with excluded options.""" shipping_response = { "content": json.dumps({ @@ -222,7 +222,7 @@ class TestAdExtractorShipping: @pytest.mark.asyncio # pylint: disable=protected-access - async def test_extract_shipping_info_with_excluded_matching_option(self, test_extractor: AdExtractor) -> None: + async def test_extract_shipping_info_with_excluded_matching_option(self, test_extractor:AdExtractor) -> None: """Test shipping info extraction when the matching option is excluded.""" shipping_response = { "content": json.dumps({ diff --git a/tests/unit/test_init.py b/tests/unit/test_init.py index 3d2e5d9..6443384 100644 --- a/tests/unit/test_init.py +++ b/tests/unit/test_init.py @@ -324,6 +324,15 @@ class TestKleinanzeigenBotAuthentication: with patch.object(configured_bot, "web_text", return_value = "Welcome testuser"): assert await configured_bot.is_logged_in() is True + @pytest.mark.asyncio + async def test_is_logged_in_returns_true_with_alternative_element(self, configured_bot:KleinanzeigenBot) -> None: + """Verify that login check returns true when logged in with alternative element.""" + with patch.object(configured_bot, "web_text", side_effect = [ + TimeoutError(), # First try with mr-medium fails + "angemeldet als: testuser" # Second try with user-email succeeds + ]): + assert await configured_bot.is_logged_in() is True + @pytest.mark.asyncio async def test_is_logged_in_returns_false_when_not_logged_in(self, configured_bot:KleinanzeigenBot) -> None: """Verify that login check returns false when not logged in."""