forked from bagisto/bagisto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request bagisto#10419 from kartikeywebkul9260/master
✨ [master] added recorded test cases using playwright
- Loading branch information
Showing
44 changed files
with
5,548 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
name: Bagisto Playwright Tests | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 180 | ||
|
||
services: | ||
mysql: | ||
image: mysql:8.0 | ||
env: | ||
MYSQL_ROOT_PASSWORD: webkul | ||
MYSQL_DATABASE: bagisto-test | ||
ports: | ||
- 3306:3306 | ||
options: >- | ||
--health-cmd="mysqladmin ping -h 127.0.0.1 -u root -pwebkul" | ||
--health-interval=10s | ||
--health-timeout=5s | ||
--health-retries=5 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install system dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y mysql-client netcat-openbsd net-tools | ||
- name: Wait for MySQL | ||
run: | | ||
echo "Waiting for MySQL..." | ||
max_attempts=30 | ||
attempt=0 | ||
until mysqladmin ping -h 127.0.0.1 -uroot -pwebkul --silent; do | ||
if [ $attempt -ge $max_attempts ]; then | ||
echo "MySQL failed to start in time." | ||
exit 1 | ||
fi | ||
echo "Waiting for MySQL... (attempt $((attempt+1))/$max_attempts)" | ||
sleep 2 | ||
((attempt++)) | ||
done | ||
- name: Configure MySQL user privileges | ||
run: | | ||
mysql -h 127.0.0.1 -uroot -pwebkul -e " | ||
CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY 'webkul'; | ||
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; | ||
FLUSH PRIVILEGES; | ||
" | ||
- name: Set up application environment | ||
run: | | ||
cp .env.example .env | ||
sed -i 's#DB_HOST=.*#DB_HOST=127.0.0.1#' .env | ||
sed -i 's#DB_PORT=.*#DB_PORT=3306#' .env | ||
sed -i 's#DB_DATABASE=.*#DB_DATABASE=bagisto-test#' .env | ||
sed -i 's#DB_USERNAME=.*#DB_USERNAME=root#' .env | ||
sed -i 's#DB_PASSWORD=.*#DB_PASSWORD=webkul#' .env | ||
sed -i 's#APP_DEBUG=.*#APP_DEBUG=false#' .env | ||
sed -i 's|APP_URL=.*|APP_URL=http://127.0.0.1:8000/|' .env | ||
- name: Install PHP and dependencies | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.3' | ||
extensions: mbstring, intl, bcmath, gd, pdo_mysql, mysql | ||
tools: composer | ||
|
||
- name: Install Composer dependencies | ||
run: composer install | ||
|
||
- name: Test MySQL Connectivity | ||
run: | | ||
echo "Testing MySQL connection..." | ||
php -r " | ||
try { | ||
\$pdo = new PDO('mysql:host=127.0.0.1;dbname=bagisto-test', 'root', 'webkul'); | ||
echo 'Connected to MySQL successfully!'; | ||
} catch (PDOException \$e) { | ||
echo 'Connection failed: ' . \$e->getMessage(); | ||
exit(1); | ||
} | ||
" | ||
- name: Install Bagisto | ||
run: | | ||
# Run the bagisto:create command to create a new project | ||
composer create | ||
# Install Bagisto | ||
php artisan bagisto:install --no-interaction | ||
- name: Run Laravel migrations | ||
run: | | ||
php artisan key:generate | ||
php artisan migrate --seed | ||
env: | ||
DB_HOST: 127.0.0.1 | ||
DB_PORT: 3306 | ||
DB_DATABASE: bagisto-test | ||
DB_USERNAME: root | ||
DB_PASSWORD: webkul | ||
APP_DEBUG: false | ||
APP_URL: http://127.0.0.1:8000 | ||
|
||
- name: Seed Product Table | ||
run: php artisan db:seed --class="Webkul\\Installer\\Database\\Seeders\\ProductTableSeeder" | ||
|
||
- name: Start Laravel server | ||
run: nohup php artisan serve --host=0.0.0.0 --port=8000 > /dev/null 2>&1 & | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
|
||
- name: Install Node.js dependencies | ||
run: npm install | ||
|
||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
|
||
- name: Run All Playwright Tests | ||
env: | ||
BASE_URL: 'http://127.0.0.1:8000' | ||
run: | | ||
npx playwright test tests --workers=1 --project=chromium --retries=0 || echo "Continue" | ||
- name: Upload Playwright Report for All Tests | ||
uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report-All-Tests | ||
path: playwright-report/ | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,5 @@ package-lock.json | |
/vendor | ||
yarn.lock | ||
yarn-error.log | ||
/test-results | ||
/playwright-report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// config.js | ||
const config = { | ||
// The base URL of the application under test | ||
baseUrl: process.env.APP_URL || 'http://dev1.amit.com', | ||
|
||
// Admin credentials | ||
adminEmail: process.env.ADMIN_EMAIL || '[email protected]', | ||
adminPassword: process.env.ADMIN_PASSWORD || 'admin123', | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
{ | ||
"private": true, | ||
"type": "module", | ||
|
||
"name": "my-playwright-tests", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"description": "", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build" | ||
"build": "vite build", | ||
"test": "npx playwright test" | ||
}, | ||
"devDependencies": { | ||
"axios": "^1.7.4", | ||
"laravel-vite-plugin": "^1.0", | ||
"vite": "^5.0" | ||
"vite": "^5.0", | ||
"@playwright/test": "^1.48.1", | ||
"@types/node": "^22.7.8" | ||
}, | ||
"dependencies": { | ||
"playwright": "^1.48.1", | ||
"readline-sync": "^1.4.10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// import dotenv from 'dotenv'; | ||
// import path from 'path'; | ||
// dotenv.config({ path: path.resolve(__dirname, '.env') }); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './tests', | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'html', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://127.0.0.1:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
|
||
{ | ||
name: 'webkit', | ||
use: { ...devices['Desktop Safari'] }, | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { test, expect, config } from '../utils/setup'; | ||
|
||
test('Login', async ({page}) => { | ||
await page.goto(`${config.baseUrl}/admin/login`); | ||
await page.getByPlaceholder('Email Address').click(); | ||
await page.getByPlaceholder('Email Address').fill(config.adminEmail); | ||
await page.getByPlaceholder('Password').click(); | ||
await page.getByPlaceholder('Password').fill(config.adminPassword); | ||
await page.getByLabel('Sign In').click(); | ||
|
||
await expect(page.getByPlaceholder('Mega Search').first()).toBeVisible(); | ||
}); | ||
|
||
test('Logout', async ({page}) => { | ||
await page.goto(`${config.baseUrl}/admin/login`); | ||
await page.getByPlaceholder('Email Address').click(); | ||
await page.getByPlaceholder('Email Address').fill(config.adminEmail); | ||
await page.getByPlaceholder('Password').click(); | ||
await page.getByPlaceholder('Password').fill(config.adminPassword); | ||
await page.getByLabel('Sign In').click(); | ||
await page.getByRole('button', { name: 'E' }).click(); | ||
await page.getByRole('link', { name: 'Logout' }).click(); | ||
await page.waitForTimeout(5000); | ||
|
||
await expect(page.getByPlaceholder('Password').first()).toBeVisible(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { test, expect, config } from '../../utils/setup'; | ||
|
||
test('Delete Attribute Family', async ({page}) => { | ||
await page.goto(`${config.baseUrl}/admin/login`); | ||
await page.getByPlaceholder('Email Address').click(); | ||
await page.getByPlaceholder('Email Address').fill(config.adminEmail); | ||
await page.getByPlaceholder('Password').click(); | ||
await page.getByPlaceholder('Password').fill(config.adminPassword); | ||
await page.getByLabel('Sign In').click(); | ||
await page.getByRole('link', { name: ' Catalog' }).click(); | ||
await page.getByRole('link', { name: 'Attribute Families' }).click(); | ||
await page.locator('div').filter({ hasText: /^1defaultDefault$/ }).locator('span').nth(1).click(); | ||
await page.getByRole('button', { name: 'Agree', exact: true }).click(); | ||
|
||
await expect(page.getByText('Family deleted successfully.')).toBeVisible(); | ||
}); |
Oops, something went wrong.