Repository: provectus/kafka-ui
Issue: [e2e] TopicTests.clearMessagesForPartition : Clear Messages for partition
Labels: scope/AQA

Autotest implentation for:
https://app.qase.io/project/KAFKAUI?view=1&suite=5&case=19

Description:
Checking Messages clearing for the selected Partition within Topic/Overview

Preconditions:
Login to Kafka-ui application

Open the 'Local' section

Select the 'Topics'

Open the Topic profile which has messages for different partitions

Stay in 'Overview' tab

Steps:
1  Click on Menu icon for partition

2  Press 'Clear messages'Expected resultSuccess message about clearing should displayAll the messages for selected partition should be deleted




Issue comments:
Hello there Redbutton18! 👋

Thank you and congratulations 🎉 for opening your very first issue in this project! 💖

In case you want to claim this issue, please comment down below! We will try to get back to you as soon as we can. 👀
Bug found 
https://github.com/provectus/kafka-ui/issues/2778

Pull request review comments:
delete your token pls
we have already defined element 'dotMenuBtn'
- use it if it's the same element
- define new element at the top of class as SelenideElement if it's another
let's use single style for defining objects
create string at the top of the class pls
please don't use extra spaces
seems that we don't need to set up for cases we use TOPIC_FOR_MESSAGES:
.setTimeToRetainData("604800001")
.setMaxSizeOnDisk("10 GB")
.setMaxMessageBytes("1000012")
I'd like o use @Issue annotation to store the link to issue because it will be displayed in Allure report
we need o waitUntilScreenReady first
what do we wait here? screen wasn't changed
in addition for TODO
Done
Done
Refactored
Done
This fields removed from TOPIC_FOR_MESSAGES
@issue annotation added
Done
Removed

Patch that resolved the issue:
diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/models/Topic.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/models/Topic.java
index 725db0dd8dd..18763e37191 100644
--- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/models/Topic.java
+++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/models/Topic.java
@@ -6,5 +6,5 @@
 @Data
 @Accessors(chain = true)
 public class Topic {
-    private String name, compactPolicyValue, timeToRetainData, maxSizeOnDisk, maxMessageBytes, messageKey, messageContent ;
+    private String name, cleanupPolicyValue, timeToRetainData, maxSizeOnDisk, maxMessageBytes, messageKey, messageContent ;
 }
diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicDetails.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicDetails.java
index b455d310fbc..5b4f1d3c962 100644
--- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicDetails.java
+++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicDetails.java
@@ -17,6 +17,8 @@ public class TopicDetails {
 
     protected SelenideElement loadingSpinner = $x("//*[contains(text(),'Loading')]");
     protected SelenideElement dotMenuBtn = $$x("//button[@aria-label='Dropdown Toggle']").first();
+    protected SelenideElement dotPartitionIdMenuBtn = $(By.cssSelector("button.sc-hOqruk.eYtACj"));
+    protected SelenideElement clearMessagesBtn = $x(("//div[contains(text(), 'Clear messages')]"));
     protected SelenideElement overviewTab = $x("//a[contains(text(),'Overview')]");
     protected SelenideElement messagesTab = $x("//a[contains(text(),'Messages')]");
     protected SelenideElement editSettingsTab = $x("//li[@role][contains(text(),'Edit settings')]");
@@ -45,6 +47,18 @@ public TopicDetails openTopicMenu(TopicMenu menu) {
         return this;
     }
 
+    @Step
+    public TopicDetails openDotPartitionIdMenu() {
+        dotPartitionIdMenuBtn.shouldBe(Condition.visible.because("dot menu invisible")).click();
+        return this;
+    }
+
+    @Step
+    public TopicDetails clickClearMessagesBtn() {
+        clearMessagesBtn.shouldBe(Condition.visible.because("Clear Messages invisible")).click();
+        return this;
+    }
+
     @Step
     public TopicDetails deleteTopic() {
         clickByJavaScript(dotMenuBtn);
@@ -70,6 +84,11 @@ public boolean isContentMessageVisible(String contentMessage) {
         return contentMessage.matches(contentMessageTab.getText().trim());
     }
 
+    @Step
+    public String MessageCountAmount() {
+        return $(By.xpath("//table[@class=\"sc-hiSbEG cvnuic\"]/tbody/tr/td[5]")).getText();
+    }
+
     private enum DotMenuHeaderItems {
         EDIT_SETTINGS("Edit settings"),
         CLEAR_MESSAGES("Clear messages"),
@@ -91,6 +110,26 @@ public String toString() {
         }
     }
 
+    public enum DotPartitionIdMenu {
+        CLEAR_MESSAGES("Clear messages");
+
+
+        private final String value;
+
+        DotPartitionIdMenu(String value) {
+            this.value = value;
+        }
+
+        public String getValue() {
+            return value;
+        }
+
+        @Override
+        public String toString() {
+            return "DotPartitionIdMenuItems{" + "value='" + value + '\'' + '}';
+        }
+    }
+
     public enum TopicMenu {
         OVERVIEW("Overview"),
         MESSAGES("Messages"),


Test patch:
diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/TopicTests.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/TopicTests.java
index bb1cfc34273..2b596a9e545 100644
--- a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/TopicTests.java
+++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/TopicTests.java
@@ -6,6 +6,7 @@
 import com.provectus.kafka.ui.utilities.qaseIoUtils.annotations.AutomationStatus;
 import com.provectus.kafka.ui.utilities.qaseIoUtils.annotations.Suite;
 import com.provectus.kafka.ui.utilities.qaseIoUtils.enums.Status;
+import io.qameta.allure.Issue;
 import io.qase.api.annotation.CaseId;
 import org.assertj.core.api.SoftAssertions;
 import org.junit.jupiter.api.*;
@@ -14,6 +15,7 @@
 import java.util.List;
 
 import static com.provectus.kafka.ui.pages.NaviSideBar.SideMenuOption.TOPICS;
+import static com.provectus.kafka.ui.pages.topic.TopicDetails.DotPartitionIdMenu.CLEAR_MESSAGES;
 import static com.provectus.kafka.ui.settings.Source.CLUSTER_NAME;
 import static com.provectus.kafka.ui.utilities.FileUtils.fileToString;
 
@@ -23,18 +25,23 @@ public class TopicTests extends BaseTest {
     private static final String SUITE_TITLE = "Topics";
     private static final Topic TOPIC_FOR_UPDATE = new Topic()
             .setName("topic-to-update")
-            .setCompactPolicyValue("Compact")
+            .setCleanupPolicyValue("Compact")
             .setTimeToRetainData("604800001")
             .setMaxSizeOnDisk("20 GB")
             .setMaxMessageBytes("1000020")
             .setMessageKey(fileToString(System.getProperty("user.dir") + "/src/test/resources/producedkey.txt"))
             .setMessageContent(fileToString(System.getProperty("user.dir") + "/src/test/resources/testData.txt"));
+    private static final Topic TOPIC_FOR_MESSAGES = new Topic()
+            .setName("topic-with-clean-message-attribute")
+            .setMessageKey(fileToString(System.getProperty("user.dir") + "/src/test/resources/producedkey.txt"))
+            .setMessageContent(fileToString(System.getProperty("user.dir") + "/src/test/resources/testData.txt"));
+
     private static final Topic TOPIC_FOR_DELETE = new Topic().setName("topic-to-delete");
     private static final List<Topic> TOPIC_LIST = new ArrayList<>();
 
     @BeforeAll
     public void beforeAll() {
-        TOPIC_LIST.addAll(List.of(TOPIC_FOR_UPDATE, TOPIC_FOR_DELETE));
+        TOPIC_LIST.addAll(List.of(TOPIC_FOR_UPDATE, TOPIC_FOR_DELETE, TOPIC_FOR_MESSAGES));
         TOPIC_LIST.forEach(topic -> apiHelper.createTopic(CLUSTER_NAME, topic.getName()));
     }
 
@@ -81,7 +88,7 @@ public void updateTopic() {
                 .openEditSettings();
         topicCreateEditForm
                 .waitUntilScreenReady()
-                .selectCleanupPolicy(TOPIC_FOR_UPDATE.getCompactPolicyValue())
+                .selectCleanupPolicy(TOPIC_FOR_UPDATE.getCleanupPolicyValue())
                 .setMinInsyncReplicas(10)
                 .setTimeToRetainDataInMs(TOPIC_FOR_UPDATE.getTimeToRetainData())
                 .setMaxSizeOnDiskInGB(TOPIC_FOR_UPDATE.getMaxSizeOnDisk())
@@ -98,7 +105,7 @@ public void updateTopic() {
                 .waitUntilScreenReady()
                 .openEditSettings();
         SoftAssertions softly = new SoftAssertions();
-        softly.assertThat(topicCreateEditForm.getCleanupPolicy()).as("Cleanup Policy").isEqualTo(TOPIC_FOR_UPDATE.getCompactPolicyValue());
+        softly.assertThat(topicCreateEditForm.getCleanupPolicy()).as("Cleanup Policy").isEqualTo(TOPIC_FOR_UPDATE.getCleanupPolicyValue());
         softly.assertThat(topicCreateEditForm.getTimeToRetain()).as("Time to retain").isEqualTo(TOPIC_FOR_UPDATE.getTimeToRetainData());
         softly.assertThat(topicCreateEditForm.getMaxSizeOnDisk()).as("Max size on disk").isEqualTo(TOPIC_FOR_UPDATE.getMaxSizeOnDisk());
         softly.assertThat(topicCreateEditForm.getMaxMessageBytes()).as("Max message bytes").isEqualTo(TOPIC_FOR_UPDATE.getMaxMessageBytes());
@@ -126,7 +133,7 @@ public void deleteTopic() {
         Assertions.assertFalse(topicsList.isTopicVisible(TOPIC_FOR_DELETE.getName()), "isTopicVisible");
         TOPIC_LIST.remove(TOPIC_FOR_DELETE);
     }
-
+    
     @DisplayName("produce message")
     @Suite(suiteId = SUITE_ID, title = SUITE_TITLE)
     @AutomationStatus(status = Status.AUTOMATED)
@@ -137,24 +144,55 @@ void produceMessage() {
                 .openSideMenu(TOPICS);
         topicsList
                 .waitUntilScreenReady()
-                .openTopic(TOPIC_FOR_UPDATE.getName());
+                .openTopic(TOPIC_FOR_MESSAGES.getName());
         topicDetails
                 .waitUntilScreenReady()
                 .openTopicMenu(TopicDetails.TopicMenu.MESSAGES)
                 .clickProduceMessageBtn();
         produceMessagePanel
                 .waitUntilScreenReady()
-                .setContentFiled(TOPIC_FOR_UPDATE.getMessageContent())
-                .setKeyField(TOPIC_FOR_UPDATE.getMessageKey())
+                .setContentFiled(TOPIC_FOR_MESSAGES.getMessageContent())
+                .setKeyField(TOPIC_FOR_MESSAGES.getMessageKey())
                 .submitProduceMessage();
         topicDetails
                 .waitUntilScreenReady();
         SoftAssertions softly = new SoftAssertions();
-        softly.assertThat(topicDetails.isKeyMessageVisible((TOPIC_FOR_UPDATE.getMessageKey()))).withFailMessage("isKeyMessageVisible()").isTrue();
-        softly.assertThat(topicDetails.isContentMessageVisible((TOPIC_FOR_UPDATE.getMessageContent()).trim())).withFailMessage("isContentMessageVisible()").isTrue();
+        softly.assertThat(topicDetails.isKeyMessageVisible((TOPIC_FOR_MESSAGES.getMessageKey()))).withFailMessage("isKeyMessageVisible()").isTrue();
+        softly.assertThat(topicDetails.isContentMessageVisible((TOPIC_FOR_MESSAGES.getMessageContent()).trim())).withFailMessage("isContentMessageVisible()").isTrue();
         softly.assertAll();
     }
 
+    @Issue("Uncomment last assertion after bug https://github.com/provectus/kafka-ui/issues/2778 fix")
+    @DisplayName("clear message")
+    @Suite(suiteId = SUITE_ID, title = SUITE_TITLE)
+    @AutomationStatus(status = Status.AUTOMATED)
+    @CaseId(19)
+    @Test
+    void clearMessage() {
+        naviSideBar
+                .openSideMenu(TOPICS);
+        topicsList
+                .waitUntilScreenReady()
+                .openTopic(TOPIC_FOR_MESSAGES.getName());
+        topicDetails
+                .waitUntilScreenReady()
+                .openTopicMenu(TopicDetails.TopicMenu.OVERVIEW)
+                .clickProduceMessageBtn();
+        produceMessagePanel
+                .waitUntilScreenReady()
+                .setContentFiled(TOPIC_FOR_MESSAGES.getMessageContent())
+                .setKeyField(TOPIC_FOR_MESSAGES.getMessageKey())
+                .submitProduceMessage();
+        topicDetails
+                .waitUntilScreenReady();
+        String messageAmount = topicDetails.MessageCountAmount();
+        Assertions.assertEquals(messageAmount,topicDetails.MessageCountAmount());
+        topicDetails
+                .openDotPartitionIdMenu()
+                .clickClearMessagesBtn();
+//        Assertions.assertEquals(Integer.toString(Integer.valueOf(messageAmount)-1),topicDetails.MessageCountAmount());
+    }
+
     @AfterAll
     public void afterAll() {
         TOPIC_LIST.forEach(topic -> apiHelper.deleteTopic(CLUSTER_NAME, topic.getName()));