Back to All Scenarios
Scenario 80 of 100
API + Selenium
Advanced
Verifying Backend APIs Before UI Render Loads
π°οΈScenario Overview
Verifying Backend APIs Before UI Render Loads
Key Takeaways & Cheat Sheet
- βSend REST-Assured requests to verify server status before launch
- βConfirm backend data integrity prior to running slow UI tests
- βEnsure tests fail early on API issues, saving execution time
- βPerform fast, isolated validation of API response payloads
Short Direct Answer
To optimize execution, verify backend API health before launching slow UI browsers. Send a fast Rest-Assured HTTP request to confirm the API is responsive. If the API returns errors, fail the test run immediately, preventing wasted execution time on browser automation.
β οΈ Senior Warning (Red Flag)
Do not let your UI tests run when the backend APIs are down or returning 500 errors. The tests will fail slowly on locator timeouts, wasting valuable CI pipeline execution time.
π‘ STAR Deep Dive Explanation & Pro Tip
Failing early on API issues is an industry best practice that keeps reports clear, separating backend server downtime from UI automation bugs.
SeleniumAutomation.java
Selenium 4 + Javaimport io.restassured.RestAssured;
import org.testng.SkipException;
// β
Fast health check before UI execution
@BeforeClass
public void checkApiHealth() {
RestAssured.baseURI = "https://api.careerraah.com";
int statusCode = RestAssured.given()
.get("/health")
.getStatusCode();
if (statusCode != 200) {
// Skip entire test class early if service is unhealthy
throw new SkipException("Skipping UI tests; backend API is down. Code: " + statusCode);
}
System.out.println("Backend API is active. Launching UI tests...");
}