Skip to content

Commit

Permalink
refactor: cleanup playwright tests (freeCodeCamp#51499)
Browse files Browse the repository at this point in the history
  • Loading branch information
ojeytonwilliams authored Sep 8, 2023
1 parent 6c25982 commit 7750cec
Show file tree
Hide file tree
Showing 12 changed files with 485 additions and 319 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/e2e-playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ jobs:
pnpm run build:curriculum
pnpm run build:server
- name: Seed Database
run: pnpm run seed

- name: Seed Database with Certified User
run: pnpm run seed:certified-user

Expand All @@ -141,10 +138,8 @@ jobs:
- name: Install playwright dependencies
run: |
cd ./e2e
npm i
npx playwright install
npx playwright install-deps
cd ..
- name: Run playwright tests
run: |
Expand Down
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,4 @@ curriculum/build

### UI Components ###
tools/ui-components/dist
/test-results/
/playwright-report/
/playwright/.cache/
test-results/
playwright-report/
/playwright/.cache/

4 changes: 4 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/test-results
/playwright-report
/playwright/.cache/
/playwright/.auth
95 changes: 0 additions & 95 deletions e2e/LoginAuth.json

This file was deleted.

4 changes: 3 additions & 1 deletion e2e/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import { test as setup } from '@playwright/test';
setup('Login', async ({ page }) => {
await page.goto('/');
await page.getByRole('link', { name: 'Sign in' }).click();
await page.context().storageState({ path: './LoginAuth.json' });
await page
.context()
.storageState({ path: 'playwright/.auth/certified-user.json' });
});
9 changes: 4 additions & 5 deletions e2e/landing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const superBlocks = [
'College Algebra with Python',
'Foundational C# with Microsoft',
'Coding Interview Prep',
'Project Euler',
'Legacy Responsive Web Design'
'Project Euler'
];

test.beforeAll(async ({ browser }) => {
Expand Down Expand Up @@ -74,10 +73,10 @@ test('Has `as seen in` section', async () => {
test('Has links to all superblocks', async () => {
const curriculumBtns = page.getByTestId(landingPageElements.curriculumBtns);
await expect(curriculumBtns).toHaveCount(15);
superBlocks.map(async (cert, i) => {
for (let i = 0; i < superBlocks.length; i++) {
const btn = curriculumBtns.nth(i);
await expect(btn).toContainText(cert);
});
await expect(btn).toContainText(superBlocks[i]);
}
});

test('Has 3 testimonial cards', async () => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "e2e",
"name": "@freecodecamp/e2e",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "npx playwright test"
},
"author": "",
"license": "ISC",
Expand Down
15 changes: 10 additions & 5 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,32 @@ export default defineConfig({

{
name: 'chromium',
use: { ...devices['Desktop Chrome'] }
use: { ...devices['Desktop Chrome'] },
dependencies: ['setup']
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] }
use: { ...devices['Desktop Firefox'] },
dependencies: ['setup']
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] }
use: { ...devices['Desktop Safari'] },
dependencies: ['setup']
},

/* Test against mobile viewports. */
{
name: 'Mobile Chrome',
use: { ...devices['Pixel 5'] }
use: { ...devices['Pixel 5'] },
dependencies: ['setup']
},
{
name: 'Mobile Safari',
use: { ...devices['iPhone 12'] }
use: { ...devices['iPhone 12'] },
dependencies: ['setup']
}
/* Uncomment the blocks out if you want to enable the mentioned features */
/* ====================================================== */
Expand Down
18 changes: 9 additions & 9 deletions e2e/show-certificate-own.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect, type Page } from '@playwright/test';

test.use({ storageState: 'LoginAuth.json' });
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.describe('Show certification own', () => {
let page: Page;
Expand All @@ -15,19 +15,19 @@ test.describe('Show certification own', () => {
});

test('should display certificate details', async () => {
expect(await page.isVisible('text=successfully completed')).toBeTruthy();
expect(await page.isVisible('text=Responsive Web Design')).toBeTruthy();
await expect(page.getByText('successfully completed')).toBeVisible();
await expect(page.getByText('Responsive Web Design')).toBeVisible();
await expect(page.locator('[data-cy=issue-date]')).toContainText(
'Developer Certification on August 3, 2018'
);
});

test('should render LinkedIn and Twitter buttons', async () => {
expect(
await page.isVisible('text=Add this certification to my LinkedIn profile')
).toBeTruthy();
expect(
await page.isVisible('text=Share this certification on Twitter')
).toBeTruthy();
await expect(
page.getByText('Add this certification to my LinkedIn profile')
).toBeVisible();
await expect(
page.getByText('Share this certification on Twitter')
).toBeVisible();
});
});
3 changes: 1 addition & 2 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom", "ES2017"],
"types": ["@playwright/test", "node"]
"lib": ["es5", "dom", "ES2017"]
},
"extends": "../tsconfig-base.json"
}
Loading

0 comments on commit 7750cec

Please sign in to comment.