# Dynamic Test Suites for ShopFlow

## Overview
This document explains the dynamic test suite approach implemented to solve the issue where smoke tests and regression tests suites had no test cases to run.

## Problem
The original `Smoke_Tests` and `Regression_Tests` suites were configured as regular test suites with setup/teardown methods but had no test cases explicitly added to them. The tag-based filtering in execution scripts (`-includeTags="P1,SMOKE"` and `-includeTags="REGRESSION"`) only works if test cases are already added to the test suites.

## Solution: Dynamic Test Suites

### 1. Smoke_Tests_Dynamic.groovy & Smoke_Tests_Dynamic.ts
- **Purpose**: Automatically discovers and runs test cases with P1 and SMOKE tags
- **Filtering**: Uses Katalon's built-in dynamic filtering with `tag=(P1) tag=(SMOKE)`
- **Test Cases**: Automatically discovers all test cases with P1 and SMOKE tags
- **Failure Handling**: Stop on failure (critical tests)
- **Timeout**: 60 seconds per test
- **Retry**: 1 attempt

### 2. Regression_Tests_Dynamic.groovy & Regression_Tests_Dynamic.ts
- **Purpose**: Automatically discovers and runs test cases with REGRESSION tags
- **Filtering**: Uses Katalon's built-in dynamic filtering with `tag=(REGRESSION)`
- **Test Cases**: Automatically discovers all test cases with REGRESSION tags
- **Failure Handling**: Continue on failure (regression tests)
- **Timeout**: 120-300 seconds per test (based on priority)
- **Retry**: 2-3 attempts (based on priority)

### 3. Smoke_Tests_Auto_Discover.groovy (Advanced)
- **Purpose**: Custom implementation with manual test case discovery
- **Features**: Dynamic tag-based discovery, comprehensive logging
- **Maintainability**: Easy to add new test cases without modifying the suite

## Test Cases Included

### Smoke Tests (P1 + SMOKE)
1. `01_Authentication/Login` - User login with 2FA
2. `01_Authentication/Logout` - User logout
3. `02_Core_Commerce/Dashboard` - Dashboard functionality
4. `02_Core_Commerce/Add_To_Cart` - Add product to cart
5. `02_Core_Commerce/Product_Catalog_Browse` - Browse product catalog
6. `02_Core_Commerce/Order_Management` - Order management
7. `05_Price_Management/Product_Catalog_Management` - Product catalog management

### Regression Tests (REGRESSION)
1. `01_Authentication/Invalid_Login` - Invalid login scenarios
2. `02_Core_Commerce/Cart_Management` - Cart management
3. `02_Core_Commerce/Order_Scheduling` - Order scheduling
4. `03_User_Management/User_Profile_View` - User profile viewing
5. `04_Admin_Management/Company_Management` - Company management
6. `04_Admin_Management/Company_User_Management` - Company user management
7. `04_Admin_Management/Seller_Management` - Seller management
8. `04_Admin_Management/Store_Management` - Store management
9. `04_Admin_Management/Seller_Groups` - Seller groups
10. `04_Admin_Management/Buying_Groups` - Buying groups
11. `05_Price_Management/Price_File_Management` - Price file management
12. `05_Price_Management/Pricing_Rules_Management` - Pricing rules management
13. `05_Price_Management/Price_File_Upload` - Price file upload
14. `06_Reports_Analytics/Sales_Report_Generation` - Sales report generation

## Usage

### Running Smoke Tests
```bash
./run_smoke_tests.sh
```

### Running Regression Tests
```bash
./run_regression_tests.sh
```

### Manual Execution
```bash
# Smoke Tests
katalonc -noSplash -runMode=console \
    -projectPath="." \
    -testSuitePath="Test Suites/suites/Smoke_Tests_Dynamic" \
    -browserType="Chrome" \
    -executionProfile="default"

# Regression Tests
katalonc -noSplash -runMode=console \
    -projectPath="." \
    -testSuitePath="Test Suites/suites/Regression_Tests_Dynamic" \
    -browserType="Chrome" \
    -executionProfile="default"
```

## Key Features

### 1. True Dynamic Test Discovery
- Uses Katalon's built-in `FilteringTestSuiteEntity` with `DynamicBuiltInSearch`
- Automatically discovers test cases based on tag filtering criteria
- No manual test case listing required
- Easy to maintain and extend

### 2. Comprehensive Logging
- Detailed execution logs
- Test summary with pass/fail counts
- Clear success/failure indicators

### 3. Flexible Configuration
- Configurable timeouts based on test priority
- Configurable retry counts
- Configurable failure handling
- Tag-based filtering in test suite configuration

### 4. Test Data Management
- Automatic test data setup and cleanup
- Isolated test environments
- Data integrity maintenance

## Benefits

1. **No Manual Configuration**: Test cases don't need to be manually added to test suites
2. **Tag-Based Organization**: Easy to organize tests by business module and priority
3. **Maintainable**: Adding new test cases only requires proper tagging
4. **Scalable**: Can easily add more test cases without modifying test suites
5. **Reliable**: Proper setup/teardown ensures test isolation

## Adding New Test Cases

To add new test cases to the dynamic suites:

1. **Create the test case** in the appropriate directory
2. **Add proper tags** to the test case (.tc file):
   - For smoke tests: Add `P1,SMOKE` tags
   - For regression tests: Add `REGRESSION` tag
3. **Create the test implementation** in the Scripts directory
4. **The test will be automatically included** in the next run

## Migration from Static Suites

The original static test suites (`Smoke_Tests.groovy` and `Regression_Tests.groovy`) are still available but not used by the execution scripts. They can be:

1. **Kept for reference** - Useful for understanding the original approach
2. **Removed** - If no longer needed
3. **Converted** - To dynamic suites if preferred

## Future Enhancements

1. **File System Scanning**: Implement actual file system scanning for automatic discovery
2. **Configuration Files**: Use external configuration files for test case lists
3. **Parallel Execution**: Add support for parallel test execution
4. **Advanced Filtering**: Support for more complex tag combinations
5. **Test Prioritization**: Automatic test prioritization based on business impact

## Troubleshooting

### No Tests Found
- Check that test cases have the correct tags
- Verify test case paths are correct
- Ensure test case files exist in the Scripts directory

### Test Failures
- Check browser compatibility
- Verify test data availability
- Review test object repository
- Check application state

### Performance Issues
- Adjust timeouts based on application performance
- Consider running tests in parallel
- Optimize test data setup/cleanup
