refactor: cleanup playwright tests (#51499)

This commit is contained in:
Oliver Eyton-Williams
2023-09-08 14:14:27 +02:00
committed by GitHub
parent 6c25982446
commit 7750cec84f
12 changed files with 485 additions and 319 deletions

View File

@@ -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
@@ -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: |

7
.gitignore vendored
View File

@@ -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
e2e/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
/test-results
/playwright-report
/playwright/.cache/
/playwright/.auth

View File

@@ -1,95 +0,0 @@
{
"cookies": [
{
"name": "_ga",
"value": "GA1.1.581746587.1692856321",
"domain": "localhost",
"path": "/",
"expires": 1727416320.892245,
"httpOnly": false,
"secure": false,
"sameSite": "Lax"
},
{
"name": "_gid",
"value": "GA1.1.1350865451.1692856321",
"domain": "localhost",
"path": "/",
"expires": 1692942720,
"httpOnly": false,
"secure": false,
"sameSite": "Lax"
},
{
"name": "_gat_UA-55446531-19",
"value": "1",
"domain": "localhost",
"path": "/",
"expires": 1692856380,
"httpOnly": false,
"secure": false,
"sameSite": "Lax"
},
{
"name": "_ga_S7DT07TF4G",
"value": "GS1.1.1692856320.1.0.1692856320.0.0.0",
"domain": "localhost",
"path": "/",
"expires": 1727416320.891943,
"httpOnly": false,
"secure": false,
"sameSite": "Lax"
},
{
"name": "_ga_KS9N2Z7EHL",
"value": "GS1.1.1692856321.1.0.1692856321.0.0.0",
"domain": "localhost",
"path": "/",
"expires": 1727416321.277638,
"httpOnly": false,
"secure": false,
"sameSite": "Lax"
},
{
"name": "_csrf",
"value": "5U4rzxSzclMprLi4cvz7bCfZ",
"domain": "localhost",
"path": "/",
"expires": -1,
"httpOnly": true,
"secure": false,
"sameSite": "Strict"
},
{
"name": "csrf_token",
"value": "dAxgAH76-KZn92rN_ViqD3DbIi3HLBi9ZKnY",
"domain": "localhost",
"path": "/",
"expires": -1,
"httpOnly": false,
"secure": false,
"sameSite": "Strict"
},
{
"name": "jwt_access_token",
"value": "s%3AeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3NUb2tlbiI6eyJpZCI6Im55eW5zVHlRcm1YTm84QVBNS2lHN1NBa1N2c0JpQzFYblo4UWhJMkd1aGZpeEFhVjZoRXB1SjVnRlROZUVjSlUiLCJ0dGwiOjc3NzYwMDAwMDAwLCJjcmVhdGVkIjoiMjAyMy0wOC0yNFQwNTo1MjowMS40NTVaIiwidXNlcklkIjoiNWZhMmRiMDBhMjVjMWMxZmE0OWNlMDY3In0sImlhdCI6MTY5Mjg1NjMyMX0.r9MVox5vCm23tECIWNud7TR7sFwIU-wd-GovD2IPQi0.KVZupFa7dUeu5aiOeFIbiRlTM6upKPw78DFTb%2FzWjps",
"domain": "localhost",
"path": "/",
"expires": 1727416321.460702,
"httpOnly": false,
"secure": false,
"sameSite": "Lax"
},
{
"name": "connect.sid",
"value": "s%3AVs5NZBimD3InWrpU5LOBoLcfKdDuPSE2.PHGiu5kNikimtDu4kuicTNURRNc3mTlKOeiOGqHztak",
"domain": "localhost",
"path": "/",
"expires": 1727416321.46071,
"httpOnly": true,
"secure": false,
"sameSite": "Lax"
}
],
"origins": []
}

View File

@@ -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' });
});

View File

@@ -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 }) => {
@@ -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 () => {

View File

@@ -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",

View File

@@ -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 */
/* ====================================================== */

View File

@@ -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;
@@ -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();
});
});

View File

@@ -1,8 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom", "ES2017"],
"types": ["@playwright/test", "node"]
"lib": ["es5", "dom", "ES2017"]
},
"extends": "../tsconfig-base.json"
}

639
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,7 @@ packages:
- 'client'
- 'curriculum'
- 'shared'
- 'e2e'
- 'tools/challenge-editor/api'
- 'tools/challenge-editor/client'
- 'tools/challenge-helper-scripts'