Flaky Test

Random Element Ordering

List items are randomly shuffled on every page load, causing position-based assertions to fail intermittently.

Shuffled Item List

The five items below are displayed in a random order on each page load. A test asserting that the second item is "Beta" would only pass when the shuffle happens to place "Beta" in position 2.

Shuffled 1 time

Order Comparison

Compare the current shuffled order against the original order to see which positions match.

Original Order

Current Shuffled Order

Technical Details

// Original order (never changes)

// Current shuffled order (changes each load/reshuffle)

Why This Causes Flaky Tests

Tests that rely on element position (e.g., "the 2nd list item should contain 'Beta'") will fail whenever the shuffle produces a different order. With 5 items, there are 120 possible orderings, so any position-based assertion has only a 1-in-5 chance of being correct.

  • Items are shuffled using Fisher-Yates algorithm on each page load
  • A test asserting items[1].text === "Beta" passes only 20% of the time
  • Fix: Assert on content presence rather than position, or sort before asserting