Skip to content

Commit 552f6f9

Browse files
chore(tools): create script to spam submissions
This commit is to be removed when merging into main.
1 parent b2d72fd commit 552f6f9

File tree

9 files changed

+188
-0
lines changed

9 files changed

+188
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import playwright from 'eslint-plugin-playwright'
2+
import baseConfigPromise from '../../eslint.config.js'
3+
4+
export default (async () => {
5+
const baseConfig = await baseConfigPromise
6+
7+
return [
8+
playwright.configs['flat/recommended'],
9+
...baseConfig,
10+
{
11+
files: ['**/*.ts', '**/*.js'],
12+
// Override or add rules here
13+
rules: {},
14+
},
15+
]
16+
})()

tools/risk-form-filler/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "risk-form-filler",
3+
"type": "module",
4+
"description": "",
5+
"license": "",
6+
"sideEffects": false,
7+
"scripts": {}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// TODO: Investigate node global process usage
2+
3+
import { fileURLToPath } from 'node:url'
4+
import { nxE2EPreset } from '@nx/playwright/preset'
5+
6+
import { defineConfig, devices } from '@playwright/test'
7+
8+
const __filename = fileURLToPath(import.meta.url)
9+
10+
// // For CI, you may want to set BASE_URL to the deployed application.
11+
// const baseURL = process.env.BASE_URL || 'http://127.0.0.1:3000'
12+
13+
/**
14+
* Read environment variables from file.
15+
* https://github.com/motdotla/dotenv
16+
*/
17+
// require('dotenv').config();
18+
19+
/**
20+
* See https://playwright.dev/docs/test-configuration.
21+
*/
22+
export default defineConfig({
23+
...nxE2EPreset(__filename, { testDir: './src' }),
24+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
25+
retries: 2,
26+
use: {
27+
// baseURL,
28+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
29+
trace: 'on-first-retry',
30+
},
31+
/* Run your local dev server before starting the tests */
32+
// webServer: {
33+
// command: 'pnpm nx start risk-form-filler',
34+
// // url: 'http://127.0.0.1:3000',
35+
// // reuseExistingServer: !process.env.CI,
36+
// cwd: workspaceRoot,
37+
// timeout: 120 * 1000,
38+
// },
39+
projects: [
40+
{
41+
name: 'chromium (desktop)',
42+
use: { ...devices['Desktop Chrome'] },
43+
},
44+
],
45+
})

tools/risk-form-filler/project.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "risk-form-filler",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "tools/risk-form-filler",
5+
"projectType": "application",
6+
"tags": [],
7+
"// targets": "to see all targets run: nx show project risk-form-filler --web",
8+
"targets": {
9+
"online": {
10+
"command": "npx tsx src/input/online-input.ts",
11+
"options": {
12+
"cwd": "tools/risk-form-filler"
13+
}
14+
},
15+
"in-person": {
16+
"command": "npx tsx src/input/in-person-input.ts",
17+
"options": {
18+
"cwd": "tools/risk-form-filler"
19+
}
20+
},
21+
"hybrid": {
22+
"command": "npx tsx src/input/hybrid-input.ts",
23+
"options": {
24+
"cwd": "tools/risk-form-filler"
25+
}
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface ScheduleOnlineParams {
2+
name: string
3+
email: string
4+
subject: string
5+
message: string
6+
}

tools/risk-form-filler/src/input/online-input.ts

+20
Large diffs are not rendered by default.

tools/risk-form-filler/src/online.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { ScheduleOnlineParams } from './input/schedule-online-params'
2+
3+
import type { FormsLayout } from './pom'
4+
5+
export async function scheduleOnline(params: ScheduleOnlineParams, formLayout: FormsLayout) {
6+
await formLayout.goto()
7+
await formLayout.fillContactPage(formLayout, params.name, params.email, params.subject, params.message)
8+
await formLayout.submitButton.click()
9+
}

tools/risk-form-filler/src/pom.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type { Locator, Page } from '@playwright/test'
2+
3+
export class FormsLayout {
4+
// Page object
5+
readonly page: Page
6+
7+
// textboxes
8+
readonly nameTextBox: Locator
9+
readonly emailTextBox: Locator
10+
readonly subjectTextBox: Locator
11+
readonly messageTextBox: Locator
12+
13+
// buttons
14+
readonly submitButton: Locator
15+
16+
constructor(page: Page) {
17+
this.page = page
18+
19+
this.nameTextBox = page.getByPlaceholder('Your Name')
20+
this.emailTextBox = page.getByPlaceholder('Your Email')
21+
this.subjectTextBox = page.getByPlaceholder('Subject')
22+
this.messageTextBox = page.getByPlaceholder('Your Message')
23+
24+
this.submitButton = page.getByRole('button', { name: 'Send Message' })
25+
}
26+
27+
// goto
28+
async goto() {
29+
await this.page.goto('http://localhost:3000/#contactpage')
30+
}
31+
32+
async fillContactPage(formLayout: FormsLayout, NAME: string, EMAIL: string, SUBJECT: string, MESSAGE: string) {
33+
await formLayout.nameTextBox.fill(NAME)
34+
await formLayout.emailTextBox.fill(EMAIL)
35+
await formLayout.subjectTextBox.fill(SUBJECT)
36+
await formLayout.messageTextBox.fill(MESSAGE)
37+
}
38+
}

tools/risk-form-filler/tsconfig.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"moduleResolution": "node",
5+
"outDir": "../../dist/out-tsc",
6+
"esModuleInterop": true
7+
},
8+
"include": [
9+
"**/*.ts",
10+
"**/*.js",
11+
"playwright.config.ts",
12+
"src/**/*.spec.ts",
13+
"src/**/*.spec.js",
14+
"src/**/*.test.ts",
15+
"src/**/*.test.js",
16+
"src/**/*.d.ts"
17+
]
18+
}

0 commit comments

Comments
 (0)