Skip to content

Commit cde0047

Browse files
committed
Update reame
1 parent cd2dd94 commit cde0047

1 file changed

Lines changed: 34 additions & 150 deletions

File tree

README.md

Lines changed: 34 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -96,79 +96,12 @@ mvn clean test \
9696

9797
### Overview
9898

99-
```
100-
┌─────────────────────────────────────────────────────────────────────────┐
101-
│ PARALLEL TEST EXECUTION (BrowserStack Cloud) │
102-
│ ┌──────────────────────────────────────────────────────────────────┐ │
103-
│ │ TestNG Orchestration Layer │ │
104-
│ │ testngSuite.xml: parallel="methods" thread-count="N" │ │
105-
│ └──────────────────────────────────────────────────────────────────┘ │
106-
│ │ │
107-
│ ┌───────────────┼───────────────┐ │
108-
│ ▼ ▼ ▼ │
109-
│ ┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────┐ │
110-
│ │ Thread-1 │ │ Thread-2 │ │ Thread-N │ │
111-
│ │ (Scenario A) │ │ (Scenario B) │ │ (Scenario X) │ │
112-
│ └─────────┬───────────┘ └─────────┬───────────┘ └─────────┬───────┘ │
113-
│ │ │ │ │
114-
│ ┌─────────▼───────────────────────▼───────────────────────▼───────┐ │
115-
│ │ SHARED SINGLETON LAYER │ │
116-
│ │ ┌───────────────────────────────────────────────────────────┐ │ │
117-
│ │ │ ConfigManager (synchronized init, immutable YAML data) │ │ │
118-
│ │ │ ExtentReports (synchronized createTest, single report) │ │ │
119-
│ │ └───────────────────────────────────────────────────────────┘ │ │
120-
│ └──────────────────────────────────────────────────────────────────┘ │
121-
│ │ │ │ │
122-
│ ┌─────────▼───────────────────────▼───────────────────────▼───────┐ │
123-
│ │ THREAD-LOCAL ISOLATION LAYER │ │
124-
│ │ │ │
125-
│ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ │
126-
│ │ │DriverManager │ │DriverManager │ │DriverManager │ │ │
127-
│ │ │ThreadLocal< │ │ThreadLocal< │ │ThreadLocal< │ │ │
128-
│ │ │ AppiumDriver> │ │ AppiumDriver> │ │ AppiumDriver> │ │ │
129-
│ │ │ → BS Session 1 │ │ → BS Session 2 │ │ → BS Session N │ │ │
130-
│ │ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │ │
131-
│ │ │ │ │ │ │
132-
│ │ ┌────────▼────────┐ ┌────────▼────────┐ ┌────────▼────────┐ │ │
133-
│ │ │PageObjectMgr │ │PageObjectMgr │ │PageObjectMgr │ │ │
134-
│ │ │ThreadLocal< │ │ThreadLocal< │ │ThreadLocal< │ │ │
135-
│ │ │ POM Instance> │ │ POM Instance> │ │ POM Instance> │ │ │
136-
│ │ │ └─HomeScreen │ │ └─HomeScreen │ │ └─HomeScreen │ │ │
137-
│ │ │ └─LoginScreen │ │ └─LoginScreen │ │ └─LoginScreen │ │ │
138-
│ │ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │ │
139-
│ │ │ │ │ │ │
140-
│ │ ┌────────▼────────┐ ┌────────▼────────┐ ┌────────▼────────┐ │ │
141-
│ │ │ExtentTest │ │ExtentTest │ │ExtentTest │ │ │
142-
│ │ │ThreadLocal< │ │ThreadLocal< │ │ThreadLocal< │ │ │
143-
│ │ │ ExtentTest> │ │ ExtentTest> │ │ ExtentTest> │ │ │
144-
│ │ │ "Scenario A" │ │ "Scenario B" │ │ "Scenario X" │ │ │
145-
│ │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ │
146-
│ └──────────────────────────────────────────────────────────────────┘ │
147-
│ │ │ │ │
148-
│ ▼ ▼ ▼ │
149-
│ ┌─────────────────────────────────────────────────────────────────┐ │
150-
│ │ BROWSERSTACK CLOUD INFRASTRUCTURE │ │
151-
│ │ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ │
152-
│ │ │ Real Device 1 │ │ Real Device 2 │ │ Real Device N │ │ │
153-
│ │ │ Galaxy S23 │ │ iPhone 15 Pro │ │ Pixel 8 │ │ │
154-
│ │ │ Android 13 │ │ iOS 17 │ │ Android 14 │ │ │
155-
│ │ └───────────────┘ └───────────────┘ └───────────────┘ │ │
156-
│ │ SDK manages: App upload, Capabilities, Device allocation │ │
157-
│ └─────────────────────────────────────────────────────────────────┘ │
158-
│ │
159-
└─────────────────────────────────────────────────────────────────────────┘
160-
161-
CLEANUP PHASE (per thread)
162-
┌─────────────────────────────────────────────────────────────────────────┐
163-
│ @After Hook (Hooks.java) - GUARANTEED via try-finally │
164-
│ ┌─────────────────────────────────────────────────────────────────┐ │
165-
│ │ finally { │ │
166-
│ │ PageObjectManager.reset(); // ThreadLocal.remove() │ │
167-
│ │ DriverManager.quitDriver(); // Quits BrowserStack session │ │
168-
│ │ } │ │
169-
│ └─────────────────────────────────────────────────────────────────┘ │
170-
└─────────────────────────────────────────────────────────────────────────┘
171-
```
99+
The framework uses a **layered isolation model** combining shared singletons for configuration and reporting with thread-local storage for driver and page object isolation. This enables safe parallel test execution without resource contention.
100+
101+
**Key Components:**
102+
- **Shared Layer**: ConfigManager (YAML config), ExtentReports (single report file)
103+
- **Thread-Local Layer**: AppiumDriver, PageObjectManager, ExtentTest instances
104+
- **Cleanup**: @After hook with try-finally ensures guaranteed resource cleanup
172105

