Bird
Raised Fist0
Selenium Pythontesting~20 mins

Logging setup in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Logging Setup Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Selenium Python logging setup?
Given the following Python code snippet configuring logging for Selenium, what will be printed to the console?
Selenium Python
import logging
from selenium import webdriver

logging.basicConfig(level=logging.INFO, format='%(levelname)s:%(message)s')
logger = logging.getLogger('selenium.webdriver.remote.remote_connection')

logger.info('Starting WebDriver')
driver = webdriver.Firefox()
logger.info('WebDriver started')
driver.quit()
ANo output printed
B
Starting WebDriver
WebDriver started
C
DEBUG:Starting WebDriver
DEBUG:WebDriver started
D
INFO:Starting WebDriver
INFO:WebDriver started
Attempts:
2 left
💡 Hint
Check the logging level and format specified in basicConfig.
❓ Configuration
intermediate
1:30remaining
Which logging configuration disables Selenium's DEBUG logs?
You want to suppress DEBUG logs from Selenium WebDriver but keep INFO and above logs visible. Which logging configuration achieves this?
Alogging.basicConfig(level=logging.WARNING)
Blogging.basicConfig(level=logging.INFO)
Clogging.basicConfig(level=logging.DEBUG)
Dlogging.basicConfig(level=logging.ERROR)
Attempts:
2 left
💡 Hint
DEBUG logs are lower than INFO level.
❓ Troubleshoot
advanced
2:00remaining
Why does this Selenium Python logging code not print any logs?
Consider this code snippet: import logging logger = logging.getLogger('selenium.webdriver.remote.remote_connection') logger.info('Test log message') Why does it not print anything to the console?
ANo logging configuration is set, so default level WARNING hides INFO messages
BThe logger name is incorrect, so messages are discarded
CThe info method is misspelled, causing no output
DThe logger is disabled by default in Selenium
Attempts:
2 left
💡 Hint
Default logging level is WARNING if not configured.
🔀 Workflow
advanced
2:30remaining
What is the correct order to enable file logging for Selenium Python logs?
Arrange these steps in the correct order to log Selenium WebDriver messages to a file named 'selenium.log' with INFO level.
A1,4,2,3
B1,2,4,3
C4,1,2,3
D2,1,4,3
Attempts:
2 left
💡 Hint
You must create the handler before setting formatter and level, then add it to logger.
✅ Best Practice
expert
3:00remaining
Which practice is best for managing Selenium Python logs in a CI/CD pipeline?
In a CI/CD environment, you want to capture Selenium WebDriver logs efficiently without cluttering the console. Which approach is best?
AUse print statements instead of logging for simplicity
BDisable all logging to avoid slowing down tests
CConfigure logging to write to a rotating file handler and only show warnings/errors on console
DPrint all logs to console with DEBUG level for full detail
Attempts:
2 left
💡 Hint
Consider log size and readability in automated environments.

Practice

(1/5)
1. What is the main purpose of setting up logging in Selenium Python tests?
easy
A. To record important events and errors during test execution
B. To speed up the test execution time
C. To automatically fix errors in the test code
D. To generate HTML reports of test results

Solution

  1. Step 1: Understand logging purpose

    Logging is used to keep track of events and errors that happen during tests.
  2. Step 2: Compare options

    Only recording events and errors matches logging's main role; speeding up or fixing code is unrelated.
  3. Final Answer:

    To record important events and errors during test execution -> Option A
  4. Quick Check:

    Logging = Record events/errors [OK]
Hint: Logging records events and errors, not speeds or fixes [OK]
Common Mistakes:
  • Thinking logging speeds up tests
  • Confusing logging with test fixing tools
  • Assuming logging creates reports automatically
2. Which of the following is the correct way to set the logging level to DEBUG in Selenium Python?
easy
A. logging.config(level='DEBUG')
B. logging.setLevel(DEBUG)
C. logging.basicConfig(level=logging.DEBUG)
D. logging.start(level=logging.DEBUG)

Solution

  1. Step 1: Recall logging setup syntax

    Use logging.basicConfig() with level=logging.DEBUG to set debug level.
  2. Step 2: Validate options

    Only logging.basicConfig(level=logging.DEBUG) uses correct function and syntax; others are invalid or incorrect method calls.
  3. Final Answer:

    logging.basicConfig(level=logging.DEBUG) -> Option C
  4. Quick Check:

    basicConfig + level=logging.DEBUG = Correct [OK]
Hint: Use logging.basicConfig(level=logging.DEBUG) to set debug level [OK]
Common Mistakes:
  • Using logging.setLevel instead of basicConfig
  • Passing level as string without logging prefix
  • Calling non-existent logging.start() method
3. What will be the output when running this code snippet?
import logging
logging.basicConfig(level=logging.INFO)
logging.debug('Debug message')
logging.info('Info message')
medium
A. No output
B. Debug message\nInfo message
C. Debug message
D. Info message

Solution

  1. Step 1: Understand logging level effect

    Setting level to INFO means messages below INFO (like DEBUG) are ignored.
  2. Step 2: Check which messages print

    DEBUG message is ignored; INFO message is printed.
  3. Final Answer:

    Info message -> Option D
  4. Quick Check:

    Level INFO hides DEBUG, shows INFO [OK]
Hint: Messages below set level do not appear in output [OK]
Common Mistakes:
  • Expecting DEBUG messages to show at INFO level
  • Confusing logging levels order
  • Assuming all messages print regardless of level
4. Identify the error in this logging setup code:
import logging
logging.basicConfig(level='DEBUG')
logging.debug('Test message')
medium
A. logging.debug() cannot be called before configuring logging
B. The level argument should be an integer, not a string
C. logging.basicConfig() requires a filename argument
D. There is no error; the code runs correctly

Solution

  1. Step 1: Check logging.basicConfig level argument type

    The level argument must be a logging level constant like logging.DEBUG, not a string.
  2. Step 2: Validate other options

    logging.debug() can be called after basicConfig; filename is optional; code errors due to string level.
  3. Final Answer:

    The level argument should be an integer, not a string -> Option B
  4. Quick Check:

    Level must be logging.DEBUG, not 'DEBUG' string [OK]
Hint: Use logging.DEBUG constant, not 'DEBUG' string for level [OK]
Common Mistakes:
  • Passing level as string instead of logging constant
  • Thinking filename is mandatory in basicConfig
  • Calling logging.debug before configuration causes error
5. You want to log Selenium test events to a file named test.log with timestamps and message levels. Which code snippet correctly sets this up?
hard
A. logging.basicConfig(filename='test.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
B. logging.basicConfig(file='test.log', level='INFO', format='%(time)s - %(level)s - %(msg)s')
C. logging.setup(filename='test.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
D. logging.basicConfig(filename='test.log', level=logging.DEBUG, format='%(message)s')

Solution

  1. Step 1: Identify correct parameters for file logging

    Use filename='test.log', level=logging.INFO, and correct format string with asctime and levelname.
  2. Step 2: Check each option for correctness

    logging.basicConfig(filename='test.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') uses correct parameter names and format; A uses wrong keys and strings; C uses non-existent logging.setup; D misses timestamps and uses DEBUG level.
  3. Final Answer:

    logging.basicConfig(filename='test.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') -> Option A
  4. Quick Check:

    filename + level=logging.INFO + correct format = logging.basicConfig(filename='test.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') [OK]
Hint: Use filename, level=logging.INFO, and format with %(asctime)s [OK]
Common Mistakes:
  • Using wrong parameter names like file instead of filename
  • Passing level as string instead of logging constant
  • Missing timestamp in format string
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard