Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.

Selenium Testing Guideline

e-taha edited this page Nov 11, 2025 · 1 revision

Selenium E2E Testing Guide

This directory contains end-to-end (E2E) tests using Selenium WebDriver.

Directory Structure

e2e/
├── config/           # Configuration files
├── helpers/          # Utility functions and helpers
├── pages/            # Page Object Models
├── tests/            # Test files
└── drivers/          # Browser drivers (if using manual setup)

Setup

1. Install Dependencies

npm install --save-dev selenium-webdriver

2. Install WebDriver Manager (Recommended)

npm install --save-dev webdriver-manager
webdriver-manager update

3. Or Manual Driver Setup

Running Tests

Run All Tests

npm run e2e

Run Specific Test File

npx jest e2e/tests/auth.test.js

Run with Specific Browser

npm run e2e:chrome

Run on Multiple Browsers

npm run e2e:all

Test Files

auth.test.js

Tests for user authentication:

  • Login with valid/invalid credentials
  • Registration flow
  • Password reset
  • Logout

recipes.test.js

Tests for recipe interactions:

  • Recipe browsing
  • Recipe details
  • Bookmarking recipes
  • Rating recipes
  • Recipe filtering and search

profile.test.js

Tests for user profile:

  • Profile display
  • Profile editing
  • User preferences
  • Bookmarked recipes
  • My recipes section

Page Object Models

LoginPage

Methods:

  • navigateTo() - Go to login page
  • login(email, password) - Perform login
  • getErrorMessage() - Get error text
  • clickForgotPassword() - Click forgot password link
  • clickRegister() - Click register link

DashboardPage

Methods:

  • navigateTo() - Go to dashboard
  • isDashboardDisplayed() - Check if dashboard visible
  • getRecipeCount() - Get number of recipes
  • clickRecipe(index) - Click recipe by index
  • clickLogout() - Logout user

RecipePage

Methods:

  • navigateTo(recipeId) - Go to recipe detail
  • getRecipeTitle() - Get recipe title
  • getRecipeDescription() - Get description
  • clickBookmark() - Toggle bookmark
  • isBookmarked() - Check if bookmarked
  • rateRecipe(stars) - Rate recipe (1-5)

ProfilePage

Methods:

  • navigateTo() - Go to profile page
  • getUserName() - Get user's name
  • getUserEmail() - Get user's email
  • clickEditProfile() - Enter edit mode
  • updateName(newName) - Update user name
  • updateBio(newBio) - Update user bio
  • clickSave() - Save changes
  • clickCancel() - Cancel editing

Helpers

waits.js

Utility functions for waiting:

  • waitForElement() - Wait for element to be present
  • waitForElementVisible() - Wait for element to be visible
  • waitForElementClickable() - Wait for element to be clickable
  • waitForUrlChange() - Wait for URL to change
  • waitForPageTitle() - Wait for page title
  • sleep() - Sleep for milliseconds (use sparingly)

Best Practices

✅ DO:

  • Use Page Object Model pattern
  • Use explicit waits instead of sleep
  • Add data-testid attributes to your components
  • Test complete user workflows
  • Give tests descriptive names
  • Clean up after tests (quit driver)

❌ DON'T:

  • Use hardcoded waits (setTimeout)
  • Test implementation details
  • Make tests depend on each other
  • Test too many things in one test
  • Forget to handle async/await

Example Test Structure

describe("Feature Group", () => {
  let driver;
  let page;

  beforeAll(async () => {
    driver = await new Builder().forBrowser("chrome").build();
    page = new MyPage(driver);
  });

  afterAll(async () => {
    await driver.quit();
  });

  test("should do something", async () => {
    await page.navigateTo();
    await page.doAction();
    const result = await page.getResult();
    expect(result).toBe(expectedValue);
  });
});

Locator Strategies

Use in By object:

By.id("element-id");
By.name("element-name");
By.className("class-name");
By.css("css.selector");
By.xpath("//xpath/expression");
By.linkText("Link Text");
By.partialLinkText("Partial");

Configuration

See config/test.config.cjs for settings:

  • Base URL
  • Browser options
  • Timeouts
  • Test data
  • Reporter settings

Troubleshooting

Issue Solution
Element not found Check locator, use DevTools to inspect
Timeout Increase timeout, verify element exists
StaleElementReference Re-find element, use explicit waits
SessionNotCreated Update WebDriver, check browser version
Port already in use Kill existing process or change port

CI/CD Integration

To run tests in CI/CD pipeline:

# GitHub Actions example
- name: Run E2E Tests
  run: npm run e2e
  env:
    BASE_URL: ${{ secrets.BASE_URL }}

Resources

⚡ Milestone Reports

⚡ Milestone Demo Plan

👥 Team Members

🚀 Project

🧱 Diagrams

Milestone 1 Demo Plan

💬 Communication Plan

🆆 Weekly Reports

09-22 Week 1
09-29 Week 2
10-06 Week 3
10-13 Week 4
10-20 Week 5
10-27 Week 6
11-03 Week 7
11-10 Week 8
11-17 Week 9
11-24 Week 10
12-01 Week 11
12-08 Week 12

👥 Lab Reports

📋 Lab Agendas

📋 Weekly Meeting Agendas

👨‍🏫 Customer Meeting Notes

🧪 Lab Meeting Notes

📅 Meeting Notes

📂 Backend Subgroup Meeting Notes

📂 Frontend Subgroup Meeting Notes

📂 Mobile Subgroup Meeting Notes

📚 Archives

📌 Milestone Report

💬 Communication Plan

📋 Meeting Agendas

📅 Meeting Notes

📂 Backend Subgroup Meeting Notes

📂 Frontend Subgroup Meeting Notes

📂 Mobile Subgroup Meeting Notes

📚 Lecture Notes

🛠️ Team Best Practices

✍️ Guidance

❗ Issues

🚀 Project

👩‍💼 User Scenarios

Click to Expand ⬇️

🗂️ Templates

Clone this wiki locally