Repository navigation
Selenium Quick Start Guide
e2e/
├── config/test.config.js # Test configuration & test data
├── helpers/waits.js # Wait utilities for reliable tests
├── pages/
│ ├── LoginPage.js # Login page object
│ ├── DashboardPage.js # Dashboard page object
│ ├── RecipePage.js # Recipe detail page object
│ └── ProfilePage.js # User profile page object
└── tests/
├── auth.test.js # Authentication tests
├── recipes.test.js # Recipe interaction tests
└── profile.test.js # Profile tests
cd practice-app/frontend
npm install --save-dev selenium-webdriver# Via npm (easiest)
npm install --save-dev webdriver-manager
npx webdriver-manager update
# Or manually download from:
# https://chromedriver.chromium.org/Add these to your package.json under "scripts":
{
"scripts": {
"e2e": "jest e2e/tests --runInBand",
"e2e:watch": "jest e2e/tests --watch --runInBand",
"e2e:chrome": "jest e2e/tests/auth.test.js --runInBand"
}
}npm run dev
# Your app should be at http://localhost:5173npm run e2e:chromeInstead of this (bad):
// ❌ Bad - scattered selectors, hard to maintain
test('login', () => {
driver.findElement({ css: 'input[type="email"]' }).sendKeys('test@test.com');
driver.findElement({ css: 'input[type="password"]' }).sendKeys('pass123');
driver.findElement({ css: 'button' }).click();
});We do this (good):
// ✅ Good - organized, reusable, maintainable
test('login', async () => {
await loginPage.login('test@test.com', 'pass123');
expect(await dashboardPage.isDisplayed()).toBe(true);
});Each page object encapsulates:
- Locators - CSS selectors/XPaths to find elements
- Actions - Methods to interact with the page
- Assertions - Methods to verify state
Example - LoginPage.js:
class LoginPage {
// 1. Locators
emailInput = By.css('input[type="email"]');
loginButton = By.css('button[type="submit"]');
// 2. Actions
async enterEmail(email) {
const element = await waitForElement(this.driver, this.emailInput);
await element.sendKeys(email);
}
// 3. Assertions
async isDisplayed() {
const element = await waitForElement(this.driver, this.loginButton, 5000);
return await element.isDisplayed();
}
}Each test file follows this pattern:
describe('Feature Group', () => {
let driver;
let page;
// Setup: run once before all tests
beforeAll(async () => {
driver = await new Builder().forBrowser('chrome').build();
page = new MyPage(driver);
});
// Cleanup: run once after all tests
afterAll(async () => {
await driver.quit();
});
// Setup before each test
beforeEach(async () => {
await loginPage.navigateTo();
await loginPage.login(user.email, user.password);
});
// Your actual test
test('should do something', async () => {
await page.doAction();
const result = await page.getResult();
expect(result).toBe(expectedValue);
});
});// Find by ID
By.id('submit-button')
// Find by CSS Selector
By.css('button.login-btn')
By.css('input[type="password"]')
// Find by XPath
By.xpath('//button[contains(text(), "Login")]')
// Find by class
By.className('submit-btn')
// Find by link text
By.linkText('Login')❌ Bad - Hardcoded waits:
driver.sleep(3000); // ❌ Slow and unreliable!✅ Good - Explicit waits:
// Wait for element to exist
await waitForElement(driver, By.id('element'), 10000);
// Wait for element to be visible
await waitForElementVisible(driver, element, 10000);
// Wait for element to be clickable
await waitForElementClickable(driver, element, 10000);
// Wait for URL to change
await waitForUrlChange(driver, '/dashboard', 10000);// Click
await element.click();
// Type text
await element.sendKeys('text here');
// Clear input
await element.clear();
// Get text
const text = await element.getText();
// Get attribute
const value = await element.getAttribute('data-value');
// Check if displayed
const visible = await element.isDisplayed();
// Check if enabled
const enabled = await element.isEnabled();✓ should display login page
✓ should login with valid credentials
✓ should show error with invalid credentials
✓ should have forgot password link
✓ should have register link
✓ should display dashboard after successful login
✓ should display user greeting
✓ should logout successfully
✓ should display recipes on dashboard
✓ should navigate to recipe detail page
✓ should display recipe title
✓ should display recipe description
✓ should display ingredients
✓ should bookmark a recipe
✓ should unbookmark a recipe
✓ should rate a recipe
✓ should navigate back to dashboard
✓ should display profile page
✓ should display user name
✓ should display user email
✓ should display bookmarked recipes count
✓ should edit user name
✓ should edit user bio
✓ should cancel profile edit
In e2e/config/test.config.js, update with real test credentials:
testData: {
validUser: {
email: 'your-test@example.com', // Update this
password: 'your-test-password' // Update this
},
invalidUser: {
email: 'invalid@example.com',
password: 'wrongpassword'
}
}If tests can't find elements, update the locators in page objects:
// In LoginPage.js - if your email input has different selector
emailInput = By.css('input[placeholder="Email"]'); // Update if needed
loginButton = By.xpath('//button[text()="Sign In"]'); // Use XPath if neededHow to find the right selector:
- Open app in browser
- Open DevTools (F12)
- Inspect the element
- Copy the selector or create XPath
Make your tests more reliable by adding data-testid to your components:
// In your React component
<input
type="email"
data-testid="email-input" // Add this
placeholder="Email"
/>
<button
type="submit"
data-testid="login-btn" // Add this
>
Login
</button>Then use in tests:
emailInput = By.css('[data-testid="email-input"]');
loginButton = By.css('[data-testid="login-btn"]');| Problem | Solution |
|---|---|
| "Element not found" | Check selector in DevTools, update locator |
| "Timeout waiting for element" | Increase timeout, verify element loads |
| "Port already in use" | App not running or port conflict - restart |
| "ChromeDriver version mismatch" | Update webdriver-manager: npx webdriver-manager update
|
| "Test times out" | Add console logs to debug, check if element exists |
| "StaleElementReference" | Re-find element instead of reusing reference |
- Run the basic tests and see what needs fixing for your app
- Update selectors in page objects to match your app's structure
- Add data-testid attributes to your React components for reliability
- Create more specific tests for your app's unique features
- Integrate with CI/CD (GitHub Actions, Jenkins, etc.)
- Selenium Documentation
- Selenium JS API Docs
- Page Object Pattern
- Best Practices Guide
- CSS Selectors
- XPath Tutorial
Q: Why use Selenium instead of Just Jest? A: Jest tests individual components. Selenium tests complete workflows with real browsers - catching integration bugs.
Q: How long should E2E tests take? A: Typically 30 seconds - 5 minutes depending on complexity. That's why they're run less frequently than unit tests.
Q: Can I run multiple tests in parallel?
A: Yes, but start with sequential (--runInBand) to avoid port conflicts.
Q: How do I test API calls? A: Selenium makes real API calls - great for testing! If you need mocking, use fixtures or intercept requests.
Enjoy testing! 🎉
- Customer Milestone 1 Report of CMPE 451 Fall 2025
- Customer Milestone 2 Report of CMPE 451 Fall 2025
- Customer Milestone 3 Report of CMPE 451 Fall 2025
- Customer Milestone 2 Template Report of CMPE 451 Fall 2025
- Lab8: Requirements Review & Acceptance Planning
- Lab 9: Milestone 3 Demo Preparation
- Celil Özkan (Backend)
- Cem Sarpkaya (Backend)
- Özgür Savaşçıoğlu (Backend)
- Taha Ensar Kukul (Frontend)
- Ahmet Hacıoğlu (Frontend)
- Ahmet Selçuk Ersoy (Frontend)
- Bahadır Demirel (Frontend)
- Muhammed Ekinci (Mobile)
- Ali Gökçek (Mobile)
- Seyit Mustafa Demir (Mobile)
- Talha Özdoğan (Mobile)
- Requirements
- Milestones Roadmap
- Lab 5: MVP Implementation & Planning
- Unit Tests Coverage
- Selenium Quick Start Guide
- Selenium Testing Guide
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
- Lab1 Report
- Lab2 Report
- Lab3 Report
- Lab4 Report
- Lab5 Report
- Lab6 Report
- Lab7 Report
- Lab8 Report
- Lab9 Report
- Lab Report Template
- Lab 1 Meeting Notes (23.09.2025)
- Lab 2 Meeting Notes (30.09.2025)
- Lab 3 Meeting Notes (07.10.2025)
- Lab 4 Meeting Notes (14.10.2025)
- Lab 5 Meeting Notes (04.11.2025)
- Lab 6 Meeting Notes (11.11.2025)
- Lab 7 Meeting Notes (18.11.2025)
- Lab 8 Meeting Notes (02.12.2025)
- Lab 9 Meeting Notes (09.12.2025)
- Meeting Agenda 1
- Meeting Agenda 2
- Meeting Agenda 3
- Meeting Agenda 4
- Meeting Agenda 5
- Meeting Agenda 6
- Meeting Notes 1 (16.02.2025)
- Meeting Notes 2 (24.02.2025)
- Meeting Notes 3 (27.02.2025)
- Meeting Notes 4 (04.03.2025)
- Meeting Notes 5 (06.03.2025)
- Meeting Notes 6 (13.03.2025)
- Meeting Notes 7 (17.03.2025)
- Meeting Notes 8 (21.04.2025)
- Meeting Notes 9 (28.04.2025)
- Meeting Notes 10 (01.05.2025)
- Meeting Notes 11 (06.05.2025)
- Lecture Notes 1 (13.02.2025)
- Lecture Notes 2 (20.02.2025)
- Lecture Notes 3 (27.02.2025)
- Lecture Notes 4 (06.03.2025)
- Lecture Notes 5 (13.03.2025)
- Project Concept Design
- Elicitation Questions
- Elicitation Q&A
- Backend Endpoints (DRAFT)
- Unit Tests Coverage
Click to Expand ⬇️
- Scenario 1 - User Register
- Scenario 2 - Dietitian Register
- Scenario 3 - User Login
- Scenario 4 - User Deletion
- Scenario 5 - Upload & Edit Recipe
- Scenario 6 - Single Meal Planning
- Scenario 7 - Grocery Price Comparison
- Scenario 8 - Community Forum
- Scenario 9 - Recipe Discovery & Filter
- Scenario 10 - Local Food Discovery
- Scenario 11 - Nutritional Guidance Interaction
- Scenario 12 - Market Inventory Management
- Scenario 13 - Profile Management and Preference Settings
- Scenario 14 - Rate and Comment the Recipe by User
- Scenario 15 - Bookmark a Meal and Access it in Profile Page
- Scenario 16 - Adding Nutrition Tips to a Dietitian Profile
- Scenario 17 - User Forget Password
- Scenario 18 ‐ User Follows Unfollows Users
- Scenario 19 - Allergen Alert and Meal Plan Adjustment
- Scenario 20 - Dietitian Rating of a Recipe