26. How do you validate broken links using Selenium?
Answer:
- Collect all links using findElements(By.tagName("a")).
- Get href attribute.
- Send HTTP request with Java/HttpURLConnection.
- If response code >= 400 → Broken link.
List<WebElement> links = driver.findElements(By.tagName("a"));
}
In a banking web app, I validated all "Help" and "FAQ" links to ensure no broken references before go-live.
27. What automation framework have you worked on? Can you explain its architecture?
I worked on a Hybrid Selenium Framework (combination of Data-Driven + POM + TestNG).
📌 Components included:
- TestNG → Test execution & reports
- POM/Page Factory → Code reusability & readability
- Data Handling → Excel, JSON, Properties files
- Utilities → For waits, logging, screenshots
- Listeners → For capturing failures
- CI/CD → Integrated with Jenkins
In my telecom Salesforce project, we used this framework to automate order-to-billing workflows. The framework reduced execution time by 40% compared to manual regression.
Answer:
- Write test classes with @Test annotation.
- Use @BeforeMethod and @AfterMethod for setup/teardown.
- Run via TestNG XML file or JUnit runner.
Example (TestNG):
@Test
public void loginTest(){
driver.get("https://app.com");
Assert.assertEquals(driver.getTitle(), "Home");
}
Real-time Use:
We ran TestNG suites in Jenkins with parallel execution enabled, saving regression execution time.
29. What are the advantages of TestNG over JUnit in Selenium?
Answer:
- TestNG XML → Better test configuration & grouping.
- Parallel Execution supported.
- Flexible Annotations (before/after suite, groups).
- Inbuilt Reporting.
- Data Provider for parameterization.
In my project, I grouped smoke and regression tests in TestNG XML and executed them separately during releases.
Answer:
- TestNG default reports
- Extent Reports / Allure Reports (for rich HTML reports with screenshots)
- Jenkins plugin reports
Real-time Use:
I implemented Extent Reports in my framework. Each failed step captured a screenshot and was embedded in the HTML report for defect tracking.
Answer:
- Push code to GitHub.
- Configure Jenkins Job → pull code via Git.
- Add build step → mvn test or TestNG suite.
- Configure email/slack notification for test results.
Our nightly regression suite ran in Jenkins at 2 AM. In the morning, the team received a mail with pass/fail summary + report link.
32. How do you handle test data in your framework (Excel, JSON, DB, Properties file)?
Answer:
- Excel (Apache POI) → Large data sets.
- JSON → Structured test data.
- Properties File → Environment configs (URLs, credentials).
- Database Connection → Directly query DB for validation.
Real-time Example:
In a Salesforce integration project, customer data was stored in Excel. I used Apache POI to drive data-driven tests.
Answer:
- Data-Driven → Test data separated from scripts (Excel, CSV, DB).
- Keyword-Driven → Uses keywords (Login, Click, Verify) stored in Excel; scripts read and execute them.
- Hybrid → Combination of both + POM.
I implemented a Hybrid framework using POM + Data Driven + TestNG. It supported multiple environments and was scalable.
Answer:
- Create Utility classes for common methods like waits, dropdown selection, screenshots.
- Create Base class for driver setup & teardown.
- Store Locators in POM classes.
Example:
public class WaitUtils {
public static void waitForVisible(WebDriver driver, By locator) {
new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(locator));
}
}
Real-time Use:
This reduced code duplication by 30% in my regression suite.
35. How do you handle logging in Selenium? Have you used log4j or other tools?
Answer:
Yes, I implemented Log4j/SLF4J for logging.
- Info logs → Test steps
- Error logs → Failures
- Debug logs → For troubleshooting
Example:
private static Logger log = LogManager.getLogger(LoginTest.class);
log.info("Navigating to login page");
log.error("Login failed due to invalid credentials");
Real-time Use:
Logs helped developers reproduce failures quickly without running the script again.
Answer:
- TestNG → parallel="tests" or parallel="methods" in XML.
- Grid / Selenium Grid / Docker → Run tests across multiple machines/browsers.
- Cloud platforms → BrowserStack, SauceLabs.
Real-time Example:
I executed regression suite on BrowserStack across Chrome, Firefox, and Safari in parallel, which reduced test cycle time from 4 hours to 1.5 hours.
37. If your script is failing randomly, how will you debug and fix it?
Steps I follow:
- Check waits → Often caused by synchronization issues.
- Review locators → Might be dynamic or incorrect.
- heck test data → Data may have changed.
- Check environment → Sometimes staging/QA environments are unstable.
- Add logging & screenshots → To see exact failure point.
Real-time Example:
My checkout script in an e-commerce app failed randomly. I found that the “Place Order” button loaded late due to AJAX. Fixed it with Explicit Wait and it became stable.
38. How do you verify that an element is visible and clickable?
Answer:
- Use isDisplayed() to check visibility.
- Use ExpectedConditions.elementToBeClickable().
Example:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.id("submitBtn")));
Real-time Use:
In Salesforce, “Save” button was disabled until mandatory fields were filled. I used this check before clicking.
Answer:
Select dropdown = new Select(driver.findElement(By.id("country")));
dropdown.selectByVisibleText("India"); // Single-select
dropdown.selectByIndex(2); // Multi-select
Real-time Example:
In a telecom app, I automated country and plan selection dropdowns. For multi-select, I validated all selected options using getAllSelectedOptions().
Answer:
String tooltip = driver.findElement(By.id("help")).getAttribute("title");
If it’s a custom tooltip (hover), use Actions class.
Actions action = new Actions(driver);
action.moveToElement(element).perform();
Real-time Example:
I validated tooltip messages in Salesforce help icons using attribute extraction.
Answer:
((JavascriptExecutor)driver).executeScript("window.scrollBy(0,500)");
Or scroll to an element:((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", element);
Real-time Example:
In my project, error messages appeared at the bottom of the form. I scrolled into view before capturing screenshots.
42. How do you drag and drop an element?
Answer:
Use Actions class.
Actions action = new Actions(driver);
action.dragAndDrop(source, target).build().perform();
Real-time Example:
In a Kanban board application, I tested dragging tasks from “To Do” to “In Progress” column.
Answer:
- If it’s a text field → Directly sendKeys("2025-09-07").
- If it’s a UI date picker → Loop through months/days until desired date is found.
Example:
while(!driver.findElement(By.className("ui-datepicker-month")).getText().equals("September")) {
driver.findElement(By.xpath("//a[@title='Next']")).click();
}
driver.findElement(By.xpath("//a[text()='7']")).click();
Real-time Example:
In a booking app, I automated selecting a journey date 3 months ahead by navigating the calendar widget.
Answer:
Assert.assertEquals(driver.getTitle(), "Dashboard");
Assert.assertTrue(driver.getCurrentUrl().contains("dashboard"));
Real-time Example:
In Salesforce, after login, I validated that the title contained “Home | Salesforce” to confirm login success.
Answer:
- Locate element and get text → getText().
- Use assertion.
Example:
String msg = driver.findElement(By.id("successMsg")).getText();
Assert.assertEquals(msg, "Order placed successfully");
Real-time Example:
I validated success/error messages after order submission in a telecom application.
Answer:
- Run tests in parallel.
- Identify redundant test cases and remove duplicates.
- Use headless browsers for faster execution.
- Optimize locators & waits.
- Categorize tests (Smoke, Sanity, Regression).
Real-time Example:
Our regression suite initially took 6 hours. After parallelizing on Selenium Grid, execution time reduced to 2 hours.
-------------------------------------------------------------------------------------------------------------------
47. How do you handle test cases that fail only in CI but pass locally?
- Check browser/driver versions in CI vs local.
- Check browser/driver versions in CI vs local.
- Add waits – CI is slower due to shared resources.
- Check resolution settings – CI may run in headless or lower resolution.
- Review test data – Sometimes test data is missing in CI DB.
- Review logs & screenshots from CI run.
Real-time Example:
In Jenkins, my login test failed but worked locally. I discovered the issue was due to headless Chrome not handling animations well. Fixed it by adding --disable-gpu in ChromeOptions.
Answer:
- Dynamic elements → Solved with robust XPaths and waits.
- Captcha/OTP → Handled via API/DB fetch instead of UI.
- Stale Element Exceptions → Solved with re-locating elements.
- CI/CD failures → Fixed with headless browser configs and retries.
Real-time Example:
In Salesforce Lightning UI, elements often refreshed dynamically. I overcame this by writing a custom wait utility for visibility + clickability checks, which improved stability by 25%.
49. How do you decide what to automate and what not to automate?
Answer:
Criteria I use:
✅ Automate when →
- Test is repetitive & stable
- Test has large data sets
- Test is critical for regression
- Test needs multiple environment runs
❌ Avoid automating when →
- Feature is still evolving
- Validation requires visual/manual judgment
- Scenarios involve Captcha, handwriting, biometric inputs
Real-time Example:
In telecom CRM, I automated order processing, billing, and reporting but left Captcha verification for login as manual.
Answer:
- Used Selenium for UI validations.
- Used REST Assured for backend data validation.
Example:
Response res = given().get("https://api.myapp.com/orders/123");
Assert.assertEquals(res.getStatusCode(), 200);
Real-time Example:
When placing an order, I used Selenium to submit the form, then used API validation to confirm the order was actually created in the backend before asserting UI.
Answer:
- Implement POM + Page Factory for reusable locators.
- Maintain test data externally (Excel/JSON/DB).
- Use utility/helper classes for common actions.
- Apply naming conventions and proper folder structure.
- Regular refactoring to remove duplicates.
- Run parallel tests with TestNG/Selenium Grid.
Real-time Example:
In my Salesforce project, new features were added frequently. By following POM + modular design, only locator files needed updates, not the whole scripts — saving huge effort.
----------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment