Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added Playwright testing CI #154

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d4c6b9a
feat: Added playwright testing ci/cd
prtkjakhar Jun 15, 2023
1c23006
feat: Added playwright testing ci
prtkjakhar Jun 15, 2023
3908e34
feat: Added playwright testing ci
prtkjakhar Jun 15, 2023
2efb982
feat: Added playwright testing ci
prtkjakhar Jun 15, 2023
07de1d9
feat: Added playwright testing ci
prtkjakhar Jun 15, 2023
9feb8c7
feat: Added playwright testing ci
prtkjakhar Jun 15, 2023
fc16488
feat: Added playwright testing ci
prtkjakhar Jun 15, 2023
680ca94
feat: Added playwright testing ci
prtkjakhar Jun 15, 2023
d2698e6
fix: increased timeout duration of test
prtkjakhar Jun 15, 2023
71d6faa
fix: increased timeout duration of test
prtkjakhar Jun 15, 2023
df5f2e2
fix: increased timeout duration of test
prtkjakhar Jun 15, 2023
78f6748
fix: increased timeout duration of test
prtkjakhar Jun 15, 2023
fe9edba
fix: increased timeout duration of test
prtkjakhar Jun 15, 2023
a77669d
fix: increased timeout duration of test
prtkjakhar Jun 15, 2023
490eb40
fix: increased timeout duration of test
prtkjakhar Jun 15, 2023
1088cf8
fix: increased timeout duration of test
prtkjakhar Jun 15, 2023
65650d1
fix: increased timeout duration of test
prtkjakhar Jun 15, 2023
5783e3f
fix: increased timeout duration of test
prtkjakhar Jun 15, 2023
96301c0
fix: added logs and screenshot to debug test
prtkjakhar Jun 16, 2023
e15226e
fix: added video logs to test
prtkjakhar Jun 16, 2023
adb425d
fix: added env in yml
prtkjakhar Jun 16, 2023
3cb4f86
fix: added env in yml
prtkjakhar Jun 16, 2023
3844df5
fix: added playwright-report in yml
prtkjakhar Jun 16, 2023
269f619
fix: added playwright-report in yml
prtkjakhar Jun 16, 2023
1ac1dc0
fix: removed playwright-report, added baseUrl in config
prtkjakhar Jun 16, 2023
8289e20
fix: added github actions recorder
prtkjakhar Jun 16, 2023
9af0265
fix: added github actions recorder
prtkjakhar Jun 16, 2023
15bd9ea
fix: removed recorders
prtkjakhar Jun 16, 2023
6365b5d
fix: added report
prtkjakhar Jun 16, 2023
6792c0b
fix: added report
prtkjakhar Jun 16, 2023
155ff38
fix: added environment E2E name
prtkjakhar Jun 16, 2023
aa68a83
fix: added repository secrets
prtkjakhar Jun 17, 2023
3ce02fb
fix: changed test names
prtkjakhar Jun 17, 2023
3538e5e
chore: Added console logs in test file
prtkjakhar Jun 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: E2E Testing

on:
push:
branches: main
pull_request:
branches: main

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci

- name: Install browser binaries
run: npx playwright install --with-deps

