-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test frontend uploads with playwright
- Install and configure playwright - Includes README.md with helpful playwright commands - Add basic upload and nav tests
- Loading branch information
1 parent
ff78a04
commit e4e2edf
Showing
7 changed files
with
684 additions
and
252 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,79 @@ | ||
// @ts-check | ||
const { defineConfig, devices } = require('@playwright/test'); | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config({ path: path.resolve(__dirname, '.env') }); | ||
|
||
/** | ||
* @see https://playwright.dev/docs/test-configuration | ||
*/ | ||
module.exports = 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'] }, | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'npm run start', | ||
// url: 'http://127.0.0.1:3000', | ||
// reuseExistingServer: !process.env.CI, | ||
// }, | ||
}); | ||
|
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,25 @@ | ||
Playwright tests exist in /tests. Before running any of the following commands, make sure you have installed the dependencies by running `npm install` and started the server by running `pipenv python manage.py runserver`. | ||
|
||
npx playwright test | ||
Runs the end-to-end tests. | ||
|
||
npx playwright test --ui | ||
Starts the interactive UI mode. | ||
|
||
npx playwright test --project=chromium | ||
Runs the tests only on Desktop Chrome. | ||
|
||
npx playwright test example | ||
Runs the tests in a specific file. | ||
|
||
npx playwright test --debug | ||
Runs the tests in debug mode. | ||
|
||
npx playwright codegen | ||
Auto generate tests with Codegen. | ||
|
||
We suggest that you begin by typing: | ||
|
||
npx playwright test | ||
|
||
Visit https://playwright.dev/docs/intro for more information. ✨ |
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,53 @@ | ||
import { test } from '@playwright/test'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const baseUrl = 'http://localhost:8000/'; | ||
|
||
async function navigateToUploadPage(page) { | ||
await page.goto(baseUrl); | ||
await page.getByRole('link', { name: 'Upload a leaflet' }).click(); | ||
await page.getByText('Take a photo of a leaflet').click(); | ||
} | ||
|
||
async function fillPostcodeAndSubmit(page, postcode = 'W8 4NU') { | ||
await page.getByLabel('What postcode was this').click(); | ||
await page.getByLabel('What postcode was this').fill(postcode); | ||
await page.getByRole('button', { name: 'Submit' }).click(); | ||
await page.getByText('Green Party').click(); | ||
await page.getByRole('button', { name: 'Submit' }).click(); | ||
await page.getByText('Thank you so much!'); | ||
} | ||
|
||
// Increase the timeout for all tests | ||
test.setTimeout(60000); | ||
|
||
test('basic upload test', async ({ page }) => { | ||
await navigateToUploadPage(page); | ||
await page.getByLabel('Take a photo of a leaflet').setInputFiles('electionleaflets/test_media/test_images/test_leaflet.jpeg'); | ||
await page.getByRole('button', { name: 'Continue' }).click(); | ||
await fillPostcodeAndSubmit(page); | ||
}); | ||
|
||
test('uploading multiple leaflet images', async ({ page }) => { | ||
await navigateToUploadPage(page); | ||
const imageDir = path.resolve(__dirname, '../electionleaflets/test_media/test_images'); | ||
const imageFiles = fs.readdirSync(imageDir).map(file => path.join(imageDir, file)); | ||
await page.getByLabel('Take a photo of a leaflet').setInputFiles(imageFiles); | ||
await page.getByRole('button', { name: 'Continue' }).click(); | ||
await fillPostcodeAndSubmit(page); | ||
}); | ||
|
||
test('uploading a non-image leaflet file', async ({ page }) => { | ||
await navigateToUploadPage(page); | ||
await page.getByLabel('Take a photo of a leaflet').setInputFiles('electionleaflets/test_media/test_images/test_leaflet.docx'); | ||
await page.getByRole('button', { name: 'Continue' }).click(); | ||
await page.getByText('Error during upload tap to retry'); | ||
}); | ||
|
||
test('read leaflet from latest leaflets', async ({ page }) => { | ||
await page.goto(baseUrl); | ||
await page.getByRole('link', { name: 'Latest leaflets' }).click(); | ||
await page.locator('.ds-card-link').first().click(); | ||
await page.getByText('Leaflet details'); | ||
}); |