diff --git a/README.md b/README.md index 14962f6..7357e85 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,18 @@ MAILSLURP_API_KEY=*your-api-key* FORM_NAME=*your-name* FORM_PHONE=*your-phone-nu APPOINTMENT_SERVICE="Abmeldung einer Wohnung" \ APPOINTMENT_EARLIEST_TIME="10:00 GMT" \ APPOINTMENT_LATEST_TIME="13:00 GMT" \ - npm run debug + npm start ``` ## Deployment -Set [playwright.config.js](/playwright.config.js) `retries` to a high number, if you want to run the app locally until a successful booking is made. You may very well be blocked for exceeding a rate limit. In this case, try setting `PROXY_URL` to a back-connect proxy URL. +### Local + +Set [playwright.config.js](/playwright.config.js) `retries` to a high number (or run `npx playwright test --retries=*a high number* ...` from the CLI), if you want to run the app until a successful booking is made. + +To increase your chances of getting an appointment, set `PROXY_URL` to a back-connect proxy URL. + +If you don't have access to a back-connect proxy service, then I suggest setting environment variable `RETRY_WAIT_SECONDS` >= `90` to avoid exceeding the rate-limit and having to wait for `RETRY_WAIT_SECONDS_BLOCKED` to retry. ## Parameters @@ -92,6 +98,8 @@ Variable | Default | Description `LOGLEVEL` | "info" | Set to "debug" to get stdout. `CONCURRENCY` | "16" | Max number of concurrent Pages. `PROXY_URL` | `undefined` | Hide your IP with a back-connect proxy. +`RETRY_WAIT_SECONDS` | "0" | How long to wait between retries. +`RETRY_WAIT_SECONDS_BLOCKED` | "600" | How long to wait when rate-limited. ## Debugging diff --git a/playwright.config.js b/playwright.config.js index 7f043f3..cde3d41 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -4,6 +4,7 @@ module.exports = defineConfig({ name: "anmeldung-berlin", testDir: "./tests/", timeout: 0, + retries: parseInt(process.env.RETRY_COUNT || "0"), reporter: [["html", { open: "never" }]], use: { ...devices["Desktop Chrome"], diff --git a/tests/appointment.test.js b/tests/appointment.test.js index 7945b39..b77a285 100644 --- a/tests/appointment.test.js +++ b/tests/appointment.test.js @@ -17,6 +17,31 @@ const test = require("../src/test.js")({ APPOINTMENT_LATEST_TIME: "23:59 GMT", }); +// eslint-disable-next-line no-empty-pattern +test.beforeEach(async ({}, testInfo) => { + if (testInfo.retry > 0) { + const waitSeconds = parseInt(process.env.RETRY_WAIT_SECONDS || "0"); + logger.info(`Waiting ${waitSeconds} seconds then retrying ...`); + await sleep(waitSeconds * 1000); + } +}); + +test.afterEach(async ({ context }, testInfo) => { + await context.close() + if (testInfo.status !== testInfo.expectedStatus) { + logger.warn(`Appointment booking failed: ${testInfo.error.message}`); + if (testInfo.error.message.match(/Rate limit exceeded/)) { + const waitSeconds = parseInt(process.env.RETRY_WAIT_SECONDS_BLOCKED || "0"); + logger.info(`Waiting ${waitSeconds} seconds because we were rate limited ...`); + await sleep(waitSeconds * 1000); + } + } +}); + +function sleep(ms = 120000) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} + test("appointment", async ({ context, params }, testInfo) => { logger.debug(JSON.stringify(params, null, 2)); const serviceURL = await getServiceURL(await context.newPage(), {