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: auto complaint generation #98

Merged
merged 6 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions .github/workflows/complaint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Complaint
on:
pull_request:
jobs:
test-complaint:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm run docker:build
working-directory: src/complaint
- run: npm run docker:run
working-directory: src/complaint
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-trace
path: src/complaint/traces
retention-days: 30\
- uses: shallwefootball/s3-upload-action@master
name: Upload trace to S3
if: always()
id: s3-trace
continue-on-error: true
with:
aws_key_id: ${{ secrets.AWS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
aws_bucket: noam-gaash.co.il
source_dir: src/complaint/traces
destination_dir: ${{ github.run_id }}/open-bus/complaint
- name: output link to report to the trace
if: always() && steps.s3-trace.outcome == 'success'
run: echo "link to trace - https://trace.playwright.dev/?trace=https://s3.amazonaws.com/noam-gaash.co.il/${{ github.run_id }}/open-bus/complaint/index.html" >> $GITHUB_STEP_SUMMARY
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ yarn-error.log*
/playwright-report/
/playwright/.cache/
.vscode/settings.json

**/traces
**/node_modules
10 changes: 10 additions & 0 deletions src/complaint/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM mcr.microsoft.com/playwright:v1.38.0-jammy

COPY complaint.js /complaint.js
COPY package.json /package.json
COPY package-lock.json /package-lock.json

RUN npm ci

CMD ["node", "/complaint.js"]

19 changes: 19 additions & 0 deletions src/complaint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# MOT Complaint Maker

## NOTICE
this project is still under development - it won't really send any reports to the MOT website.

## Goal
After searching for specific bus in one of the pages, users might wasnt to submit a complaint about a bus:

* maybe the bus came too early / too late
* maybe it didn't stop at all
* maybe the bus driver had a yellow T-shirt
and so on.

anyway - we would like to make complaints submission accessible and easy, instead of the dark UX we currently have.

## usefull commands
build the image - `npm run docker:build`
run the image (won't really send anything to the MOT) - `npm run docker:run`
see the report - `npm run view-trace`
110 changes: 110 additions & 0 deletions src/complaint/complaint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { chromium } from 'playwright'
// import { express } from 'express'

const url =
'https://forms.gov.il/globaldata/getsequence/getHtmlForm.aspx?formType=PniotMot%40mot.gov.il'

const complaint = {
// first page
firstName: 'אבי',
lastName: 'כהן',
id: '316159003',
email: '[email protected]',
phone: '0536218158',

// third page
operator: 'אגד',
licensePlate: '1234567',
time: new Date(),
lineNumber: '1',
routeName: 'כרמיאל-כרמיאל',
}

const complaintTypes = ['אי עצירה בתחנה', 'אחר']

const browser = await chromium.launch({
// headless: false,
})
const context = await browser.newContext()
await context.tracing.start({
screenshots: true,
snapshots: true,
sources: true,
})
const page = await context.newPage()
try {
await page.goto(url)
console.log('page loaded')
await page.click('text=כניסה לטופס')
await page.getByLabel('שם פרטי').fill(complaint.firstName)
await page.getByLabel('שם משפחה').fill(complaint.lastName)
await page.getByLabel('מספר זהות').fill(complaint.id)
await page.getByLabel('טלפון נייד', { exact: true }).fill(complaint.phone)
await page.getByRole('textbox', { name: 'דואר אלקטרוני' }).fill(complaint.email)

console.log('filled first page')

await page.getByRole('button', { name: 'לשלב הבא' }).click()
// await page.getByLabel('נושא הפנייה').getByLabel('בחירה מהרשימה').first().click()
// await new Promise((r) => setTimeout(r, 100))
await page.getByLabel('נושא הפנייה', { exact: true }).fill('אוטובוס')
await new Promise((r) => setTimeout(r, 100))
await page.getByLabel('נושא הפנייה').getByLabel('בחירה מהרשימה').first().click()
await new Promise((r) => setTimeout(r, 100))
await page.getByText('אוטובוס', { exact: true }).click()
await new Promise((r) => setTimeout(r, 100))
await page.getByLabel('סוג הפנייה').fill(complaintTypes[0])
await new Promise((r) => setTimeout(r, 100))
await page.getByText(complaintTypes[0]).click()
await new Promise((r) => setTimeout(r, 100))

console.log('filled second page')

await page.getByRole('button', { name: 'לשלב הבא' }).click()
await page.getByLabel('חברת האוטובוסים (מפעיל)').fill(complaint.operator)
await page.getByRole('textbox', { name: 'מספר רישוי' }).fill(complaint.licensePlate)
await page.getByRole('textbox', { name: 'תאריך האירוע' }).fill(formatDate(complaint.time))
await page.getByRole('textbox', { name: 'שעת האירוע' }).fill(formatTime(complaint.time))
await page.getByLabel('שעת המתנה מ').fill('00:00')
await page.getByLabel('שעת המתנה עד').fill('23:59')
await page
.getByRole('textbox', { name: 'תוכן הפנייה' })
.fill('האוטובוס עצר בתחנה ולא נסע עד שעה מאוחרת')

await page.getByRole('textbox', { name: 'מספר קו' }).fill(complaint.lineNumber)
await page.getByLabel('מוצא/ יעד (כיוון )').fill(complaint.routeName)

console.log('filled third page')

for (let i = 0; i < 10 && (await page.getByText('הנחיות לצירוף מסמכים').isHidden()); i++) {
// retry until it works
await page.getByRole('button', { name: 'לשלב הבא' }).click()
await page.waitForTimeout(300)
}
// await new Promise((r) => setTimeout(r, 1000000))
// await page.getByRole('button', { name: 'לשלב הבא' }).click({ force: true })
// await page.getByRole('button', { name: 'לשלב הבא' }).click()
} finally {
await context.tracing.stop({
path: `/traces/trace.zip`,
})
// await page.waitForTimeout(10000)
await browser.close()
}
/**
* @param {Date} date
*/
function formatDate(date) {
const d = leadZero(date.getDate())
const month = leadZero(date.getMonth() + 1)
const year = date.getFullYear()
return `${d}/${month}/${year}`
}

function formatTime(date) {
return `${leadZero(date.getHours())}:${leadZero(date.getMinutes())}`
}

function leadZero(number) {
return number < 10 ? `0${number}` : number
}
57 changes: 57 additions & 0 deletions src/complaint/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/complaint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "complaint",
"version": "0.0.0",
"description": "",
"type": "module",
"main": "complaint.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"docker:build": "docker build -t complaint .",
"docker:run": "docker run -v ./traces:/traces complaint",
"view-trace": "playwright show-trace traces/trace.zip"
},
"author": "",
"license": "ISC",
"dependencies": {
"playwright": "^1.38.1"
}
}
Loading