From 14517785b24184739d1a1d35a9db65543352d771 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Wed, 5 Jul 2023 10:39:04 +0800 Subject: [PATCH] DEV: Fix flaky system test when expanding chat message actions on mobile (#22428) Why this change? Chat system tests that opens the message actions on mobile have been flaky on our CI. Those system test usually fails when the message actions do not show up as expected causing subsequent actions to fail. In the case of the `Reply to message - channel - mobile when the message has an existing thread replies to the existing thread` system test, failure screenshot shows that we ended up navigating to the thread instead of opening the message actions button. To understand why this happens, we first need to understand that by default Capybara clicks on the centre of an element. Also, we need to note that the HTML structure of a chat message is like so: ```
``` Since `PageObjects::Pages::ChatChannel#expand_message_actions_mobile` attempts to click on the `.chat-message-contaier`, there is a possibility that the center of that element is the `.chat-message-thread-indicator` element which would explain why we navigated to the thread list instead of opening up the message actions. This is possible because the content of the original chat message as well as the message excerpt in the thread is randomly generated where the length of the message and how the text wraps on mobile can affect the height of the `.chat-message-content` element as thus its position in the `.chat-message-container` element. In most cases, the middle of the `.chat-message-container` happens to be the `.chat-message-content` which is why this test "flakes" sometimes. What is the solution? Instead of clicking on the `.chat-message-container`, we be more specific and click on the `.chat-message-content` element instead. --- plugins/chat/spec/system/page_objects/chat/chat_channel.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/chat/spec/system/page_objects/chat/chat_channel.rb b/plugins/chat/spec/system/page_objects/chat/chat_channel.rb index fd2437d7c01..a80457dc6a7 100644 --- a/plugins/chat/spec/system/page_objects/chat/chat_channel.rb +++ b/plugins/chat/spec/system/page_objects/chat/chat_channel.rb @@ -64,7 +64,7 @@ module PageObjects end def expand_message_actions_mobile(message, delay: 2) - message_by_id(message.id).click(delay: delay) + find(message_by_id_selector(message.id)).find(".chat-message-content").click(delay: delay) end def click_message_action_mobile(message, message_action)