Bird
Raised Fist0
Selenium Pythontesting~20 mins

Parallel execution in CI in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Parallel Execution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why use parallel test execution in CI?

Imagine you have 100 automated UI tests. Running them one by one takes a long time. Why is running tests in parallel in a Continuous Integration (CI) environment beneficial?

AIt makes tests run slower but more reliably.
BIt ensures tests run in a specific order to avoid conflicts.
CIt reduces total test execution time by running multiple tests at the same time.
DIt disables flaky tests automatically during execution.
Attempts:
2 left
💡 Hint

Think about how doing many things at once affects total time.

❓ Predict Output
intermediate
2:00remaining
Output of parallel test run with shared state

Consider this simplified Python Selenium test snippet run in parallel threads sharing the same WebDriver instance:

from selenium import webdriver
from threading import Thread

shared_driver = webdriver.Chrome()
results = []

def test():
    shared_driver.get('https://example.com')
    results.append(shared_driver.title)

threads = [Thread(target=test) for _ in range(2)]
for t in threads:
    t.start()
for t in threads:
    t.join()
print(results)

What is the most likely outcome?

A['Example Domain', 'Example Domain'] - Both threads succeed using shared driver.
BRuntimeError or WebDriverException due to concurrent access to shared driver.
C[] - No titles collected because threads run before page loads.
D['Example Domain'] - Only one thread appends result, other fails silently.
Attempts:
2 left
💡 Hint

Think about thread safety when sharing browser instances.

❓ locator
advanced
1:30remaining
Best locator strategy for parallel Selenium tests

In parallel Selenium tests running on multiple browsers, which locator strategy is best to avoid flaky tests caused by dynamic page changes?

AUsing unique IDs or data-test attributes for elements.
BUsing absolute XPath expressions starting from the root element.
CUsing CSS selectors with nth-child to locate elements by position.
DUsing text-based XPath queries that match visible text.
Attempts:
2 left
💡 Hint

Think about stability and uniqueness of locators across test runs.

❓ assertion
advanced
1:30remaining
Correct assertion for parallel test results aggregation

You run 5 parallel Selenium tests that each return a boolean pass/fail result. You collect results in a list results. Which assertion correctly verifies all tests passed?

Selenium Python
results = [True, True, True, True, True]
Aassert all(results) == True
Bassert results is True
Cassert any(results) == True
Dassert results == True
Attempts:
2 left
💡 Hint

Check how to verify all items in a list are True.

❓ framework
expert
1:30remaining
Configuring pytest-xdist for parallel Selenium tests in CI

You want to run Selenium tests in parallel on 4 workers using pytest-xdist in a CI pipeline. Which pytest command correctly runs tests in parallel with 4 workers?

Apytest -w 4
Bpytest --workers=4
Cpytest --parallel=4
Dpytest -n 4
Attempts:
2 left
💡 Hint

Check pytest-xdist documentation for the parallel option syntax.

Practice

(1/5)
1. What is the main benefit of running Selenium tests in parallel during Continuous Integration (CI)?
easy
A. It reduces the total test execution time by running tests simultaneously.
B. It makes tests run slower but more accurately.
C. It ensures tests run only on one browser at a time.
D. It disables all tests except one to save resources.

Solution

  1. Step 1: Understand parallel execution in CI

    Parallel execution means running multiple tests at the same time instead of one after another.
  2. Step 2: Identify the benefit of parallel execution

    Running tests simultaneously saves time by reducing total test duration.
  3. Final Answer:

    It reduces the total test execution time by running tests simultaneously. -> Option A
  4. Quick Check:

    Parallel execution = faster testing [OK]
Hint: Parallel means running tests at the same time [OK]
Common Mistakes:
  • Thinking parallel slows tests down
  • Believing tests run only on one browser
  • Confusing parallel with disabling tests
2. Which Python module is commonly used to run Selenium tests in parallel within a CI pipeline?
easy
A. ThreadPoolExecutor
B. unittest
C. multiprocessing
D. time

