From 15e4247fa2cbfe05f0d1c5b9ebcacee4119f84c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Hennes?= Date: Thu, 20 Nov 2025 20:51:43 +0100 Subject: [PATCH] WIP functional testing --- .github/workflows/eicaptcha-e2e-tests.yml | 202 ++++++ .gitignore | 1 + tests/README.md | 595 ++++++++++++++++++ tests/functionnal/.env.ps178 | 22 + tests/functionnal/.env.ps8 | 22 + tests/functionnal/.env.ps9 | 22 + tests/functionnal/.gitignore | 24 +- tests/functionnal/apply_case.php | 34 +- tests/functionnal/docker-compose.yml | 87 +++ tests/functionnal/e2e/pages/defaultPage.ts | 2 +- tests/functionnal/package-lock.json | 70 +-- tests/functionnal/playwright.config.ts | 32 +- tests/functionnal/scripts/init-prestashop.sh | 116 ++++ tests/functionnal/scripts/restore-db.sh | 94 +++ .../functionnal/scripts/test-all-versions.sh | 72 +++ tests/functionnal/scripts/test-local.sh | 116 ++++ tests/functionnal/snapshots/.gitkeep | 0 17 files changed, 1446 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/eicaptcha-e2e-tests.yml create mode 100644 tests/README.md create mode 100644 tests/functionnal/.env.ps178 create mode 100644 tests/functionnal/.env.ps8 create mode 100644 tests/functionnal/.env.ps9 create mode 100644 tests/functionnal/docker-compose.yml create mode 100755 tests/functionnal/scripts/init-prestashop.sh create mode 100755 tests/functionnal/scripts/restore-db.sh create mode 100755 tests/functionnal/scripts/test-all-versions.sh create mode 100755 tests/functionnal/scripts/test-local.sh create mode 100644 tests/functionnal/snapshots/.gitkeep diff --git a/.github/workflows/eicaptcha-e2e-tests.yml b/.github/workflows/eicaptcha-e2e-tests.yml new file mode 100644 index 0000000..665dd57 --- /dev/null +++ b/.github/workflows/eicaptcha-e2e-tests.yml @@ -0,0 +1,202 @@ +name: eicaptcha E2E Tests + +on: + push: + branches: + - main + - develop + paths: + - 'modules/eicaptcha/**' + - '.github/workflows/eicaptcha-e2e-tests.yml' + pull_request: + paths: + - 'modules/eicaptcha/**' + - '.github/workflows/eicaptcha-e2e-tests.yml' + workflow_dispatch: # Allow manual trigger + +jobs: + e2e-tests: + name: E2E Tests (PS ${{ matrix.prestashop }} - PHP ${{ matrix.php }}) + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + include: + # PrestaShop 1.7.8.x with PHP 7.4 & 8.1 + - prestashop: '1.7.8.11' + php: '7.4' + mysql: '5.7' + node: '14' + - prestashop: '1.7.8.11' + php: '8.1' + mysql: '5.7' + node: '14' + + # PrestaShop 8.x with PHP 8.1 + - prestashop: '8.1.7' + php: '8.1' + mysql: '8.0' + node: '16' + + # PrestaShop 9.x with PHP 8.1 & 8.3 + - prestashop: '9.0.0' + php: '8.1' + mysql: '8.0' + node: '18' + - prestashop: '9.0.0' + php: '8.3' + mysql: '8.0' + node: '18' + + services: + mysql: + image: mysql:${{ matrix.mysql }} + env: + MYSQL_ROOT_PASSWORD: prestashop + MYSQL_DATABASE: prestashop + MYSQL_USER: prestashop + MYSQL_PASSWORD: prestashop + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping -h localhost -u root -pprestashop" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring, xml, ctype, iconv, intl, pdo_mysql, dom, filter, gd, json, zip + coverage: none + + - name: Setup Node.js ${{ matrix.node }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'npm' + cache-dependency-path: modules/eicaptcha/tests/functionnal/package-lock.json + + - name: Get Composer Cache Directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache Composer dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-ps${{ matrix.prestashop }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer-ps${{ matrix.prestashop }}- + ${{ runner.os }}-composer- + + - name: Install PrestaShop ${{ matrix.prestashop }} + run: | + # Download and extract PrestaShop + wget -O prestashop.zip https://github.com/PrestaShop/PrestaShop/releases/download/${{ matrix.prestashop }}/prestashop_${{ matrix.prestashop }}.zip + unzip -q prestashop.zip -d prestashop + cd prestashop + + # Extract inner zip if exists + if [ -f prestashop.zip ]; then + unzip -q prestashop.zip + rm prestashop.zip + fi + + # Install PrestaShop via CLI + php install-dev/index_cli.php \ + --domain=localhost:8000 \ + --db_server=127.0.0.1 \ + --db_name=prestashop \ + --db_user=prestashop \ + --db_password=prestashop \ + --prefix=ps_ \ + --email=admin@prestashop.local \ + --password=Prestashop123 \ + --language=en \ + --country=fr \ + --newsletter=0 + + # Remove install directory + rm -rf install-dev + + - name: Install eicaptcha module + run: | + cd prestashop + + # Copy module from repository to PrestaShop modules directory + cp -r ../modules/eicaptcha modules/ + + # Install module via CLI + php bin/console prestashop:module install eicaptcha + + - name: Create test user + run: | + cd prestashop + php -r " + require_once 'config/config.inc.php'; + + \$customer = new Customer(); + \$customer->firstname = 'Dev'; + \$customer->lastname = 'Test'; + \$customer->email = 'dev@dev.com'; + \$customer->passwd = Tools::hash('dev1234%123'); + \$customer->id_gender = 1; + \$customer->birthday = '1990-01-01'; + \$customer->newsletter = 1; + \$customer->active = 1; + + if (\$customer->add()) { + echo 'Test customer created successfully!'; + } else { + echo 'Failed to create test customer'; + exit(1); + } + " + + - name: Start PHP built-in server + run: | + cd prestashop + php -S localhost:8000 -t . & + sleep 5 + + # Wait for server to be ready + timeout 30 bash -c 'until curl -f http://localhost:8000/ > /dev/null 2>&1; do sleep 2; done' + + - name: Install Playwright dependencies + working-directory: modules/eicaptcha/tests/functionnal + run: | + npm ci + npx playwright install --with-deps firefox + + - name: Run Playwright tests + working-directory: modules/eicaptcha/tests/functionnal + env: + CI: true + CI_ENVIRONMENT_URL: http://localhost:8000 + run: | + npx playwright test --workers=1 + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: playwright-results-ps${{ matrix.prestashop }}-php${{ matrix.php }} + path: | + modules/eicaptcha/tests/functionnal/playwright-report/ + modules/eicaptcha/tests/functionnal/test-results/ + retention-days: 30 + + - name: Upload screenshots on failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: screenshots-ps${{ matrix.prestashop }}-php${{ matrix.php }} + path: modules/eicaptcha/tests/functionnal/test-results/**/*.png + retention-days: 30 diff --git a/.gitignore b/.gitignore index a6c9a85..85e4782 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ vendor .idea config.xml config_*.xml +credentials.txt logs/*.log \ No newline at end of file diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..9f0aa3d --- /dev/null +++ b/tests/README.md @@ -0,0 +1,595 @@ +# eicaptcha Module - Tests Documentation + +This directory contains all automated tests for the **eicaptcha** PrestaShop module, including functional end-to-end tests using Playwright. + +## Table of Contents + +- [Overview](#overview) +- [Prerequisites](#prerequisites) +- [Quick Start](#quick-start) +- [Running Tests Locally with Docker](#running-tests-locally-with-docker) +- [Running Tests on Multiple PrestaShop Versions](#running-tests-on-multiple-prestashop-versions) +- [GitHub Actions CI/CD](#github-actions-cicd) +- [Project Structure](#project-structure) +- [Database Snapshots](#database-snapshots) +- [Test Configuration](#test-configuration) +- [Adding New Tests](#adding-new-tests) +- [Troubleshooting](#troubleshooting) + +--- + +## Overview + +The eicaptcha module uses **Playwright** for end-to-end (E2E) testing to validate that the reCAPTCHA integration works correctly across: + +- **Contact forms** (reCAPTCHA v2 and v3) +- **Customer registration forms** +- **Newsletter subscription forms** + +Tests are run against multiple PrestaShop versions: +- **PrestaShop 1.7.8.x** (latest 1.7 version) +- **PrestaShop 8.x** (current stable) +- **PrestaShop 9.x** (latest version) + +--- + +## Prerequisites + +### For Local Development + +- **Docker** (20.10+) and **Docker Compose** (1.29+) +- **Node.js** (14+ for PS 1.7.8, 16+ for PS 8.x, 18+ for PS 9.x) +- **npm** (comes with Node.js) +- **Git** (to clone the repository) + +### For GitHub Actions + +No local setup required. Tests run automatically on: +- Push to `main` or `develop` branches +- Pull requests affecting the `modules/eicaptcha/` directory +- Manual workflow dispatch + +--- + +## Quick Start + +### 1. Initialize Test Environment + +Navigate to the functional tests directory: + +```bash +cd modules/eicaptcha/tests/functionnal +``` + +Install Node.js dependencies: + +```bash +npm install +``` + +### 2. Set Up PrestaShop with Docker + +Initialize PrestaShop for a specific version (this creates a database snapshot): + +```bash +# For PrestaShop 8.x (default) +./scripts/init-prestashop.sh 8 + +# For PrestaShop 1.7.8 +./scripts/init-prestashop.sh 1.7.8 + +# For PrestaShop 9.x +./scripts/init-prestashop.sh 9 +``` + +**What this does:** +- Starts Docker containers (PrestaShop + MySQL) +- Installs PrestaShop +- Installs the eicaptcha module +- Creates a test user (`dev@dev.com` / `dev1234%123`) +- Generates a database snapshot for fast restoration + +### 3. Run Tests + +```bash +# Run tests on PrestaShop 8.x +./scripts/test-local.sh 8 + +# Run tests on PrestaShop 1.7.8 +./scripts/test-local.sh 1.7.8 + +# Run tests with Playwright in headed mode (see browser) +./scripts/test-local.sh 8 --headed + +# Run tests in debug mode +./scripts/test-local.sh 8 --debug +``` + +--- + +## Running Tests Locally with Docker + +### Architecture + +The Docker setup includes: + +- **PrestaShop** container (official `prestashop/prestashop` image) +- **MySQL** container (MySQL 5.7 for PS 1.7.8, MySQL 8.0 for PS 8.x/9.x) +- **Playwright** tests run from the host machine (for better debugging) + +### Available Scripts + +| Script | Description | +|--------|-------------| +| `./scripts/init-prestashop.sh ` | Initial setup: installs PrestaShop, module, creates snapshot | +| `./scripts/restore-db.sh ` | Restores database from snapshot (fast reset) | +| `./scripts/test-local.sh ` | Runs E2E tests on specified version | +| `./scripts/test-all-versions.sh` | Runs tests on all supported versions sequentially | + +### Environment Configuration + +Each PrestaShop version has its own environment file: + +- `.env.ps178` - PrestaShop 1.7.8.11 +- `.env.ps8` - PrestaShop 8.1.7 +- `.env.ps9` - PrestaShop 9.0.0 + +You can create a `.env.local` file to override settings for local development: + +```bash +# .env.local example +PS_VERSION=8.1.7 +CI_ENVIRONMENT_URL=http://localhost:8080 +MYSQL_ROOT_PASSWORD=custom_password +``` + +### Docker Commands + +```bash +# View PrestaShop logs +docker-compose logs prestashop + +# View MySQL logs +docker-compose logs mysql + +# Access PrestaShop container +docker-compose exec prestashop bash + +# Access MySQL container +docker-compose exec mysql mysql -u prestashop -pprestashop prestashop + +# Stop all containers +docker-compose down + +# Stop and remove volumes (clean slate) +docker-compose down -v +``` + +--- + +## Running Tests on Multiple PrestaShop Versions + +### Test All Versions Sequentially + +```bash +./scripts/test-all-versions.sh +``` + +This will: +1. Run tests on PrestaShop 1.7.8 +2. Clean up containers +3. Run tests on PrestaShop 8.x +4. Clean up containers +5. Run tests on PrestaShop 9.x +6. Display a summary of results + +### Test Specific Versions + +```bash +# Test only 1.7.8 and 8.x +for version in 1.7.8 8; do + ./scripts/test-local.sh $version +done +``` + +--- + +## GitHub Actions CI/CD + +### Workflow Overview + +The GitHub Actions workflow (`.github/workflows/eicaptcha-e2e-tests.yml`) runs tests on a matrix of: + +- **PrestaShop versions:** 1.7.8.11, 8.1.7, 9.0.0 +- **PHP versions:** 7.4, 8.1, 8.3 (compatibility-based) +- **MySQL versions:** 5.7, 8.0 + +### Matrix Configuration + +```yaml +matrix: + include: + # PS 1.7.8 with PHP 7.4 & 8.1 + - prestashop: '1.7.8.11' + php: '7.4' + mysql: '5.7' + - prestashop: '1.7.8.11' + php: '8.1' + mysql: '5.7' + + # PS 8.x with PHP 8.1 + - prestashop: '8.1.7' + php: '8.1' + mysql: '8.0' + + # PS 9.x with PHP 8.1 & 8.3 + - prestashop: '9.0.0' + php: '8.1' + mysql: '8.0' + - prestashop: '9.0.0' + php: '8.3' + mysql: '8.0' +``` + +### Triggering Workflows + +**Automatic:** +- Push to `main` or `develop` +- Pull requests affecting the module + +**Manual:** +- Go to **Actions** tab in GitHub +- Select **"eicaptcha E2E Tests"** +- Click **"Run workflow"** + +### Viewing Results + +- **Test Reports:** Uploaded as artifacts (retain for 30 days) +- **Screenshots:** Available on test failures +- Download artifacts from the workflow run page + +--- + +## Project Structure + +``` +modules/eicaptcha/tests/ +├── README.md # This file +└── functionnal/ + ├── docker-compose.yml # Docker services configuration + ├── .env.ps178 # PrestaShop 1.7.8 environment + ├── .env.ps8 # PrestaShop 8.x environment + ├── .env.ps9 # PrestaShop 9.x environment + ├── .gitignore # Git ignore rules + ├── package.json # Node.js dependencies + ├── playwright.config.ts # Playwright configuration + ├── apply_case.php # PHP script to apply test configurations + ├── List.md # Test cases documentation + ├── scripts/ + │ ├── init-prestashop.sh # Initialize PrestaShop + module + │ ├── restore-db.sh # Restore database snapshot + │ ├── test-local.sh # Run tests locally + │ └── test-all-versions.sh # Run tests on all versions + ├── snapshots/ + │ ├── prestashop-1.7.8.x-snapshot.sql + │ ├── prestashop-8.x-snapshot.sql + │ └── prestashop-9.x-snapshot.sql + └── e2e/ + ├── contactForm.spec.ts # Contact form tests + ├── customerRegistrationForm.spec.ts + ├── newsletterForm.spec.ts + └── pages/ + ├── defaultPage.ts # Base page object + ├── contactFormPage.ts + ├── customerRegistrationPage.ts + └── newsletterPage.ts +``` + +--- + +## Database Snapshots + +### Why Snapshots? + +Database snapshots allow fast test environment resets without reinstalling PrestaShop each time: + +- **Installation**: ~2-3 minutes +- **Snapshot restore**: ~5-10 seconds + +### Creating Snapshots + +Snapshots are automatically created when you run `init-prestashop.sh`: + +```bash +./scripts/init-prestashop.sh 8 +``` + +This generates: `snapshots/prestashop-8.x-snapshot.sql` + +### Restoring Snapshots + +To reset the database to a clean state: + +```bash +./scripts/restore-db.sh 8 +``` + +### Regenerating Snapshots + +If you need to update a snapshot (e.g., after module changes): + +```bash +# Stop containers +docker-compose down -v + +# Reinitialize (creates new snapshot) +./scripts/init-prestashop.sh 8 +``` + +**Note:** Snapshots are gitignored due to their size. Regenerate them locally as needed. + +--- + +## Test Configuration + +### Test Cases + +Tests use predefined configuration cases defined in `apply_case.php`: + +**Contact Form Tests:** +- `C_1`: reCAPTCHA v2 disabled +- `C_2`: reCAPTCHA v2 enabled (guests) +- `C_3`: reCAPTCHA v2 enabled (logged customers exempt) +- `C_4`: reCAPTCHA v2 with German language +- `C_5`: reCAPTCHA v2 with dark theme +- `C_6`: reCAPTCHA v3 enabled +- `C_7`: reCAPTCHA v3 (logged customers exempt) + +**Customer Registration Tests:** +- `CU_1` to `CU_7`: Similar variations for registration form + +**Newsletter Tests:** +- `NL_1` to `NL_7`: Similar variations for newsletter form + +### Test User Credentials + +All tests use a pre-created test user: + +- **Email:** `dev@dev.com` +- **Password:** `dev1234%123` + +This user is created during initialization and included in snapshots. + +### reCAPTCHA Test Keys + +Tests use Google's official test keys: + +**reCAPTCHA v2:** +- Site Key: `6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI` +- Secret Key: `6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe` + +**reCAPTCHA v3:** +- Site Key: `6LfLDMceAAAAAEWfCM1_p3D2CkuPfDnC0R2DE3ZS` +- Secret Key: `6LfLDMceAAAAANazDlF6_Ddhlj5odSwxyzSmdJxr` + +--- + +## Adding New Tests + +### 1. Define Test Configuration + +Add a new case to `apply_case.php`: + +```php +'NEW_1' => [ + 'CAPTCHA_VERSION' => 2, + 'CAPTCHA_PRIVATE_KEY' => $captchaV2SecretKey, + 'CAPTCHA_PUBLIC_KEY' => $captchaV2SiteKey, + 'CAPTCHA_ENABLE_CUSTOM_FORM' => 1, + // ... other settings +], +``` + +### 2. Create Page Object (if needed) + +Create `e2e/pages/customFormPage.ts`: + +```typescript +import { DefaultPage } from './defaultPage'; + +export class CustomFormPage extends DefaultPage { + protected pageUrl = 'en/custom-form'; + + async fillAndSubmitForm() { + // Test logic here + } +} +``` + +### 3. Write Test Spec + +Create `e2e/customForm.spec.ts`: + +```typescript +import { test, expect } from '@playwright/test'; +import { CustomFormPage } from './pages/customFormPage'; + +test.describe.configure({ mode: 'serial' }); + +test.describe('Custom Form reCAPTCHA', () => { + test('Case NEW_1', async ({ page }) => { + const customFormPage = new CustomFormPage(page); + await customFormPage.applyConfiguration('NEW_1'); + await customFormPage.goto(); + await customFormPage.fillAndSubmitForm(); + await customFormPage.assertSuccessMessage(); + }); +}); +``` + +### 4. Run New Tests + +```bash +./scripts/test-local.sh 8 +``` + +--- + +## Troubleshooting + +### PrestaShop Container Won't Start + +**Problem:** `docker-compose logs prestashop` shows errors + +**Solutions:** +```bash +# Clean restart +docker-compose down -v +./scripts/init-prestashop.sh 8 + +# Check logs +docker-compose logs -f prestashop +``` + +### Tests Fail to Connect to PrestaShop + +**Problem:** `Error: page.goto: net::ERR_CONNECTION_REFUSED` + +**Solutions:** +```bash +# Verify PrestaShop is running +curl http://localhost:8080/ + +# Check if port is available +lsof -i :8080 + +# Restart containers +docker-compose restart prestashop +``` + +### Database Connection Issues + +**Problem:** MySQL errors during initialization + +**Solutions:** +```bash +# Wait longer for MySQL +docker-compose logs mysql + +# Manually check MySQL +docker-compose exec mysql mysql -u prestashop -pprestashop -e "SHOW DATABASES;" + +# Reset MySQL +docker-compose down -v +docker-compose up -d mysql +``` + +### Module Not Found in Tests + +**Problem:** `apply_case.php` can't load `config.inc.php` + +**Solution:** +The script tries multiple paths automatically. If it still fails: + +```bash +# Check module mounting +docker-compose exec prestashop ls -la /var/www/html/modules/eicaptcha + +# Verify volume mapping in docker-compose.yml +``` + +### Playwright Browser Issues + +**Problem:** Playwright can't find browsers + +**Solutions:** +```bash +# Install Playwright browsers +npx playwright install firefox + +# Install system dependencies +npx playwright install-deps firefox +``` + +### Snapshot Restore Fails + +**Problem:** Database restore errors + +**Solutions:** +```bash +# Check snapshot exists +ls -lh snapshots/ + +# Regenerate snapshot +docker-compose down -v +./scripts/init-prestashop.sh 8 + +# Manual restore +docker-compose exec -T mysql mysql -u prestashop -pprestashop prestashop < snapshots/prestashop-8.x-snapshot.sql +``` + +### Tests Run Sequentially Too Slowly + +**Problem:** Tests take too long + +**Optimization:** +```bash +# Run specific test file +npx playwright test contactForm.spec.ts --workers=1 + +# Run specific test case +npx playwright test -g "Case C_2" --workers=1 +``` + +### Clean Slate Reset + +When all else fails: + +```bash +# Nuclear option: remove everything and start fresh +docker-compose down -v +rm -rf node_modules playwright-report test-results +npm install +npx playwright install firefox +./scripts/init-prestashop.sh 8 +./scripts/test-local.sh 8 +``` + +--- + +## Support and Contributions + +### Reporting Issues + +If you encounter bugs or have feature requests: + +1. Check the [Troubleshooting](#troubleshooting) section +2. Review existing GitHub issues +3. Open a new issue with: + - PrestaShop version + - PHP version + - Steps to reproduce + - Error logs + +### Contributing + +Contributions are welcome! Please: + +1. Fork the repository +2. Create a feature branch +3. Add tests for new functionality +4. Ensure all tests pass locally +5. Submit a pull request + +--- + +## Additional Resources + +- [Playwright Documentation](https://playwright.dev/docs/intro) +- [PrestaShop Documentation](https://devdocs.prestashop-project.org/) +- [reCAPTCHA Documentation](https://developers.google.com/recaptcha/docs/display) +- [Docker Compose Reference](https://docs.docker.com/compose/) + +--- + +**Last Updated:** 2025-01-19 diff --git a/tests/functionnal/.env.ps178 b/tests/functionnal/.env.ps178 new file mode 100644 index 0000000..7e9ec55 --- /dev/null +++ b/tests/functionnal/.env.ps178 @@ -0,0 +1,22 @@ +# PrestaShop 1.7.8.x Test Environment Configuration + +# PrestaShop Version +PS_VERSION=1.7.8.11 + +# Database Configuration +MYSQL_ROOT_PASSWORD=prestashop +MYSQL_DATABASE=prestashop +MYSQL_USER=prestashop +MYSQL_PASSWORD=prestashop + +# PrestaShop Admin Configuration +ADMIN_MAIL=admin@prestashop.local +ADMIN_PASSWD=Prestashop123 + +# Test Environment URL (for Playwright tests) +# Use http://localhost:8080 when running tests from host machine +# Use http://prestashop:80 when running tests inside Docker +CI_ENVIRONMENT_URL=http://localhost:8080 + +# Snapshot to restore +SNAPSHOT_FILE=prestashop-1.7.8.x-snapshot.sql diff --git a/tests/functionnal/.env.ps8 b/tests/functionnal/.env.ps8 new file mode 100644 index 0000000..5c525ea --- /dev/null +++ b/tests/functionnal/.env.ps8 @@ -0,0 +1,22 @@ +# PrestaShop 8.x Test Environment Configuration + +# PrestaShop Version +PS_VERSION=8.1.7 + +# Database Configuration +MYSQL_ROOT_PASSWORD=prestashop +MYSQL_DATABASE=prestashop +MYSQL_USER=prestashop +MYSQL_PASSWORD=prestashop + +# PrestaShop Admin Configuration +ADMIN_MAIL=admin@prestashop.local +ADMIN_PASSWD=Prestashop123 + +# Test Environment URL (for Playwright tests) +# Use http://localhost:8080 when running tests from host machine +# Use http://prestashop:80 when running tests inside Docker +CI_ENVIRONMENT_URL=http://localhost:8080 + +# Snapshot to restore +SNAPSHOT_FILE=prestashop-8.x-snapshot.sql diff --git a/tests/functionnal/.env.ps9 b/tests/functionnal/.env.ps9 new file mode 100644 index 0000000..e17fab8 --- /dev/null +++ b/tests/functionnal/.env.ps9 @@ -0,0 +1,22 @@ +# PrestaShop 9.x Test Environment Configuration + +# PrestaShop Version +PS_VERSION=9.0.0 + +# Database Configuration +MYSQL_ROOT_PASSWORD=prestashop +MYSQL_DATABASE=prestashop +MYSQL_USER=prestashop +MYSQL_PASSWORD=prestashop + +# PrestaShop Admin Configuration +ADMIN_MAIL=admin@prestashop.local +ADMIN_PASSWD=Prestashop123 + +# Test Environment URL (for Playwright tests) +# Use http://localhost:8080 when running tests from host machine +# Use http://prestashop:80 when running tests inside Docker +CI_ENVIRONMENT_URL=http://localhost:8080 + +# Snapshot to restore +SNAPSHOT_FILE=prestashop-9.x-snapshot.sql diff --git a/tests/functionnal/.gitignore b/tests/functionnal/.gitignore index 6619af3..fdb3b4f 100644 --- a/tests/functionnal/.gitignore +++ b/tests/functionnal/.gitignore @@ -1,5 +1,19 @@ -/node_modules/ -/test-results/ -/playwright-report/ -/playwright/.cache/ -/.env \ No newline at end of file +# Local environment overrides +.env +.env.local +.nvmrc + +# Database snapshots (can be large, regenerate as needed) +snapshots/*.sql + +# Playwright +playwright-report/ +test-results/ +playwright/.cache/ + +# Node modules +node_modules/ + +# OS files +.DS_Store +Thumbs.db diff --git a/tests/functionnal/apply_case.php b/tests/functionnal/apply_case.php index 938257f..7f8a740 100644 --- a/tests/functionnal/apply_case.php +++ b/tests/functionnal/apply_case.php @@ -1,7 +1,37 @@ ' . + 'Error: Could not find config.inc.php in any expected location.
' . + 'Searched paths:
' . implode('
', $possiblePaths) . + ''); +} //Check Eicaptcha version $eicaptcha = Module::getInstanceByName('eicaptcha'); diff --git a/tests/functionnal/docker-compose.yml b/tests/functionnal/docker-compose.yml new file mode 100644 index 0000000..ecd4e04 --- /dev/null +++ b/tests/functionnal/docker-compose.yml @@ -0,0 +1,87 @@ +version: '3.8' + +services: + mysql: + image: mysql:8.0 + container_name: prestashop-mysql-test + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-prestashop} + MYSQL_DATABASE: ${MYSQL_DATABASE:-prestashop} + MYSQL_USER: ${MYSQL_USER:-prestashop} + MYSQL_PASSWORD: ${MYSQL_PASSWORD:-prestashop} + volumes: + - mysql_data:/var/lib/mysql + - ./snapshots:/docker-entrypoint-initdb.d + ports: + - "3307:3306" + networks: + - prestashop_network + healthcheck: + test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-prestashop}"] + interval: 10s + timeout: 5s + retries: 5 + + prestashop: + image: prestashop/prestashop:${PS_VERSION:-8.1.7} + container_name: prestashop-test + depends_on: + mysql: + condition: service_healthy + environment: + DB_SERVER: mysql + DB_NAME: ${MYSQL_DATABASE:-prestashop} + DB_USER: ${MYSQL_USER:-prestashop} + DB_PASSWD: ${MYSQL_PASSWORD:-prestashop} + DB_PREFIX: ps_ + PS_DOMAIN: localhost:8080 + PS_FOLDER_INSTALL: install-dev + PS_FOLDER_ADMIN: admin-dev + PS_LANGUAGE: en + PS_COUNTRY: FR + PS_DEV_MODE: 1 + PS_ENABLE_SSL: 0 + ADMIN_MAIL: ${ADMIN_MAIL:-admin@prestashop.local} + ADMIN_PASSWD: ${ADMIN_PASSWD:-Prestashop123} + volumes: + # Mount the eicaptcha module from the local directory + - ../../:/var/www/html/modules/eicaptcha + # Persistent PrestaShop data + - prestashop_data:/var/www/html + ports: + - "8080:80" + networks: + - prestashop_network + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost/en/"] + interval: 15s + timeout: 10s + retries: 10 + start_period: 60s + + playwright: + image: mcr.microsoft.com/playwright:v1.32.3-focal + container_name: prestashop-playwright + depends_on: + prestashop: + condition: service_healthy + working_dir: /app + environment: + CI_ENVIRONMENT_URL: ${CI_ENVIRONMENT_URL:-http://prestashop:80} + NODE_ENV: test + volumes: + - .:/app + - /app/node_modules + networks: + - prestashop_network + command: npx playwright test --workers=1 + profiles: + - test + +volumes: + mysql_data: + prestashop_data: + +networks: + prestashop_network: + driver: bridge diff --git a/tests/functionnal/e2e/pages/defaultPage.ts b/tests/functionnal/e2e/pages/defaultPage.ts index 749a6e8..7ecf675 100644 --- a/tests/functionnal/e2e/pages/defaultPage.ts +++ b/tests/functionnal/e2e/pages/defaultPage.ts @@ -15,7 +15,7 @@ export abstract class DefaultPage { protected readonly loginPasswordSelector: string = '#field-password'; protected readonly loginSubmitSelector: string = '#submit-login'; protected readonly loginEmail:string = 'dev@dev.com'; - protected readonly loginPassword:string = 'dev1234'; + protected readonly loginPassword:string = 'dev1234%123'; //Configuration page protected configurationPageUrl: string = 'modules/eicaptcha/tests/functionnal/apply_case.php?test_case='; diff --git a/tests/functionnal/package-lock.json b/tests/functionnal/package-lock.json index bb51ebe..7b51799 100644 --- a/tests/functionnal/package-lock.json +++ b/tests/functionnal/package-lock.json @@ -1,81 +1,45 @@ { "name": "functionnal", "version": "1.0.0", - "lockfileVersion": 3, + "lockfileVersion": 1, "requires": true, - "packages": { - "": { - "name": "functionnal", - "version": "1.0.0", - "license": "ISC", - "dependencies": { - "dotenv": "^16.3.1" - }, - "devDependencies": { - "@playwright/test": "^1.32.3" - } - }, - "node_modules/@playwright/test": { + "dependencies": { + "@playwright/test": { "version": "1.32.3", "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.32.3.tgz", "integrity": "sha512-BvWNvK0RfBriindxhLVabi8BRe3X0J9EVjKlcmhxjg4giWBD/xleLcg2dz7Tx0agu28rczjNIPQWznwzDwVsZQ==", "dev": true, - "dependencies": { + "requires": { "@types/node": "*", + "fsevents": "2.3.2", "playwright-core": "1.32.3" }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=14" - }, - "optionalDependencies": { - "fsevents": "2.3.2" - } - }, - "node_modules/@playwright/test/node_modules/playwright-core": { - "version": "1.32.3", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.32.3.tgz", - "integrity": "sha512-SB+cdrnu74ZIn5Ogh/8278ngEh9NEEV0vR4sJFmK04h2iZpybfbqBY0bX6+BLYWVdV12JLLI+JEFtSnYgR+mWg==", - "dev": true, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=14" + "dependencies": { + "playwright-core": { + "version": "1.32.3", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.32.3.tgz", + "integrity": "sha512-SB+cdrnu74ZIn5Ogh/8278ngEh9NEEV0vR4sJFmK04h2iZpybfbqBY0bX6+BLYWVdV12JLLI+JEFtSnYgR+mWg==", + "dev": true + } } }, - "node_modules/@types/node": { + "@types/node": { "version": "18.15.11", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz", "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==", "dev": true }, - "node_modules/dotenv": { + "dotenv": { "version": "16.3.1", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", - "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/motdotla/dotenv?sponsor=1" - } + "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==" }, - "node_modules/fsevents": { + "fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } + "optional": true } } } diff --git a/tests/functionnal/playwright.config.ts b/tests/functionnal/playwright.config.ts index 3ca564c..9b20a4b 100644 --- a/tests/functionnal/playwright.config.ts +++ b/tests/functionnal/playwright.config.ts @@ -1,10 +1,33 @@ import { defineConfig, devices } from '@playwright/test'; +import * as dotenv from 'dotenv'; +import * as path from 'path'; /** * Read environment variables from file. - * https://github.com/motdotla/dotenv + * Supports multiple .env files for different PrestaShop versions + * Priority: .env.local > .env.ps[version] > .env */ -require('dotenv').config(); +const envFiles = [ + '.env.local', // Local overrides (gitignored) + '.env.ps178', // PrestaShop 1.7.8 + '.env.ps8', // PrestaShop 8.x + '.env.ps9', // PrestaShop 9.x + '.env', // Default +]; + +// Load the first env file that exists +for (const envFile of envFiles) { + const envPath = path.resolve(__dirname, envFile); + try { + const result = dotenv.config({ path: envPath }); + if (!result.error) { + console.log(`✓ Loaded environment from: ${envFile}`); + break; + } + } catch (error) { + // File doesn't exist, try next one + } +} /** * See https://playwright.dev/docs/test-configuration. @@ -15,12 +38,13 @@ export default defineConfig({ forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, workers: 1, - reporter: 'html', + reporter: process.env.CI ? 'github' : 'html', use: { /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: process.env.CI_ENVIRONMENT_URL, // Will need to be replaced by a CI or a local url to test + baseURL: process.env.CI_ENVIRONMENT_URL || 'http://localhost:8080', trace: 'on-first-retry', screenshot: 'only-on-failure', + video: process.env.CI ? 'retain-on-failure' : 'off', }, /* Configure projects for major browsers */ projects: [ diff --git a/tests/functionnal/scripts/init-prestashop.sh b/tests/functionnal/scripts/init-prestashop.sh new file mode 100755 index 0000000..d1acb90 --- /dev/null +++ b/tests/functionnal/scripts/init-prestashop.sh @@ -0,0 +1,116 @@ +#!/bin/bash +set -e + +# Script to initialize PrestaShop with eicaptcha module +# Usage: ./init-prestashop.sh [version] +# Example: ./init-prestashop.sh 8 + +VERSION=${1:-8} + +echo "=========================================" +echo "PrestaShop Test Environment Setup" +echo "Version: ${VERSION}" +echo "=========================================" + +# Load environment variables based on version +case $VERSION in + 1.7.8|178) + ENV_FILE=".env.ps178" + ;; + 8) + ENV_FILE=".env.ps8" + ;; + 9) + ENV_FILE=".env.ps9" + ;; + *) + echo "Error: Unknown version '${VERSION}'" + echo "Usage: $0 [1.7.8|8|9]" + exit 1 + ;; +esac + +if [ ! -f "$ENV_FILE" ]; then + echo "Error: Environment file $ENV_FILE not found" + exit 1 +fi + +echo "Loading environment from $ENV_FILE..." +export $(grep -v '^#' $ENV_FILE | xargs) + +# Start Docker Compose +echo "Starting Docker containers..." +docker-compose --env-file $ENV_FILE up -d mysql prestashop + +# Wait for MySQL to be ready +echo "Waiting for MySQL to be ready..." +until docker-compose exec -T mysql mysqladmin ping -h localhost -u root -p${MYSQL_ROOT_PASSWORD} --silent; do + echo "MySQL is unavailable - sleeping" + sleep 5 +done +echo "MySQL is ready!" + +# Wait for PrestaShop to be ready +echo "Waiting for PrestaShop to be ready..." +sleep 10 +until docker-compose exec -T prestashop curl -f http://localhost/ > /dev/null 2>&1; do + echo "PrestaShop is unavailable - sleeping" + sleep 10 +done +echo "PrestaShop is ready!" + +# Install eicaptcha module +echo "Installing eicaptcha module..." +docker-compose exec -T prestashop php bin/console prestashop:module install eicaptcha || { + echo "Warning: Module installation via console failed. Trying alternative method..." + # Alternative: use PrestaShop admin or module installer +} + +# Create test user (dev@dev.com / dev1234%123) +echo "Creating test user..." +docker-compose exec -T prestashop php -r " +require_once '/var/www/html/config/config.inc.php'; + +\$customer = new Customer(); +\$customer->firstname = 'Dev'; +\$customer->lastname = 'Test'; +\$customer->email = 'dev@dev.com'; +\$customer->passwd = Tools::hash('dev1234%123'); +\$customer->id_gender = 1; +\$customer->birthday = '1990-01-01'; +\$customer->newsletter = 1; +\$customer->active = 1; + +if (\$customer->add()) { + echo 'Test customer created successfully!'; +} else { + echo 'Customer may already exist or creation failed.'; +} +" || echo "Customer creation skipped (may already exist)" + +# Export database snapshot +echo "Creating database snapshot..." +SNAPSHOT_DIR="./snapshots" +mkdir -p $SNAPSHOT_DIR + +docker-compose exec -T mysql mysqldump \ + -u ${MYSQL_USER} \ + -p${MYSQL_PASSWORD} \ + ${MYSQL_DATABASE} \ + > "${SNAPSHOT_DIR}/${SNAPSHOT_FILE}" + +echo "=========================================" +echo "Setup completed successfully!" +echo "Snapshot saved to: ${SNAPSHOT_DIR}/${SNAPSHOT_FILE}" +echo "=========================================" +echo "" +echo "Test user credentials:" +echo " Email: dev@dev.com" +echo " Password: dev1234%123" +echo "" +echo "PrestaShop admin:" +echo " URL: http://localhost:8080/admin-dev" +echo " Email: ${ADMIN_MAIL}" +echo " Password: ${ADMIN_PASSWD}" +echo "" +echo "You can now run tests with: ./scripts/test-local.sh ${VERSION}" diff --git a/tests/functionnal/scripts/restore-db.sh b/tests/functionnal/scripts/restore-db.sh new file mode 100755 index 0000000..e535c17 --- /dev/null +++ b/tests/functionnal/scripts/restore-db.sh @@ -0,0 +1,94 @@ +#!/bin/bash +set -e + +# Script to restore database snapshot +# Usage: ./restore-db.sh [version] +# Example: ./restore-db.sh 8 + +VERSION=${1:-8} + +echo "=========================================" +echo "Restoring PrestaShop Database Snapshot" +echo "Version: ${VERSION}" +echo "=========================================" + +# Load environment variables based on version +case $VERSION in + 1.7.8|178) + ENV_FILE=".env.ps178" + ;; + 8) + ENV_FILE=".env.ps8" + ;; + 9) + ENV_FILE=".env.ps9" + ;; + *) + echo "Error: Unknown version '${VERSION}'" + echo "Usage: $0 [1.7.8|8|9]" + exit 1 + ;; +esac + +if [ ! -f "$ENV_FILE" ]; then + echo "Error: Environment file $ENV_FILE not found" + exit 1 +fi + +echo "Loading environment from $ENV_FILE..." +export $(grep -v '^#' $ENV_FILE | xargs) + +# Check if snapshot exists +SNAPSHOT_PATH="./snapshots/${SNAPSHOT_FILE}" +if [ ! -f "$SNAPSHOT_PATH" ]; then + echo "Error: Snapshot file not found: $SNAPSHOT_PATH" + echo "" + echo "Please create the snapshot first by running:" + echo " ./scripts/init-prestashop.sh ${VERSION}" + exit 1 +fi + +# Ensure MySQL is running +echo "Checking MySQL container..." +if ! docker-compose ps mysql | grep -q "Up"; then + echo "Starting MySQL container..." + docker-compose --env-file $ENV_FILE up -d mysql + + echo "Waiting for MySQL to be ready..." + sleep 10 + until docker-compose exec -T mysql mysqladmin ping -h localhost -u root -p${MYSQL_ROOT_PASSWORD} --silent; do + echo "MySQL is unavailable - sleeping" + sleep 5 + done +fi + +echo "Dropping and recreating database..." +docker-compose exec -T mysql mysql -u root -p${MYSQL_ROOT_PASSWORD} -e " + DROP DATABASE IF EXISTS ${MYSQL_DATABASE}; + CREATE DATABASE ${MYSQL_DATABASE}; +" + +echo "Restoring database from snapshot..." +docker-compose exec -T mysql mysql -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} < "$SNAPSHOT_PATH" + +echo "=========================================" +echo "Database restored successfully!" +echo "=========================================" + +# Restart PrestaShop container to clear cache +if docker-compose ps prestashop | grep -q "Up"; then + echo "Restarting PrestaShop container..." + docker-compose restart prestashop + + echo "Waiting for PrestaShop to be ready..." + sleep 10 + until docker-compose exec -T prestashop curl -f http://localhost/ > /dev/null 2>&1; do + echo "PrestaShop is starting - sleeping" + sleep 5 + done + + echo "PrestaShop is ready!" +fi + +echo "" +echo "You can now run tests with: ./scripts/test-local.sh ${VERSION}" diff --git a/tests/functionnal/scripts/test-all-versions.sh b/tests/functionnal/scripts/test-all-versions.sh new file mode 100755 index 0000000..4c33fe4 --- /dev/null +++ b/tests/functionnal/scripts/test-all-versions.sh @@ -0,0 +1,72 @@ +#!/bin/bash +set -e + +# Script to run E2E tests on all PrestaShop versions +# Usage: ./test-all-versions.sh [playwright-options] +# Example: ./test-all-versions.sh +# Example: ./test-all-versions.sh --headed + +echo "=========================================" +echo "Running E2E Tests on All Versions" +echo "=========================================" + +VERSIONS=("1.7.8" "8" "9") +FAILED_VERSIONS=() +PASSED_VERSIONS=() + +# Store additional playwright arguments +PLAYWRIGHT_ARGS="$@" + +for VERSION in "${VERSIONS[@]}"; do + echo "" + echo "=========================================" + echo "Testing PrestaShop ${VERSION}" + echo "=========================================" + + # Stop any running containers first + docker-compose down 2>/dev/null || true + + # Run tests for this version + if ./scripts/test-local.sh $VERSION $PLAYWRIGHT_ARGS; then + PASSED_VERSIONS+=("$VERSION") + echo "✓ PrestaShop ${VERSION} tests PASSED" + else + FAILED_VERSIONS+=("$VERSION") + echo "✗ PrestaShop ${VERSION} tests FAILED" + fi + + # Clean up containers after each version + echo "Cleaning up containers..." + docker-compose down 2>/dev/null || true + sleep 5 +done + +# Summary +echo "" +echo "=========================================" +echo "Test Summary" +echo "=========================================" + +if [ ${#PASSED_VERSIONS[@]} -gt 0 ]; then + echo "" + echo "✓ PASSED (${#PASSED_VERSIONS[@]} versions):" + for VERSION in "${PASSED_VERSIONS[@]}"; do + echo " - PrestaShop ${VERSION}" + done +fi + +if [ ${#FAILED_VERSIONS[@]} -gt 0 ]; then + echo "" + echo "✗ FAILED (${#FAILED_VERSIONS[@]} versions):" + for VERSION in "${FAILED_VERSIONS[@]}"; do + echo " - PrestaShop ${VERSION}" + done + echo "" + echo "To debug failed tests, run:" + echo " ./scripts/test-local.sh --headed" + exit 1 +else + echo "" + echo "All versions passed! 🎉" + exit 0 +fi diff --git a/tests/functionnal/scripts/test-local.sh b/tests/functionnal/scripts/test-local.sh new file mode 100755 index 0000000..6eadb0c --- /dev/null +++ b/tests/functionnal/scripts/test-local.sh @@ -0,0 +1,116 @@ +#!/bin/bash +set -e + +# Script to run E2E tests locally with Docker +# Usage: ./test-local.sh [version] [options] +# Example: ./test-local.sh 8 +# Example: ./test-local.sh 8 --headed +# Example: ./test-local.sh 8 --debug + +VERSION=${1:-8} +shift || true # Remove first argument (version) from $@ + +echo "=========================================" +echo "Running E2E Tests" +echo "PrestaShop Version: ${VERSION}" +echo "=========================================" + +# Load environment variables based on version +case $VERSION in + 1.7.8|178) + ENV_FILE=".env.ps178" + ;; + 8) + ENV_FILE=".env.ps8" + ;; + 9) + ENV_FILE=".env.ps9" + ;; + *) + echo "Error: Unknown version '${VERSION}'" + echo "Usage: $0 [1.7.8|8|9] [playwright-options]" + exit 1 + ;; +esac + +if [ ! -f "$ENV_FILE" ]; then + echo "Error: Environment file $ENV_FILE not found" + exit 1 +fi + +echo "Loading environment from $ENV_FILE..." +export $(grep -v '^#' $ENV_FILE | xargs) + +# Start PrestaShop and MySQL +echo "Starting Docker containers..." +docker-compose --env-file $ENV_FILE up -d mysql prestashop + +# Wait for MySQL to be ready +echo "Waiting for MySQL to be ready..." +until docker-compose exec -T mysql mysqladmin ping -h localhost -u root -p${MYSQL_ROOT_PASSWORD} --silent 2>/dev/null; do + echo "MySQL is unavailable - sleeping" + sleep 5 +done +echo "MySQL is ready!" + +# Wait for PrestaShop to be ready +echo "Waiting for PrestaShop to be ready..." +sleep 10 +MAX_ATTEMPTS=30 +ATTEMPT=0 +until docker-compose exec -T prestashop curl -f http://localhost/ > /dev/null 2>&1; do + ATTEMPT=$((ATTEMPT + 1)) + if [ $ATTEMPT -ge $MAX_ATTEMPTS ]; then + echo "Error: PrestaShop failed to start after ${MAX_ATTEMPTS} attempts" + docker-compose logs prestashop + exit 1 + fi + echo "PrestaShop is starting (attempt ${ATTEMPT}/${MAX_ATTEMPTS}) - sleeping" + sleep 10 +done +echo "PrestaShop is ready!" + +# Check if node_modules exists, if not install dependencies +if [ ! -d "node_modules" ]; then + echo "Installing npm dependencies..." + npm install +fi + +# Install Playwright browsers if not already installed +echo "Checking Playwright browsers..." +npx playwright install firefox || echo "Playwright browsers already installed" + +# Run tests from host machine (not in Docker for better debugging) +echo "" +echo "=========================================" +echo "Running Playwright tests..." +echo "=========================================" + +# Pass additional arguments to playwright +npx playwright test --workers=1 "$@" + +TEST_EXIT_CODE=$? + +echo "" +echo "=========================================" +echo "Test Results" +echo "=========================================" + +if [ $TEST_EXIT_CODE -eq 0 ]; then + echo "✓ All tests passed!" +else + echo "✗ Some tests failed (exit code: $TEST_EXIT_CODE)" + echo "" + echo "To view the test report, run:" + echo " npx playwright show-report" +fi + +echo "" +echo "To stop the containers, run:" +echo " docker-compose down" +echo "" +echo "To view logs:" +echo " docker-compose logs prestashop" +echo " docker-compose logs mysql" + +exit $TEST_EXIT_CODE diff --git a/tests/functionnal/snapshots/.gitkeep b/tests/functionnal/snapshots/.gitkeep new file mode 100644 index 0000000..e69de29