- name: Start the dev server and Playwright testing
env:
NEXT_PUBLIC_ENVIRONMENT_ID: ${{secrets.NEXT_PUBLIC_ENVIRONMENT_ID}}
NEXT_PUBLIC_FLAGSMITH_API: ${{secrets.NEXT_PUBLIC_FLAGSMITH_API}}
NEXT_PUBLIC_SOCKET_URL: ${{secrets.NEXT_PUBLIC_SOCKET_URL}}
NEXT_PUBLIC_BASE_URL: ${{secrets.NEXT_PUBLIC_BASE_URL}}
NEXT_PUBLIC_USER_SERVICE_APP_ID: ${{secrets.NEXT_PUBLIC_USER_SERVICE_APP_ID}}
NEXT_PUBLIC_JWKS_URI: ${{secrets.NEXT_PUBLIC_JWKS_URI}}
NEXT_PUBLIC_OTP_BASE_URL: ${{secrets.NEXT_PUBLIC_OTP_BASE_URL}}
NEXT_PUBLIC_FIREBASE_API_KEY: ${{secrets.NEXT_PUBLIC_FIREBASE_API_KEY}}
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: ${{secrets.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN}}
NEXT_PUBLIC_FIREBASE_PROJECT_ID: ${{secrets.NEXT_PUBLIC_FIREBASE_PROJECT_ID}}
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: ${{secrets.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET}}
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: ${{secrets.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID}}
NEXT_PUBLIC_FIREBASE_APP_ID: ${{secrets.NEXT_PUBLIC_FIREBASE_APP_ID}}
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID: ${{secrets.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID}}
NEXT_PUBLIC_FCM_VAPID_KEY: ${{secrets.NEXT_PUBLIC_FCM_VAPID_KEY}}
NEXT_PUBLIC_FUS_APP_ID: ${{secrets.NEXT_PUBLIC_FUS_APP_ID}}
NEXT_PUBLIC_FUS_URL: ${{secrets.NEXT_PUBLIC_FUS_URL}}
NEXT_PUBLIC_FUS_AUTH: ${{secrets.NEXT_PUBLIC_FUS_AUTH}}
NEXT_PUBLIC_DHRUVA_AUTH: ${{secrets.NEXT_PUBLIC_DHRUVA_AUTH}}
NEXT_PUBLIC_TRANSLITERATION_MODELID: ${{secrets.NEXT_PUBLIC_TRANSLITERATION_MODELID}}
run: npm run dev & sleep 65 && npm run e2e:test
- name: Uploading Test Video (can be downloaded from Summary)
uses: actions/upload-artifact@v3
if: always()
with:
name: Test Video
path: test-results
retention-days: 2
1 change: 0 additions & 1 deletion apps/amakrushi/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Unified Communication Interface
[![ci](https://github.com/samagra-comms/uci-web-channel/actions/workflows/ci.yml/badge.svg)](https://github.com/samagra-comms/uci-web-channel/actions/workflows/ci.yml)
[![badges](https://github.com/samagra-comms/uci-web-channel/actions/workflows/badges.yml/badge.svg)](https://github.com/samagra-comms/uci-web-channel/actions/workflows/badges.yml)
![cypress version](https://img.shields.io/badge/cypress-9.7.0-brightgreen)

## About UCI :open_book:

Expand Down
8 changes: 3 additions & 5 deletions apps/amakrushi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"lint": "next lint",
"analyze": "cross-env ANALYZE=true next build",
"analyze:server": "cross-env BUNDLE_ANALYZE=server next build",
"analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build"
"analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build",
"e2e:test": "npx playwright test"
},
"dependencies": {
"@chakra-ui/react": "^1.8.8",
"@emotion/react": "^11.7.1",
"@emotion/styled": "^11.6.0",
"@magicbell/magicbell-react": "^8.5.3",
"@material-ui/core": "^4.12.4",
"@next/bundle-analyzer": "^13.3.0",
"@storybook/react": "^6.5.9",
Expand Down Expand Up @@ -55,8 +55,7 @@
"web-vitals": "^2.1.4"
},
"devDependencies": {
"@cypress/react": "^5.12.5",
"@cypress/webpack-dev-server": "^1.8.4",
"@playwright/test": "^1.35.0",
"@storybook/addon-actions": "^6.4.19",
"@storybook/addon-essentials": "^6.4.19",
"@storybook/addon-interactions": "^6.4.19",
Expand All @@ -73,7 +72,6 @@
"@types/react-dom": "^18.0.5",
"@types/underscore": "^1.11.4",
"@types/uuid": "^9.0.1",
"cypress": "^9.7.0",
"dotenv-cli": "^7.2.1",
"eslint": "8.18.0",
"eslint-config-next": "12.1.6",
Expand Down
12 changes: 12 additions & 0 deletions apps/amakrushi/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
testDir: './src/tests/e2e',
outputDir: '../../test-results',
use: {
video: 'on',
baseURL: 'http://localhost:3000',
},
};

export default config;
4 changes: 2 additions & 2 deletions apps/amakrushi/src/components/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const LoginPage: React.FC = () => {

<form onSubmit={(event) => event?.preventDefault()}>
<div className={styles.container}>
<NumberInput style={{ margin: '5vh auto 0px auto', width: '100%' }}>
<NumberInput id='mobile-number-input' style={{ margin: '5vh auto 0px auto', width: '100%' }}>
<NumberInputField
height="45px"
padding="18px 16px"
Expand All @@ -95,7 +95,7 @@ const LoginPage: React.FC = () => {
>
{t("message.register_message")}
</div> */}
<button className={styles.submitButton} onClick={handleOTPPage} disabled={isButtonDisabled}>
<button id='login-continue-button' className={styles.submitButton} onClick={handleOTPPage} disabled={isButtonDisabled}>
{t('label.continue')}
</button>
</div>
Expand Down
74 changes: 74 additions & 0 deletions apps/amakrushi/src/tests/e2e/login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { test, expect } from '@playwright/test';

// This code will run before each test
test.beforeEach(async ({ page }) => {
// Navigate to the login page
await page.goto('http://localhost:3000');
// Wait for the page title to load
await page.waitForLoadState('networkidle');
await page.waitForFunction(() => document.title === 'ଆମ କୃଷି');
});

test('Login Page - Mobile input field', async ({ page }) => {
console.log('1) Running test: Login Page - Mobile input field');
// Find the mobile number input field
const mobileNumberInput = await page.$('#mobile-number-input');
expect(mobileNumberInput).not.toBeNull(); // Assert that the input field exists

if (mobileNumberInput) {
console.log('Mobile input field found successfully! ✅ ');
const inputPlaceholder = await mobileNumberInput.getAttribute(
'placeholder'
);
expect(inputPlaceholder).toBe('ମୋବାଇଲ୍ ନମ୍ବର ପ୍ରବେଶ କରନ୍ତୁ |');
console.log(
'Mobile input field placeholder text matched successfully! ✅ '
);
} else {
throw new Error('Mobile number input field not found.');
}
});

test('Login Page - Less than 10 digits', async ({ page }) => {
console.log('2) Running test: Login Page - Less than 10 digits');
// Find the mobile number input field
const mobileNumberInput = await page.$('#mobile-number-input');
expect(mobileNumberInput).not.toBeNull(); // Assert that the input field exists

if (mobileNumberInput) {
// Enter less than 10 digits in the input field and click continue
await mobileNumberInput.fill('123456789');
const continueButton = await page.$('#login-continue-button');
expect(await continueButton?.innerText()).toBe('ଜାରି ରଖ');
await continueButton?.click();

// Verify the URL remains same after clicking continue
const currentURL = page.url();
expect(currentURL).toBe('http://localhost:3000/login');
console.log('Did not send OTP on entering less than 10 digits! ✅ ');
} else {
throw new Error('Mobile number input field not found.');
}
});

test('Login Page - Send OTP', async ({ page }) => {
console.log('3) Running test: Login Page - Send OTP');
// Find the mobile number input field
const mobileNumberInput = await page.$('#mobile-number-input');
expect(mobileNumberInput).not.toBeNull(); // Assert that the input field exists

if (mobileNumberInput) {
console.log('Running test: Login Page - Send OTP');
// Enter exactly 10 digits in the input field and click continue
await mobileNumberInput.fill('9034350533');
const continueButton = await page.$('#login-continue-button');
await continueButton?.click();

// Verify the URL after clicking continue
const otpURL = new URL('http://localhost:3000/otp?state=9034350533');
await page.waitForURL((url) => url.href.startsWith(otpURL.href));
console.log('Successfully sent OTP on entering 10 digits! ✅ ');
} else {
throw new Error('Mobile number input field not found.');
}
});
Loading