41. Noisy screenshot tests
Visual regression tests fail on most runs with tiny pixel differences in fonts, plus a changing date and a carousel. Developers now ignore the failures. What is the best fix?
- A.Raise the allowed pixel difference to 30% for all tests
- B.Delete all screenshot tests
- C.Run screenshots in one fixed environment (same container, browser and fonts), mask or freeze dynamic content, and disable animations
- D.Take screenshots only on developers' own laptops
Show answer
Answer: C. Run screenshots in one fixed environment (same container, browser and fonts), mask or freeze dynamic content, and disable animations
Font rendering differs between operating systems and GPUs, so baselines must come from the same environment, often a Docker image. Dynamic areas should be masked or given fixed data and clocks, and animations turned off. A huge threshold would hide real layout bugs.
42. When automation pays off
A regression set takes 4 hours to run by hand. Automating it takes 40 hours, and each automated run needs 1 hour of upkeep and analysis. After how many runs does automation start saving time?
- A.10 runs
- B.40 runs
- C.14 runs
- D.8 runs
Show answer
Answer: C. 14 runs
Each run saves 4 − 1 = 3 hours. 40 ÷ 3 ≈ 13.3, so it pays back on the 14th run. Ignoring upkeep (40 ÷ 4 = 10) overstates the benefit, a common mistake in automation business cases.
43. Element inside an iframe
In Selenium, a payment card field is inside an iframe, and findElement(By.id("card")) throws NoSuchElementException. What is needed?
- A.Switch to the frame first with driver.switchTo().frame(...), interact, then switch back with defaultContent()
- B.Use a longer implicit wait
- C.Use an absolute XPath from the top document
- D.Run the test in headless mode
Show answer
Answer: A. Switch to the frame first with driver.switchTo().frame(...), interact, then switch back with defaultContent()
Each iframe has its own document, so Selenium only searches the current browsing context. You must switch into the frame. Playwright handles this with page.frameLocator() or locator.contentFrame().
44. Waiting for network idle
A team waits for "networkidle" after every navigation. Tests are slow and still flaky on pages with analytics and polling. What is the better approach?
- A.Increase the networkidle timeout to 60 seconds
- B.Block all network requests
- C.Wait for the specific UI state the test needs, using web-first assertions on visible content
- D.Use page.waitForTimeout(5000) instead
Show answer
Answer: C. Wait for the specific UI state the test needs, using web-first assertions on visible content
Pages with polling, websockets or analytics may never be idle, and idle does not mean the right content is shown. Playwright's docs discourage networkidle for testing. Asserting on the content you care about is faster and more meaningful.
45. DRY or DAMP tests
A framework has helpers so abstract that a test reads: runScenario(config[7]). Reviewers cannot tell what it checks. What guideline applies?
- A.Tests should be as DRY as possible, even if unreadable
- B.Prefer DAMP (descriptive and meaningful phrases) in tests: some repetition is fine if each test clearly shows its setup, action and expected result
- C.Remove all helpers and copy code everywhere
- D.Move all assertions into the helpers
Show answer
Answer: B. Prefer DAMP (descriptive and meaningful phrases) in tests: some repetition is fine if each test clearly shows its setup, action and expected result
Tests are documentation and are read when they fail. Share mechanics (fixtures, page objects, builders) but keep the test-specific inputs and expectations visible in the test body.
46. Testing with generated inputs
A function splits a bill among N people in whole paise. Instead of a few hand-picked examples, you want to check that the shares always add up to the total for many random inputs. Which approach is this?
- A.Snapshot testing of the output for one large input
- B.Mutation testing of the function's source code
- C.Contract testing between the bill service and its users
- D.Property-based testing, for example Hypothesis or fast-check
Show answer
Answer: D. Property-based testing, for example Hypothesis or fast-check
Property-based tools generate many inputs, check that an invariant holds, and shrink any failure to a minimal example. They are good at finding edge cases, such as totals that do not divide evenly, that example-based tests miss.
47. Shuffling test order on purpose
Why might a team run tests in random order (for example with pytest-randomly or jest --randomize) in CI?
- A.To make the suite run faster by spreading slow tests evenly
- B.To expose hidden dependencies between tests, with a seed to replay
- C.To give every test in the suite an equal chance of being skipped
- D.To make results differ each time so flaky tests are hidden
Show answer
Answer: B. To expose hidden dependencies between tests, with a seed to replay
Tests that only pass in a fixed order secretly rely on state left by others. Randomising order flushes these out before they cause confusing failures in parallel runs. The seed is printed so the exact failing order can be replayed.
48. SQLite in tests, Postgres in production
Tests run against SQLite for speed while production uses PostgreSQL. Which bug is most likely to slip through?
- A.A type, constraint or collation rule that SQLite handles differently
- B.A typo in a local variable name inside the repository class
- C.A missing import of the database driver in the main application code
- D.A wrong HTTP status code returned by the API controller
Show answer
Answer: A. A type, constraint or collation rule that SQLite handles differently
SQLite has looser typing, different collation and date handling, and different locking and constraint behaviour. Code that relies on Postgres semantics can pass on SQLite and fail in production. Run at least the repository tests against the real engine, for example with Testcontainers.
49. A cache that remembers old tests
A singleton PriceCache is filled by one test with a ₹999 price. Another test later expects ₹1,099 from a stubbed service but gets ₹999. What is the best long-term fix?
- A.Order the tests so that the ₹1,099 test always runs first
- B.Inject the cache so each test gets a fresh one, or reset it in a fixture
- C.Add a sleep so the cache entry expires before the second test
- D.Mark the second test as flaky and allow two retries
Show answer
Answer: B. Inject the cache so each test gets a fresh one, or reset it in a fixture
Global or static state survives between tests and makes results depend on order and parallel scheduling. Injecting dependencies, or at least resetting shared state in setup, restores isolation. Ordering, sleeps and retries only hide the coupling.
50. A test that can never fail
Why does this test always pass, even when no "Overdue" invoice exists?
test('flags overdue invoices', () => {
const invoices = getInvoices()
invoices.filter((i) => i.status === 'Overdue').forEach((i) => {
expect(i.reminderSent).toBe(true)
})
})- A.If the filter returns no items, no assertion runs and the test passes
- B.forEach runs asynchronously, so Jest misses the assertions inside
- C.toBe(true) always passes when the property is undefined
- D.Jest skips tests that use filter() on arrays of objects
Show answer
Answer: A. If the filter returns no items, no assertion runs and the test passes
Assertions inside loops or callbacks pass vacuously when the loop runs zero times. Assert the precondition, for example expect(overdue.length).toBeGreaterThan(0), or use expect.assertions(n), so the test fails when the data it depends on is missing.
51. Checking structure, not pixels
Screenshot tests of a navigation menu break with every font or colour change, but the team mainly cares that the right links exist in the right order. Which check fits better?
- A.toHaveScreenshot() with a 50% pixel difference tolerance
- B.Asserting that the menu's innerHTML equals a saved string
- C.expect(locator).toMatchAriaSnapshot() comparing the accessibility tree
- D.Comparing the CSS class list of every link to a saved list
Show answer
Answer: C. expect(locator).toMatchAriaSnapshot() comparing the accessibility tree
An ARIA snapshot compares roles, names and structure in a YAML-like form, so styling changes do not break it but missing or reordered links do. Comparing raw HTML is brittle, and a huge pixel tolerance would hide real visual bugs too.
52. Paying one invoice in a table
In a table of invoices, each row has one button, "Pay", and rows = page.getByRole("row"). Which locator finds "Pay" only in the row whose invoice cell is exactly "INV-1043" (and not "INV-10431")?
- A.rows.filter({ has: page.getByRole('cell', { name: 'INV-1043', exact: true }) }).getByRole('button')
- B.rows.filter({ hasText: 'INV-1043' }).first().getByRole('button', { name: 'Pay', exact: true })
- C.page.getByText('INV-1043').locator('..').getByRole('button', { name: 'Pay' }).first()
- D.rows.getByRole('button', { name: 'Pay', exact: true }).nth(1043).filter({ hasText: 'Pay' })
Show answer
Answer: A. rows.filter({ has: page.getByRole('cell', { name: 'INV-1043', exact: true }) }).getByRole('button')
hasText matches substrings, so "INV-1043" would also match "INV-10431" and cause a strict mode error or the wrong click. filter({ has }) with an exact cell locator selects the right row precisely, and the chained button locator stays within that row.
53. Extra words in a table cell
A sortable column header shows "Amount", but allTextContents() returns "Amount sorted ascending" because of a <span style="display:none">. Which method returns only the rendered text?
- A.allTextContents()
- B.allInnerTexts()
- C.getAttribute('textContent')
- D.evaluate((el) => el.outerHTML)
Show answer
Answer: B. allInnerTexts()
textContent includes all text nodes, even hidden ones. innerText reflects rendered text and skips display:none content. Pick the one that matches what you mean to assert: what a user sees (innerText) or the raw DOM text.
54. Clicking through JavaScript
A tester "fixes" an intercepted click by using ((JavascriptExecutor) driver).executeScript("arguments[0].click()", button). Why can this be harmful?
- A.It clicks even when a real user could not, so it can hide a real bug
- B.JavaScript clicks are always slower than WebDriver clicks
- C.executeScript does not work on buttons, only on links
- D.It permanently disables the overlay for all other tests
Show answer
Answer: A. It clicks even when a real user could not, so it can hide a real bug
A JavaScript click skips visibility and hit-testing, so a button hidden under a modal or off-screen will still be "clicked". The test passes while users are blocked. Use it only for deliberate edge cases, after understanding why the real click failed.
55. Logging in on another domain in Cypress
The app redirects to an identity provider at login.idp.com for SSO. In Cypress, commands on that page fail. What is the supported way to interact with it?
- A.Set chromeWebSecurity to false and use cy.visit for every page
- B.Open the identity provider in a new tab with cy.window().open()
- C.Wrap those steps in cy.origin('https://login.idp.com', () => { ... })
- D.Use cy.wait(5000) so Cypress can switch to the other domain
Show answer
Answer: C. Wrap those steps in cy.origin('https://login.idp.com', () => { ... })
Because Cypress runs inside the browser alongside the app, cross-origin pages need cy.origin to run commands in that origin. Often a better choice is to log in programmatically (for example via cy.request to get tokens) and use cy.session, testing the SSO UI in only one test.
56. Finding an item in an infinite feed
A feed loads 20 more items each time you scroll to the bottom. A test must find a post created a week ago. Which approach is most robust?
- A.Scroll with an unbounded while loop until the post finally appears
- B.Scroll once and wait 30 seconds for all the posts to load
- C.Create the post in the test, or scroll in a bounded loop until found
- D.Zoom the browser to 10% so every post fits on the screen
Show answer
Answer: C. Create the post in the test, or scroll in a bounded loop until found
Tests should control their data: creating a fresh post means it appears at the top. If you must search, scroll with a limit on attempts and wait for new items after each scroll, so the test fails clearly instead of hanging when the item is missing.
57. getText() returns an empty string
A hidden <span> with display:none holds a tracking number. Selenium's getText() returns "". What explains this, and how do you read it?
- A.The element is stale; find it again and call getText() once more
- B.getText() fails on spans; use getTagName() to read the value
- C.Hidden text is encrypted; use executeScript to decrypt it
- D.getText() returns only visible text; read getDomProperty("textContent")
Show answer
Answer: D. getText() returns only visible text; read getDomProperty("textContent")
WebDriver getText() is defined as the rendered, visible text, so hidden elements give an empty string. textContent reads the raw DOM text. Ask whether the test should be reading hidden text at all, since users cannot see it.
58. Article text on a phone
On a 360 px wide phone, an article uses 13 px text with 8 px side margins to fit more words per line. What is the main problem and fix?
- A.Lines are too short; use 11 px text
- B.Margins are too wide; remove them
- C.Line height is too large; set it to 1.0
- D.Text is too small; use 16 px+ and wider margins
Show answer
Answer: D. Text is too small; use 16 px+ and wider margins
Small text strains eyes on phones and tiny margins make text crowd the edge. About 16 px or more body text with 16 px margins gives roughly 35–45 characters per line, which is comfortable on mobile.
59. Setting text for readers with dyslexia
A government portal wants body text that is easier for readers with dyslexia. Which change has the strongest support from guidance such as the British Dyslexia Association style guide?
- A.A special dyslexia font set in all caps
- B.Fully justified text in narrow columns
- C.Light grey text on pure white for softness
- D.Left-aligned, well-spaced text, no long italics
Show answer
Answer: D. Left-aligned, well-spaced text, no long italics
Guidance stresses layout: left-aligned text, line spacing around 1.5, avoiding long italic or underlined passages, and good but not glaring contrast. Evidence that special dyslexia fonts help is weak; spacing and setting matter more.
60. A sales cut-off problem
The year ends on 31 March. Goods were dispatched on 3 April, but the invoice was dated 30 March and recorded as a sale for the year. Control passes on dispatch. What is the effect, and which assertion is affected?
- A.Revenue understated; completeness
- B.No effect, because the invoice date decides the period
- C.Revenue and receivables overstated (and inventory understated); cut-off
- D.Expenses overstated; classification
Show answer
Answer: C. Revenue and receivables overstated (and inventory understated); cut-off
Control passed on 3 April, so the revenue belongs to the next year. Recording it on 30 March overstates revenue and receivables, and if inventory was removed from the books, understates inventory at year end. This is a cut-off error, and sales just before year end are a classic area for testing and for fraud risk.