From 4ebcc9ba951b347b29a292f3c584a3868392cb97 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 5 Jul 2022 20:28:39 -0700 Subject: [PATCH] puppeteer_tests: Fix type errors. Signed-off-by: Anders Kaseorg --- frontend_tests/puppeteer_lib/common.ts | 26 +++++++++++----------- frontend_tests/puppeteer_tests/compose.ts | 3 +++ frontend_tests/puppeteer_tests/settings.ts | 2 ++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/frontend_tests/puppeteer_lib/common.ts b/frontend_tests/puppeteer_lib/common.ts index 0e0f45c519..acdbe17bcd 100644 --- a/frontend_tests/puppeteer_lib/common.ts +++ b/frontend_tests/puppeteer_lib/common.ts @@ -103,7 +103,7 @@ class CommonUtils { // This function hacks around that issue; once it's fixed in // puppeteer upstream, we can delete this function and return // its callers to using `page.url()` - return await page.evaluate("location.href"); + return await page.evaluate(() => window.location.href); } // This function will clear the existing value of the element and @@ -280,13 +280,13 @@ class CommonUtils { } async assert_compose_box_content(page: Page, expected_value: string): Promise { - await page.waitForSelector("#compose-textarea"); - - const compose_box_element = await page.$("#compose-textarea"); - const compose_box_content = await page.evaluate( - (element: HTMLTextAreaElement) => element.value, - compose_box_element, - ); + const compose_box_element = await page.waitForSelector("#compose-textarea"); + const compose_box_content = await page.evaluate((element) => { + if (!(element instanceof HTMLTextAreaElement)) { + throw new TypeError("expected HTMLTextAreaElement"); + } + return element.value; + }, compose_box_element); assert.equal( compose_box_content, expected_value, @@ -501,12 +501,12 @@ class CommonUtils { `//*[@class="typeahead dropdown-menu" and contains(@style, "display: block")]//li[contains(normalize-space(), "${item}")]//a`, {visible: true}, ); - const entry_x = (await entry?.boundingBox())?.x; - const entry_y = (await entry?.boundingBox())?.y; - if (entry_x && entry_y) { - await page.mouse.move(entry_x, entry_y); - } + assert.ok(entry); + await entry.hover(); await page.evaluate((entry) => { + if (!(entry instanceof HTMLElement)) { + throw new TypeError("expected HTMLElement"); + } entry.click(); }, entry); } diff --git a/frontend_tests/puppeteer_tests/compose.ts b/frontend_tests/puppeteer_tests/compose.ts index 2bf6aa2d98..729fe1d334 100644 --- a/frontend_tests/puppeteer_tests/compose.ts +++ b/frontend_tests/puppeteer_tests/compose.ts @@ -179,6 +179,7 @@ async function test_markdown_preview_without_any_content(page: Page): Promise element.textContent, markdown_preview_element), "Nothing to preview", @@ -189,6 +190,7 @@ async function test_markdown_preview_without_any_content(page: Page): Promise { await page.waitForSelector("#compose .markdown_preview", {visible: true}); let markdown_preview_element = await page.$("#compose .preview_content"); + assert.ok(markdown_preview_element); assert.equal( await page.evaluate((element: Element) => element.textContent, markdown_preview_element), "", @@ -202,6 +204,7 @@ async function test_markdown_rendering(page: Page): Promise { "

Markdown preview >> Test for Markdown preview

"; await page.waitForFunction(() => $("#compose .preview_content").html() !== ""); markdown_preview_element = await page.$("#compose .preview_content"); + assert.ok(markdown_preview_element); assert.equal( await page.evaluate((element: Element) => element.innerHTML, markdown_preview_element), expected_markdown_html, diff --git a/frontend_tests/puppeteer_tests/settings.ts b/frontend_tests/puppeteer_tests/settings.ts index 5851ec5587..e7e9adf1bb 100644 --- a/frontend_tests/puppeteer_tests/settings.ts +++ b/frontend_tests/puppeteer_tests/settings.ts @@ -217,6 +217,8 @@ async function test_invalid_edit_bot_form(page: Page): Promise { await page.waitForFunction( (cancel_button_selector: string) => !document.querySelector(cancel_button_selector)?.hasAttribute("disabled"), + {}, + cancel_button_selector, ); await page.click(cancel_button_selector); await page.waitForXPath(