Repository navigation
[java] fix logging in Selenium own tests - #16933
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||
1. Replace ConsoleHandlers by RecordingHandler before each test 2. Restore original ConsoleHandlers after each test 3. For failed tests - write down ALL logs 4. For succeeded tests - write down WARN and ERROR logs (they might be also useful)
58add2d to
4780364
Compare
User description
🔗 Related Issues
Fixes #16932
💥 What does this PR do?
This PR fixes
SeleniumExtension, so that Selenium logs are written again when running Selenium own tests.🔧 Implementation Notes
Now
SeleniumExtensionworks as follows:🔄 Types of changes
PR Type
Bug fix
Description
Fix logging capture in Selenium tests by refactoring
CaptureLoggingRuleReplace console handlers with recording handler before each test
Restore original handlers after each test completion
Write all logs for failed tests, warn/error logs for passed tests
Diagram Walkthrough
flowchart LR A["Test Execution"] -->|beforeEach| B["Start Log Capture"] B -->|Remove ConsoleHandlers| C["Add RecordingHandler"] C -->|Test Runs| D["Logs Recorded"] D -->|afterEach| E["End Log Capture"] E -->|Check Test Status| F{Test Failed?} F -->|Yes| G["Write ALL Logs"] F -->|No| H["Write WARN/ERROR Logs"] G -->|Restore Handlers| I["Original Handlers"] H -->|Restore Handlers| IFile Walkthrough
CaptureLoggingRule.java
Refactor logging capture with selective level-based outputjava/test/org/openqa/selenium/testing/CaptureLoggingRule.java
startLogCapture()method for lifecyclemanagement
Levelparameter towriteCapturedLogs()andendLogCapture()forselective logging
RecordingHandlernow stores original handlers to restore them aftertest
handlers()helper method to filter handlers by typewrite()method to filter logs by level before outputSeleniumExtension.java
Integrate selective log capture based on test outcomejava/test/org/openqa/selenium/testing/SeleniumExtension.java
captureLoggingRuleas instance field instead of inconstructor
startLogCapture()inbeforeEach()to capture logs before testexecution
afterEach()to determine log level based on test failurestatus
endLogCapture()-Level.ALLfor failedtests,
Level.WARNINGfor passed testswriteCapturedLogs()call fromtestFailed()methodJupiterTestBase.java
Make SeleniumExtension field finaljava/test/org/openqa/selenium/testing/JupiterTestBase.java
seleniumExtensionfieldfinalfor immutability@RegisterExtensionannotation placement