From 074fd3222cb1887f85eeb113906bde8b3a326afc Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Sat, 29 Oct 2022 17:45:24 +0530 Subject: [PATCH] test: webhook stability fix Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- .../pages/Dashboard/WebhookForm/index.ts | 53 ++++++++++++++----- scripts/playwright/tests/01-webhook.spec.ts | 8 +-- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/scripts/playwright/pages/Dashboard/WebhookForm/index.ts b/scripts/playwright/pages/Dashboard/WebhookForm/index.ts index 9d6e6ef7c9..13e06ce9cb 100644 --- a/scripts/playwright/pages/Dashboard/WebhookForm/index.ts +++ b/scripts/playwright/pages/Dashboard/WebhookForm/index.ts @@ -42,7 +42,7 @@ export class WebhookFormPage extends BasePage { await this.get().waitFor({ state: "visible" }); await this.configureHeader({ - key: "Content-type", + key: "Content-Type", value: "application/json", }); await this.configureWebhook({ title, event, url }); @@ -161,8 +161,7 @@ export class WebhookFormPage extends BasePage { await this.get().locator(`.ant-tabs-tab-btn:has-text("Headers")`).click(); await this.get().locator(".nc-input-hook-header-key >> input").fill(key); - const modal = this.rootPage.locator(`.nc-dropdown-webhook-header`); - await modal.locator(`.ant-select-item:has-text("${key}")`).click(); + await this.rootPage.locator(`.ant-select-item:has-text("${key}")`).click(); await this.get().locator(".nc-input-hook-header-value").type(value); await this.get().press("Enter"); @@ -188,16 +187,42 @@ export class WebhookFormPage extends BasePage { urlMethod: string; condition: boolean; }) { - await expect.poll( - async () => await this.get().locator('input.nc-text-field-hook-title').inputValue() - ).toBe(title); - await expect(this.get().locator('.nc-text-field-hook-event >> .ant-select-selection-item')).toHaveText(hookEvent); - await expect(this.get().locator('.nc-select-hook-notification-type >> .ant-select-selection-item')).toHaveText(notificationType); - await expect(this.get().locator('.nc-select-hook-url-method >> .ant-select-selection-item')).toHaveText(urlMethod); - await expect.poll(async() => await this.get().locator('input.nc-text-field-hook-url-path').inputValue()).toBe(url); - - const conditionCheckbox = this.get().locator('label.nc-check-box-hook-condition >> input[type="checkbox"]') - if(condition) { + await expect + .poll( + async () => + await this.get() + .locator("input.nc-text-field-hook-title") + .inputValue() + ) + .toBe(title); + await expect( + this.get().locator( + ".nc-text-field-hook-event >> .ant-select-selection-item" + ) + ).toHaveText(hookEvent); + await expect( + this.get().locator( + ".nc-select-hook-notification-type >> .ant-select-selection-item" + ) + ).toHaveText(notificationType); + await expect( + this.get().locator( + ".nc-select-hook-url-method >> .ant-select-selection-item" + ) + ).toHaveText(urlMethod); + await expect + .poll( + async () => + await this.get() + .locator("input.nc-text-field-hook-url-path") + .inputValue() + ) + .toBe(url); + + const conditionCheckbox = this.get().locator( + 'label.nc-check-box-hook-condition >> input[type="checkbox"]' + ); + if (condition) { await expect(conditionCheckbox).toBeChecked(); } else { await expect(conditionCheckbox).not.toBeChecked(); @@ -205,6 +230,6 @@ export class WebhookFormPage extends BasePage { } async goBackFromForm() { - await this.get().locator('svg.nc-icon-hook-navigate-left').click(); + await this.get().locator("svg.nc-icon-hook-navigate-left").click(); } } diff --git a/scripts/playwright/tests/01-webhook.spec.ts b/scripts/playwright/tests/01-webhook.spec.ts index 240c9e7733..0a7061aac6 100644 --- a/scripts/playwright/tests/01-webhook.spec.ts +++ b/scripts/playwright/tests/01-webhook.spec.ts @@ -20,9 +20,9 @@ async function clearServerData({ request }) { async function verifyHookTrigger(count: number, value: string, request) { // Retry since there can be lag between the time the hook is triggered and the time the server receives the request let response; - for(let i = 0; i < 6; i++) { + for (let i = 0; i < 6; i++) { response = await request.get(hookPath + "/count"); - if(await response.json() === count) { + if ((await response.json()) === count) { break; } await new Promise((resolve) => setTimeout(resolve, 100)); @@ -37,13 +37,13 @@ async function verifyHookTrigger(count: number, value: string, request) { test.describe.serial("Webhook", async () => { // start a server locally for webhook tests - + let dashboard: DashboardPage, toolbar: ToolbarPage, webhook: WebhookFormPage; let context: any; test.beforeAll(async () => { await makeServer(); - }) + }); test.beforeEach(async ({ page }) => { context = await setup({ page });