From 5da304d902bbb2dc4df8948ffdac941b4416bed0 Mon Sep 17 00:00:00 2001 From: Riken Shah Date: Wed, 20 Jan 2021 13:19:21 +0000 Subject: [PATCH] puppeteer_test: Replace textContent to value for the compose box. This commit fixes the broken assertions for checking if compose box is empty. Fixes: #17088 --- frontend_tests/puppeteer_lib/common.js | 28 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/frontend_tests/puppeteer_lib/common.js b/frontend_tests/puppeteer_lib/common.js index 091a8106a9..612b392601 100644 --- a/frontend_tests/puppeteer_lib/common.js +++ b/frontend_tests/puppeteer_lib/common.js @@ -239,6 +239,21 @@ class CommonUtils { }); } + async assert_compose_box_content(page, expected_value) { + await page.waitForSelector("#compose-textarea"); + + const compose_box_element = await page.$("#compose-textarea"); + const compose_box_content = await page.evaluate( + (element) => element.value, + compose_box_element, + ); + assert.equal( + compose_box_content, + expected_value, + `Compose box content did not match with the expected value '{${expected_value}}'`, + ); + } + async wait_for_fully_processed_message(page, content) { await page.waitForFunction( (content) => { @@ -302,7 +317,8 @@ class CommonUtils { const {outside_view} = params; delete params.outside_view; - await page.waitForSelector("#compose-textarea"); + // Compose box content should be empty before sending the message. + await this.assert_compose_box_content(page, ""); if (type === "stream") { await page.keyboard.press("KeyC"); @@ -328,17 +344,13 @@ class CommonUtils { } await this.fill_form(page, 'form[action^="/json/messages"]', params); + await this.assert_compose_box_content(page, params.content); await this.ensure_enter_does_not_send(page); await page.waitForSelector("#compose-send-button", {visible: true}); await page.click("#compose-send-button"); - // confirm if compose box is empty. - const compose_box_element = await page.$("#compose-textarea"); - const compose_box_content = await page.evaluate( - (element) => element.textContent, - compose_box_element, - ); - assert.equal(compose_box_content, "", "Compose box not empty after message sent"); + // Sending should clear compose box content. + this.assert_compose_box_content(page, ""); if (!outside_view) { await this.wait_for_fully_processed_message(page, params.content);