Solution

  1. Step 1: Identify Python modules for parallel execution

    Python offers several modules, but ThreadPoolExecutor from concurrent.futures is popular for parallel threads.
  2. Step 2: Match module to Selenium parallel testing

    ThreadPoolExecutor allows running multiple Selenium tests in parallel threads efficiently.
  3. Final Answer:

    ThreadPoolExecutor -> Option A
  4. Quick Check:

    ThreadPoolExecutor = parallel threads [OK]
Hint: ThreadPoolExecutor is for parallel threads in Python [OK]
Common Mistakes:
  • Choosing multiprocessing which uses processes, not threads
  • Selecting unittest which is a test framework, not parallel executor
  • Picking time which is for delays, not parallelism
3. Given the code snippet below, what will be the output?
from concurrent.futures import ThreadPoolExecutor
import time

def test_func(name):
    time.sleep(1)
    return f"Test {name} done"

with ThreadPoolExecutor(max_workers=3) as executor:
    results = list(executor.map(test_func, ['A', 'B', 'C', 'D']))
print(results)
medium
A. Error due to max_workers less than tasks
B. ['Test A done', 'Test B done', 'Test C done']
C. ['Test A done', 'Test B done', 'Test C done', 'Test D done']
D. ['Test D done']

Solution

  1. Step 1: Understand ThreadPoolExecutor with max_workers=3

    It runs up to 3 threads at once, but can handle more tasks by queuing them.
  2. Step 2: Analyze executor.map behavior

    executor.map runs test_func on all 4 inputs and returns results in order after all finish.
  3. Final Answer:

    ['Test A done', 'Test B done', 'Test C done', 'Test D done'] -> Option C
  4. Quick Check:

    All tasks run, results list includes all [OK]
Hint: ThreadPoolExecutor queues extra tasks beyond max_workers [OK]
Common Mistakes:
  • Assuming only 3 results because max_workers=3
  • Expecting error due to more tasks than workers
  • Thinking results order changes
4. You wrote this code to run Selenium tests in parallel but get an error: RuntimeError: cannot schedule new futures after shutdown. What is the likely cause?
from concurrent.futures import ThreadPoolExecutor
executor = ThreadPoolExecutor(max_workers=2)
executor.shutdown()
executor.submit(test_function)
medium
A. ThreadPoolExecutor requires a context manager to work.
B. max_workers=2 is too low for submitting tasks.
C. test_function is not defined before submit call.
D. Calling submit after shutdown closes the executor, so no new tasks allowed.

Solution

  1. Step 1: Understand executor.shutdown() effect

    shutdown() stops the executor from accepting new tasks and cleans up threads.
  2. Step 2: Analyze submit call after shutdown

    Calling submit after shutdown causes RuntimeError because executor is closed.
  3. Final Answer:

    Calling submit after shutdown closes the executor, so no new tasks allowed. -> Option D
  4. Quick Check:

    submit after shutdown = error [OK]
Hint: Don't submit tasks after executor.shutdown() [OK]
Common Mistakes:
  • Thinking max_workers causes this error
  • Assuming test_function undefined causes this error
  • Believing context manager is required
5. You want to run Selenium tests in parallel on Chrome and Firefox browsers in your CI pipeline using Python. Which approach correctly sets up parallel execution for both browsers?
hard
A. Run tests sequentially by switching browser drivers inside a single test function.
B. Use ThreadPoolExecutor to run a test function twice, each time initializing a different browser driver inside the function.
C. Use a single WebDriver instance shared by all tests to save memory.
D. Run tests in parallel but initialize browsers outside the test functions to avoid overhead.

Solution

  1. Step 1: Understand parallel testing with multiple browsers

    Each test must create its own browser driver instance to avoid conflicts.
  2. Step 2: Use ThreadPoolExecutor to run tests in parallel

    Running test functions in parallel, each initializing its own browser, allows simultaneous testing on Chrome and Firefox.
  3. Final Answer:

    Use ThreadPoolExecutor to run a test function twice, each time initializing a different browser driver inside the function. -> Option B
  4. Quick Check:

    Separate drivers per thread = correct parallel setup [OK]
Hint: Initialize browser inside each parallel test function [OK]
Common Mistakes:
  • Sharing one WebDriver instance across threads
  • Switching browsers sequentially defeats parallelism
  • Initializing browsers outside test functions causes conflicts
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