173106
### Component-Level Thread Safety
174107

@@ -442,40 +375,22 @@ public class Hooks {
442375

443376
### Parallel Execution Memory Model
444377

445-
```
446-
┌─────────────────────────────────────────────────────────────────────────┐
447-
JVM HEAP
448-
├─────────────────────────────────────────────────────────────────────────┤
449-
│ │
450-
│ ┌────────────────────────────────────────────────────────────────────┐ │
451-
│ │ SHARED MEMORY (Singletons) │ │
452-
│ │ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │ │
453-
│ │ │ ConfigManager │ │ ExtentReports │ │ BrowserStack SDK │ │ │
454-
│ │ │ (YAML Config) │ │ (Report File) │ │ (Cloud Manager) │ │ │
455-
│ │ └──────────────────┘ └──────────────────┘ └──────────────────┘ │ │
456-
│ └────────────────────────────────────────────────────────────────────┘ │
457-
│ │
458-
│ ┌────────────────────────────────────────────────────────────────────┐ │
459-
│ │ THREAD-LOCAL MEMORY (Per Thread) │ │
460-
│ │ │ │
461-
│ │ Thread-1 Stack Thread-2 Stack │ │
462-
│ │ ┌─────────────────────┐ ┌─────────────────────┐ │ │
463-
│ │ │ ThreadLocal Data: │ │ ThreadLocal Data: │ │ │
464-
│ │ │ ├─ AppiumDriver │ │ ├─ AppiumDriver │ │ │
465-
│ │ │ ├─ PageObjectMgr │ │ ├─ PageObjectMgr │ │ │
466-
│ │ │ │ ├─ HomeScreen │ │ │ ├─ HomeScreen │ │ │
467-
│ │ │ │ └─ LoginScreen │ │ │ └─ LoginScreen │ │ │
468-
│ │ │ └─ ExtentTest │ │ └─ ExtentTest │ │ │
469-
│ │ └─────────────────────┘ └─────────────────────┘ │ │
470-
│ └────────────────────────────────────────────────────────────────────┘ │
471-
│ │
472-
└─────────────────────────────────────────────────────────────────────────┘
473-
```
378+
Each test thread has isolated copies of driver, page objects, and test reporting:
379+
380+
| Component | Isolation Level | Storage | Thread-Safe |
381+
|-----------|-----------------|---------|-------------|
382+
| AppiumDriver | Per thread | ThreadLocal |ZERO contention |
383+
| PageObjectManager | Per thread | ThreadLocal |No shared state |
384+
| ExtentTest | Per thread | ThreadLocal |Isolated test nodes |
385+
| ConfigManager | Shared (read-only) | Static singleton |Synchronized init only |
386+
| ExtentReports | Shared (write-safe) | Static singleton |Internally synchronized |
474387

475388
### Running Parallel Tests
476389

390+
Tests execute in parallel via TestNG with isolated threads per scenario:
391+
477392
```bash
478-
# Enable parallel execution in TestNG (standard command)
393+
# Standard parallel execution (configured in testngSuite.xml)
479394
mvn clean test \
480395
-DsuiteXmlFile=testngSuite.xml \
481396
-Dplatform=android \
@@ -498,17 +413,22 @@ mvn clean test \
498413
</suite>
499414
```
500415

416+
**Parallelization Strategy:**
417+
- `parallel="methods"`: Each test method runs in its own thread
418+
- `thread-count="4"`: Maximum 4 concurrent threads
419+
- Thread-local storage: Each thread maintains isolated driver, page objects, and test reporting
420+
501421
### Thread Safety Checklist
502422

503-
| Component | Pattern | Thread-Safe? | Notes |
504-
|-----------|---------|--------------|-------|
505-
| DriverManager | ThreadLocal | ✅ | Each thread has isolated driver |
506-
| PageObjectManager | ThreadLocal | ✅ | Each thread has isolated page objects |
507-
| ExtentReportManager | ThreadLocal + Synchronized | ✅ | Shared report, isolated test nodes |
508-
| ConfigManager | Synchronized init | ✅ | One-time load, immutable after |
509-
| DriverFactory | BrowserStack Cloud | ✅ | SDK handles device allocation & isolation |
510-
| BasePage | Stateless | ✅ | Uses thread's driver via DriverManager |
511-
| Hooks | try-finally | ✅ | Guaranteed cleanup |
423+
| Component | Pattern | Thread-Safe | Notes |
424+
|-----------|---------|-------------|-------|
425+
| DriverManager | ThreadLocal | ✅ | Each thread has isolated driver; BrowserStack cloud handles session isolation |
426+
| PageObjectManager | ThreadLocal | ✅ | Each thread has isolated page objects; cleaned up via @After hook |
427+
| ExtentReportManager | ThreadLocal + Synchronized | ✅ | Shared report file with isolated test nodes per thread |
428+
| ConfigManager | Synchronized init | ✅ | One-time YAML load; immutable after initialization |
429+
| DriverFactory | BrowserStack SDK | ✅ | SDK manages device allocation and capabilities injection |
430+
| BasePage | Stateless | ✅ | Accesses thread's driver via DriverManager.getDriver() |
431+
| Hooks | try-finally | ✅ | Guaranteed cleanup prevents memory leaks in parallel execution |
512432

513433
## 🎯 Key Design Patterns
514434

@@ -524,47 +444,15 @@ mvn clean test \
524444
| **Template Method** | `BasePage` defines common actions | DRY, consistent element interactions |
525445
| **Strategy Pattern** | Element-based assertions with fallbacks | Reliable mobile element detection |
526446

527-
## Architectural Traceability & Rationale ##
528447

529-
Why This Design?
530-
Our framework is architected for scalability, maintainability, and parallel execution. Key design choices include:
531-
532-
Layered Traceability:
533-
Each test scenario flows from .feature files (business intent), through step definitions (glue), into screen/page objects (UI abstraction), and down to base classes and utilities (engine). This clear separation ensures traceability from business requirements to code.
534-
535-
OOP Principles:
536-
537-
Abstract BasePage: Enforces a contract for all screens, sharing common actions while preventing direct instantiation.
538-
Protected Methods: Restrict low-level actions to subclasses, encapsulating driver logic and reducing accidental misuse.
539-
Final Utility Classes: (e.g., WdioLocators) Prevent inheritance and instantiation, ensuring a single source of truth for constants and locators.
540-
Composition Over Inheritance:
541-
Utility classes (e.g., ElementActions, WaitUtils) are injected into page objects, promoting loose coupling and easier testing.
542-
543-
Thread Safety:
544-
DriverManager uses ThreadLocal to isolate driver instances, enabling safe parallel test execution and maximizing resource utilization.
545-
546-
Design Patterns:
547-
548-
Singleton: For configuration management, ensuring consistent settings.
549-
Factory: For driver creation, supporting multiple platforms.
550-
Page Object Manager: Centralizes and reuses page objects, reducing duplication.
551-
Architectural Intelligence
552-
This design:
553-
554-
Supports parallelism (via ThreadLocal drivers).
555-
Enforces encapsulation (via access modifiers and abstract classes).
556-
Promotes reusability and maintainability (via composition and design patterns).
557-
Enables clear traceability from business logic to engine code, making debugging and onboarding easier.
558448

559449

560450
## 🚀 Quick Start
561451

562452
### Prerequisites
563453
- Java 21+
564454
- Maven 3.8+
565-
- Appium Server 2.x (`npm install -g appium`)
566-
- Android SDK (for Android testing)
567-
- Xcode (for iOS testing on macOS)
455+
- BrowserStack account with active credentials
568456

569457
### Installation
570458

@@ -575,15 +463,11 @@ cd MobileAutomation_BDD_Framework
575463

576464
# Install dependencies
577465
mvn clean install -DskipTests
578-
579-
# Install Appium drivers
580-
appium driver install uiautomator2 # Android
581-
appium driver install xcuitest # iOS
582466
```
583467

584468
### Running Tests
585469

586-
All tests run on BrowserStack using the SDK agent. See the BrowserStack section below for detailed instructions.
470+
All tests run on BrowserStack cloud infrastructure using the SDK agent. See the **BrowserStack (SDK-Only)** section for detailed instructions.
587471

588472
---
589473

0 commit comments

Comments
 (0)