Skip to content

QA-SE-001 — Hard sleep before element lookup (Java, missing WebDriverWait) ​

← Back to the rule catalog

Generated from the rule registry. Get the same detail from the CLI with mjolnir explain QA-SE-001.

FieldValue
Severitywarning
Confidencemedium
Tierquarantine
Measured FP rate0% (n=10)
Evidence levelE2
QA impactFlaky-test risk (FLAKY-RISK)
False-positive risk (author estimate)medium
Autofix availableno
Languagesjava
Frameworksselenium
Detection strategyLEXICAL (sequence shape: Thread.sleep followed by a findElement/interaction call within 3 lines (code-only view))
Introduced inv0.6.0

Why this fails in production ​

A Selenium Thread.sleep before findElement encodes a guess about the app's timing: the explicit wait it replaces polls the DOM until the element is interactive, while the sleep waits a constant and then proceeds blindly. Under load the element appears after the sleep ends and NoSuchElementException fails the run (flaky); on a fast run the sleep is pure dead time charged to every execution (slow). Selenium's implicit-wait setting cannot rescue this shape — implicitlyWait only applies to the lookup itself, not to the sleep before it.

What gets flagged (real detector output) ​

Hard sleep before an element lookup (sleep at line 8) — the explicit-wait substitute (QA-SE-001).

Example from this rule's own must-fire fixture: tests/fixtures/QA-SE-001/must-fire/InventoryTest.java

The fix ​

Replace the sleep with an explicit wait: Java new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(...)); C# new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(...); Python WebDriverWait(driver, 10).until(EC.visibility_of_element_located(...)).

Confirmed NOT to fire on the corresponding clean pattern ​

Verified against tests/fixtures/QA-SE-001/must-not-fire/InventoryTest.java — a legitimate, similar-looking pattern this rule correctly leaves alone.

Corpus-measured false-positive risk ​

Real occurrence counts from npm run corpus:audit against actively-maintained OSS repos — reproduce yourself, don't just trust this table (see the false-positive audit):

RepoOccurrences
positive-fixtures1

Released under the MIT License.