Automation Testing · Evolution
React JS vs Old Tools: What Changed for QA Testers
Quick summary — React vs Old Tools
The core difference is the DOM.
Old websites loaded new HTML for every click. React apps update the Virtual DOM without reloading.
For QA testers, this means traditional wait strategies (like Thread.sleep()) fail, and XPaths break constantly.
Here is what changed:
- No Page Reloads: You can't rely on
document.readyStateto know when a page is ready. - Dynamic Elements: React generates random IDs and classes (e.g.,
css-1a2b3c). You must use semantic locators ordata-testid. - Wait Strategies: You must use smart waits (e.g.,
waitForElementToBeVisible) instead of fixed sleeps.
SECTION 01What is React JS?
React is a JavaScript library built by Facebook for creating user interfaces. It's the most popular frontend library in the world.
Instead of building the UI with static HTML, React builds a "Virtual DOM" — a lightweight copy of the UI. When state changes, React updates only the parts of the screen that need to change.
SECTION 02The Old Way (Static HTML)
In the old days, when you clicked a link, the server sent a whole new HTML page. The browser refreshed. Your script just had to wait for the page to load.
driver.get("https://example.com");
driver.findElement(By.id("login")).click();
// Page reloads
driver.findElement(By.id("dashboard")).click();
• The page reloads after click.
• The DOM is completely new.
• Elements are predictable.
SECTION 03The React Way (Virtual DOM)
In React, there is no page reload. The URL changes, but the page doesn't. React efficiently updates the DOM. Your script can't just wait for a page load.
driver.get("https://example.com");
driver.findElement(By.id("login")).click();
// The page does NOT reload. The dashboard appears dynamically.
// This will fail if the element is not ready yet.
driver.findElement(By.id("dashboard")).click(); // Fails!
cy.visit("https://example.com");
cy.get('[data-testid=login]').click();
// Automatically waits for dashboard to appear.
cy.get('[data-testid=dashboard]').click();
SECTION 04Key Challenges for QA Testers
| Challenge | Why It Happens | The Fix |
|---|---|---|
| Flaky XPaths | React generates dynamic classes (e.g., .sc-xyz-123). | Ask devs for data-testid attributes. |
| Stale Elements | React re-renders components, replacing old DOM nodes. | Re-find elements using smart locators. |
| No Page Load | No reload event to wait for. | Use explicit waits (Wait for element to be visible). |
SECTION 05How to Test React Apps
To test modern web apps, you need to adopt modern testing strategies:
- Use Data-Test-IDs: Ask developers to add
data-testid="login-button"to elements. These don't change with styling. - Use Explicit Waits: Instead of
Thread.sleep(3000), useawait page.waitForSelector('.dashboard'). - Use Modern Frameworks: Tools like Cypress and Playwright are built for React. They auto-wait for elements to appear.
SECTION 06Checklist for Testing React
Strategy:
☐ Avoid brittle XPaths.
☐ Request data-testid attributes.
☐ Use explicit waits.
☐ Test error boundaries.
Tools:
☐ Learn Cypress.
☐ Learn Playwright.
☐ Learn React Testing Library (Jest).
☐ Learn mocking network requests.
Portfolio:
☐ Build a test suite for a React app.
☐ Use data-testid in your tests.
☐ Add CI/CD to your repo.
☐ Show reports in GitHub.
SECTION 07Interview Q&A — React Testing
Q1Why is testing React different from testing static HTML?
React uses a virtual DOM and doesn't reload pages. Elements change dynamically, so you need smart waits and robust selectors.
Q2What is data-testid?
An HTML attribute that developers add to elements specifically for testing. It doesn't change with styles and is stable.
Q3What is the difference between Cypress and Selenium for React?
Cypress runs directly in the browser and auto-waits for elements. Selenium requires explicit waits and has more issues with React's async nature.
Q4How do you handle stale elements in React?
Re-query the element each time it's needed, or use a framework like Playwright that automatically handles stale elements.
Q5Do I need to know JavaScript to test React?
Yes, basic JavaScript is required, especially for modern tools like Cypress and Playwright.
SECTION 08Test yourself — React Testing Quiz
Five questions. No sign-up.
0 / 5Pick an answer to see why it is right or wrong.
SECTION 09Frequently asked questions
What is the biggest challenge testing React apps?
Handling dynamic elements and managing waits. Static XPaths fail because the DOM updates continuously.
Is Selenium good for React testing?
Selenium can work, but it requires complex explicit waits. Tools like Cypress and Playwright are much better suited.
Should I use React Testing Library?
RTL is for unit and component testing, not end-to-end testing. Cypress/Playwright are for E2E.
How do I convince my devs to add data-testid?
Show them how brittle XPaths cause flaky tests and slow down releases. Data-testid is a win for everyone.
What is the learning curve for Cypress?
Very small. If you know JavaScript, you can write basic Cypress tests in a day.
SECTION 10Related reads
Classroom & online · Noida
Stay ahead of the curve — learn React testing
Our Automation Testing Course now includes Cypress and Playwright for React, with 10+ live projects and mock interviews.
₹18,500 · full programme- Learn Cypress & Playwright
- Portfolio & GitHub review
- Mock interviews
- Weekday & weekend batches




