Skip to content

Commit

Permalink
Fix check service and wait for reason type to load
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-cortez-stevenson committed Jan 19, 2024
1 parent a0c0db0 commit 3718b80
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions tests/appointment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ test("appointment", async ({ context, params }, testInfo) => {
earliestDate: params.APPOINTMENT_EARLIEST_DATE,
latestDate: params.APPOINTMENT_LATEST_DATE,
});
expect(dateURLs.length, "No available appointment dates").toBeGreaterThan(
0
);
expect(dateURLs.length, "No available appointment dates").toBeGreaterThan(0);

const appointmentURLs = await getAppointmentURLs(context, dateURLs, {
earliestTime: params.APPOINTMENT_EARLIEST_TIME,
Expand Down Expand Up @@ -554,6 +552,12 @@ async function otvAppointment(
}
) {
return test.step("otv appointment", async () => {
const RESOURCE_EXCLUSTIONS = ["stylesheet"];
await page.route("**/*", (route) => {
return RESOURCE_EXCLUSTIONS.includes(route.request().resourceType())
? route.abort()
: route.continue();
});
page.on("load", async (page) => {
await Promise.all([
expect(page, "Unexpectedly logged out").not.toHaveURL("**/logout", {
Expand All @@ -563,10 +567,10 @@ async function otvAppointment(
page.getByRole("heading", { name: "Sitzungsende" }),
"Unexpectedly logged out"
).not.toBeVisible({ timeout: 1 }),
// expect(
// page.getByText("aktuell keine Termine frei"),
// "No appointments currently available"
// ).not.toBeVisible({ timeout: 1 }),
expect(
page.locator(".errorMessage"), // page.getByText("Für die gewählte Dienstleistung sind aktuell keine Termine frei! Bitte versuchen Sie es zu einem späteren Zeitpunkt erneut."),
"No appointments currently available"
).not.toBeVisible({ timeout: 1 }),
]);
});
await page.getByRole("link", { name: "Termin buchen" }).click();
Expand All @@ -579,6 +583,7 @@ async function otvAppointment(
.getByLabel("Staatsangehörigkeit (Wenn Sie")
.selectOption(nationality);
await page.locator("#xi-sel-422").selectOption(numberOfPeople);
const serviceLocator = page.getByLabel(serviceName);
await expect(async () => {
const withFamilyLocator = page.getByLabel(
"Leben Sie in Berlin zusammen mit einem Familienangehörigen (z.B. Ehepartner, Kind)*",
Expand All @@ -592,36 +597,44 @@ async function otvAppointment(
const familyNationalityLocator = page.getByLabel(
"Staatsangehörigkeit des Familienangehörigen"
);
await page.waitForTimeout(500); // Wait for the form to load.
if (await familyNationalityLocator.isVisible()) {
await familyNationalityLocator.selectOption(familyNationality);
}
await expect(page.getByLabel(serviceName)).toHaveCount(1);
await expect(serviceLocator).toHaveCount(1);
}).toPass();
// TODO: serviceLocator is not visible for some reason.
const serviceLocator = page.getByLabel(serviceName);
await expect(serviceLocator).toBeVisible();
await serviceLocator.check();
// TODO: Everything below is untested so far.
const residenceReasonTypeLocator = page.getByLabel(residenceReasonType);
await page.waitForTimeout(500); // Wait for the form to load.
if (await residenceReasonTypeLocator.isVisible()) {
await residenceReasonTypeLocator.check();
}
await page.getByLabel(residenceReason).check();
const lastNameLocator = page.getByLabel("Nachnamen");
await page.waitForTimeout(500); // Wait for the form to load.
if (await lastNameLocator.isVisible()) {
await lastNameLocator.fill(lastName);
}
await page.getByRole("button", { name: "Weiter" }).click();
await page.waitForLoadState();
// TODO: Everything below is untested so far.
await page.getByRole("row").getByRole("link").first().click();
await page
.getByLabel("Bitte wählen Sie einen Tag")
.selectOption({ label: /d{2}:\d{2}/ });
// Solve captcha with 2Captcha chrome extension
// TODO: Solve captcha with 2Captcha API
await page.locator(".captcha-solver").click();
await expect(
page.locator(`.captcha-solver[data-state="solved"]`)
).toBeVisible({ timeout: 150_000 });
// Solve captcha with 2Captcha chrome extension
const captchaSolver = page.locator(".captcha-solver");
await captchaSolver.click();
await expect(captchaSolver, "Captcha solver didn't solve").toHaveAttribute(
"data-state",
"solved",
{ timeout: 150_000 }
);
// Submit booking
await page.getByRole("button", { name: "Weiter" }).click();
await page.waitForLoadState();
// TODO: Save booking confirmation or handle whatever comes next.
});
}

0 comments on commit 3718b80

Please sign in to comment.