Friday, April 11, 2025

Selenium interview qutestion specially for e-Commerce

Lets learn some e-commerce-based testing. Here's a concise breakdown covering key areas, useful for interviews or hands-on QA/testing work.


🔍 1. Core Functionalities to Test

  • User Account & Authentication:

    • Registration, login, password reset

    • Role-based access (admin, customer)

  • Product Catalog:

    • Search, filters, sorting

    • Product detail page (images, descriptions, price, stock status)

  • Shopping Cart:

    • Add/remove items

    • Quantity updates

    • Price calculations (including taxes, discounts, shipping)

  • Checkout Process:

    • Address handling (add/edit/delete)

    • Payment gateway integration (PayPal, Stripe, credit cards)

    • Order confirmation & summary

  • Order Management:

    • Order history, tracking

    • Cancel, return, refund flow

  • Payment Testing:

    • Positive & negative scenarios (failed payments, expired cards)

    • Payment status synchronization (pending, success, failed)


🧪 Types of Testing Specific to E-Commerce

Type Examples
Functional Testing Cart functionality, filters, checkout flow
Integration Testing Payment gateway, shipping API, tax service
Security Testing SQL injection, session management, data privacy
Performance Testing Load testing during a flash sale or Black Friday
Usability Testing Mobile responsiveness, UX/UI validation
A/B Testing Banner placements, checkout layout effectiveness
Regression Testing After new features or bug fixes

🧰 Test Data Scenarios

  • Guest vs Logged-in user

  • Out-of-stock products

  • Discounts and promo codes

  • International addresses (e.g., ZIP/postal codes, regions)

  • Multiple payment methods


🧠 Common Bug Examples

  • Wrong price calculation after discount

  • Cart showing wrong product image

  • Orders being placed without payment

  • Coupons being reused improperly

  • Broken links in email confirmations


⚙️ Tools Commonly Used

  • Automation: Selenium, Cypress, Playwright

  • API Testing: Postman, RestAssured

  • Performance: JMeter, Gatling

  • CI/CD Integration: Jenkins, GitHub Actions

  • Bug Tracking: JIRA, Bugzilla

  • Test Management: TestRail, Zephyr



========================================================================

Selenium Q&A set tailored for e-commerce testing, covering sessions, test data variations, parallel execution, pop-ups (like discounts), and billing accuracy.


🧠 Selenium Q&A for E-commerce Testing


1. How do you manage user sessions in Selenium while testing an e-commerce site?

Answer: In Selenium, user sessions are managed via cookies or the WebDriver instance. For example, to keep a user logged in:

// Save cookies after login
Set<Cookie> cookies = driver.manage().getCookies();

// Reuse cookies in another session
for (Cookie cookie : cookies) {
    driver.manage().addCookie(cookie);
}
driver.navigate().refresh(); // Refresh to reflect logged-in state

This is useful when testing cart persistence or returning users.


2. How do you handle dynamic discount pop-ups using Selenium?

Answer: Discount pop-ups are often dynamic overlays. Handle them using waits and conditional logic:

try {
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
    WebElement popup = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("discount-popup")));
    WebElement closeBtn = popup.findElement(By.className("close"));
    closeBtn.click(); // Or interact if needed
} catch (TimeoutException e) {
    // Pop-up didn’t appear; continue
}

3. How can you test different user data or scenarios (like guest vs registered users)?

Answer: Use data-driven testing via:

  • Excel/CSV files (via Apache POI / OpenCSV)

  • JSON or YAML config files

  • TestNG @DataProvider

Example using DataProvider (TestNG):

@DataProvider(name = "userTypes")
public Object[][] getUserTypes() {
    return new Object[][] {
        {"guest", "", ""},
        {"registered", "user@example.com", "password123"}
    };
}

Use it in your test:

@Test(dataProvider = "userTypes")
public void testCheckoutFlow(String userType, String email, String password) {
    if (userType.equals("registered")) {
        login(email, password);
    }
    addItemToCart();
    proceedToCheckout();
    // assertions here
}

4. How do you verify the correct billing (including discount, tax, shipping)?

Answer: Grab the values from the UI and compute expected values programmatically.

double price = Double.parseDouble(driver.findElement(By.id("product-price")).getText().replace("$", ""));
double tax = Double.parseDouble(driver.findElement(By.id("tax")).getText().replace("$", ""));
double discount = Double.parseDouble(driver.findElement(By.id("discount")).getText().replace("$", ""));
double total = Double.parseDouble(driver.findElement(By.id("total")).getText().replace("$", ""));

double expectedTotal = price + tax - discount;

Assert.assertEquals(total, expectedTotal, "Billing mismatch detected!");

Use rounding for decimal places to avoid floating point mismatches.


5. How do you run the same product flow in parallel (e.g., 2 users buying same item)?

Answer: Use TestNG parallel execution with thread-safe WebDriver instances (like ThreadLocal pattern) or tools like Selenium Grid or Dockerized Selenium with docker-compose.

testng.xml:

<suite name="ParallelTests" parallel="tests" thread-count="2">
  <test name="User1Flow">
    <classes><class name="tests.User1Test" /></classes>
  </test>
  <test name="User2Flow">
    <classes><class name="tests.User2Test" /></classes>
  </test>
</suite>

In each test class, instantiate your own WebDriver:

ThreadLocal<WebDriver> driver = new ThreadLocal<>();

@BeforeMethod
public void setup() {
    WebDriver wd = new ChromeDriver();
    driver.set(wd);
}

6. How do you verify stock updates if two users buy the same product in parallel?

Answer:

  1. Use parallel execution (as above).

  2. Both users try to add the last item in stock.

  3. One will succeed; the other should see an "Out of stock" message.

Use assertions to verify:

String stockMessage = driver.findElement(By.id("stock-status")).getText();
Assert.assertTrue(stockMessage.contains("Out of stock") || stockMessage.contains("Item added"),
 "Unexpected stock behavior");

7. How do you handle stale element exceptions during e-commerce testing?

Answer: When page DOM updates dynamically (e.g., after applying filters), the element references become stale.

Solution:

  • Re-locate the element after wait or action.

  • Use ExpectedConditions.refreshed.

WebElement filterBtn = wait.until(ExpectedConditions.refreshed(
    ExpectedConditions.elementToBeClickable(By.id("apply-filter"))));
filterBtn.click();

========================================================================


No comments:

Post a Comment