Which of the following is the most common cause of flaky automated tests that sometimes pass and sometimes fail without code changes?
Think about what can cause unpredictable delays or failures outside the test code.
Tests that rely on external systems or network calls can fail unpredictably if those systems are slow or down, causing flaky tests.
You want to verify that a loading spinner disappears after a page finishes loading in an automated UI test. Which assertion best checks this?
The spinner should not be visible after loading completes.
Checking that the spinner element is not displayed confirms it disappeared.
Given this test code snippet, what is the most likely cause of intermittent failure?
button.click() assert message.text == 'Success'
Think about what happens immediately after clicking a button in UI tests.
The test fails intermittently because it asserts the message text before the UI updates. Adding a wait or retry fixes this.
Which approach is best to maintain test data for automated tests to reduce maintenance effort?
Think about how to avoid changing many test scripts when data changes.
Externalizing test data allows easy updates without modifying test code, reducing maintenance.
What is the output of this Python test retry code when the flaky_function fails the first time and passes the second time?
def flaky_function(): flaky_function.counter += 1 if flaky_function.counter < 2: raise Exception('Fail') return 'Pass' flaky_function.counter = 0 for attempt in range(3): try: result = flaky_function() print(f'Attempt {attempt+1}: {result}') break except Exception as e: print(f'Attempt {attempt+1}: {e}') else: print('All attempts failed')
Count how many times flaky_function raises an exception before returning 'Pass'.
The function fails once, then passes on the second call, so the loop prints failure then success and stops.