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?
Think about how doing many things at once affects total time.
Parallel execution allows multiple tests to run simultaneously, reducing the total time needed to complete all tests. This speeds up feedback in CI pipelines.
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?
Think about thread safety when sharing browser instances.
WebDriver instances are not thread-safe. Sharing one instance across threads causes errors or unpredictable behavior.
In parallel Selenium tests running on multiple browsers, which locator strategy is best to avoid flaky tests caused by dynamic page changes?
Think about stability and uniqueness of locators across test runs.
Unique IDs or dedicated data-test attributes provide stable, fast, and reliable locators that reduce flakiness in parallel tests.
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?
results = [True, True, True, True, True]
Check how to verify all items in a list are True.
all(results) returns True only if every item in the list is True. This correctly asserts all tests passed.
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?
Check pytest-xdist documentation for the parallel option syntax.
The -n option followed by a number specifies the number of parallel workers in pytest-xdist.