Repository: provectus/kafka-ui
Issue: [e2e]TopicTests.purgeMessagesOfTopics : Purge messages of topics
Labels: scope/QA
scope/AQA

Autotest implementation for:

https://app.qase.io/case/KAFKAUI-10
Description:
Checking possibility to Purge messages of the selected Topic from All Topics' list

Pre-conditions:
1)Login to Kafka-ui application
2)Open the 'Local' section
3)Select the 'Topics'
4)Create a new Topic
5)Add message into a new created Topic

Post-conditions:
Not set

Steps:
1)Check the previously created Topic from All Topics' list
2)Click on 'Purge messages of selected topics'
3)Press 'Cancel' button
4)Click on 'Purge messages of selected topics'
5)Click 'Confirm' button
6)Turn to 'Messages' tab of the selected Topic

Expected results:
1)Make sure 'Delete selected topics', 'Copy selected topic', 'Purge messages of selected topics' are displayed
2)Should appear 'Confirm the action' pop up for confirmation deleting the topic with following information: 'Are you sure you want to purge messages of selected topics?' message, 'Cancel' and 'Confirm buttons
3)'Confirm the action' pop up should disappear
4)Make sure the pop up 'Confirm the action' opened again
5)'[Topic name] Messages have been successfully cleared!' success message should appear
6)Should not be displayed the messages

Issue comments:

Pull request review comments:
can't we reuse TOPIC_TO_CLEAR_MESSAGES in this test to not create a lot of instances. u can rename it to TOPIC_TO_CLEAR_AND_PURGE_MESSAGES
I believe we can place this test after @Order(4)
Fixed.

Patch that resolved the issue:
diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/BasePage.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/BasePage.java
index 8b12d3b0d3f..afe95432ca8 100644
--- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/BasePage.java
+++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/BasePage.java
@@ -19,7 +19,9 @@ public abstract class BasePage extends WebUtils {
   protected SelenideElement dotMenuBtn = $x("//button[@aria-label='Dropdown Toggle']");
   protected SelenideElement alertHeader = $x("//div[@role='alert']//div[@role='heading']");
   protected SelenideElement alertMessage = $x("//div[@role='alert']//div[@role='contentinfo']");
+  protected SelenideElement confirmationMdl = $x("//div[text()= 'Confirm the action']/..");
   protected SelenideElement confirmBtn = $x("//button[contains(text(),'Confirm')]");
+  protected SelenideElement cancelBtn = $x("//button[contains(text(),'Cancel')]");
   protected ElementsCollection allGridItems = $$x("//tr[@class]");
   protected String summaryCellLocator = "//div[contains(text(),'%s')]";
   protected String tableElementNameLocator = "//tbody//a[contains(text(),'%s')]";
@@ -74,6 +76,15 @@ protected void clickConfirmButton() {
     confirmBtn.shouldBe(Condition.disappear);
   }
 
+  protected void clickCancelButton() {
+    cancelBtn.shouldBe(Condition.enabled).click();
+    cancelBtn.shouldBe(Condition.disappear);
+  }
+
+  protected boolean isConfirmationModalVisible() {
+    return isVisible(confirmationMdl);
+  }
+
   public enum AlertHeader {
     SUCCESS("Success"),
     VALIDATION_ERROR("Validation Error"),
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 1de0478abec..119f602a402 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
@@ -51,7 +51,6 @@ public class TopicDetails extends BasePage {
   protected SelenideElement cleanUpPolicyField = $x("//div[contains(text(),'Clean Up Policy')]/../span/*");
   protected SelenideElement partitionsField = $x("//div[contains(text(),'Partitions')]/../span");
   protected SelenideElement backToCreateFiltersLink = $x("//div[text()='Back To create filters']");
-  protected SelenideElement confirmationMdl = $x("//div[text()= 'Confirm the action']/..");
   protected ElementsCollection messageGridItems = $$x("//tbody//tr");
   protected SelenideElement actualCalendarDate = $x("//div[@class='react-datepicker__current-month']");
   protected SelenideElement previousMonthButton = $x("//button[@aria-label='Previous Month']");
@@ -103,7 +102,7 @@ public TopicDetails clickEditSettingsMenu() {
 
   @Step
   public boolean isConfirmationMdlVisible(){
-    return isVisible(confirmationMdl);
+    return isConfirmationModalVisible();
   }
 
   @Step
diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicsList.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicsList.java
index 9db1d18c8bd..6280ffe8a47 100644
--- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicsList.java
+++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicsList.java
@@ -87,6 +87,12 @@ public TopicsList clickCopySelectedTopicBtn(){
       return this;
     }
 
+    @Step
+    public TopicsList clickPurgeMessagesOfSelectedTopicsBtn(){
+    purgeMessagesOfSelectedTopicsBtn.shouldBe(Condition.enabled).click();
+    return this;
+    }
+
     @Step
     public TopicsList clickClearMessagesBtn(){
       clickByJavaScript(clearMessagesBtn.shouldBe(visible));
@@ -111,6 +117,17 @@ public TopicsList clickConfirmBtnMdl() {
     return this;
     }
 
+    @Step
+    public TopicsList clickCancelBtnMdl(){
+      clickCancelButton();
+      return this;
+    }
+
+    @Step
+    public boolean isConfirmationMdlVisible(){
+      return isConfirmationModalVisible();
+    }
+
     @Step
     public boolean isAlertWithMessageVisible(AlertHeader header, String message) {
       return isAlertVisible(header, message);


Test patch:
diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/suite/topics/TopicMessagesTests.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/suite/topics/TopicMessagesTests.java
index 205707a263e..4993a2d4837 100644
--- a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/suite/topics/TopicMessagesTests.java
+++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/suite/topics/TopicMessagesTests.java
@@ -40,8 +40,8 @@ public class TopicMessagesTests extends BaseTest {
       .setName("topic-with-clean-message-attribute-" + randomAlphabetic(5))
       .setMessageKey(randomAlphabetic(5))
       .setMessageContent(randomAlphabetic(10));
-  private static final Topic TOPIC_TO_CLEAR_MESSAGES = new Topic()
-      .setName("topic-to-clear-message-attribute-" + randomAlphabetic(5))
+  private static final Topic TOPIC_TO_CLEAR_AND_PURGE_MESSAGES = new Topic()
+      .setName("topic-to-clear-and-purge-messages-attribute-" + randomAlphabetic(5))
       .setMessageKey(randomAlphabetic(5))
       .setMessageContent(randomAlphabetic(10));
   private static final Topic TOPIC_FOR_CHECKING_FILTERS = new Topic()
@@ -56,7 +56,8 @@ public class TopicMessagesTests extends BaseTest {
 
   @BeforeAll
   public void beforeAll() {
-    TOPIC_LIST.addAll(List.of(TOPIC_FOR_MESSAGES, TOPIC_FOR_CHECKING_FILTERS, TOPIC_TO_CLEAR_MESSAGES, TOPIC_TO_RECREATE));
+    TOPIC_LIST.addAll(List.of(TOPIC_FOR_MESSAGES, TOPIC_FOR_CHECKING_FILTERS, TOPIC_TO_CLEAR_AND_PURGE_MESSAGES,
+        TOPIC_TO_RECREATE));
     TOPIC_LIST.forEach(topic -> apiService.createTopic(topic.getName()));
     IntStream.range(1, 3).forEach(i -> apiService.sendMessage(TOPIC_FOR_CHECKING_FILTERS));
     waitUntilNewMinuteStarted();
@@ -111,22 +112,57 @@ void clearMessage() {
   @Order(3)
   @Test
   void checkClearTopicMessage() {
-    navigateToTopicsAndOpenDetails(TOPIC_TO_CLEAR_MESSAGES.getName());
+    navigateToTopicsAndOpenDetails(TOPIC_TO_CLEAR_AND_PURGE_MESSAGES.getName());
     topicDetails
         .openDetailsTab(OVERVIEW);
-    produceMessage(TOPIC_TO_CLEAR_MESSAGES);
+    produceMessage(TOPIC_TO_CLEAR_AND_PURGE_MESSAGES);
     navigateToTopics();
-    assertThat(topicsList.getTopicItem(TOPIC_TO_CLEAR_MESSAGES.getName()).getNumberOfMessages())
+    assertThat(topicsList.getTopicItem(TOPIC_TO_CLEAR_AND_PURGE_MESSAGES.getName()).getNumberOfMessages())
         .as("getNumberOfMessages()").isEqualTo(1);
     topicsList
-        .openDotMenuByTopicName(TOPIC_TO_CLEAR_MESSAGES.getName())
+        .openDotMenuByTopicName(TOPIC_TO_CLEAR_AND_PURGE_MESSAGES.getName())
         .clickClearMessagesBtn()
         .clickConfirmBtnMdl();
     SoftAssertions softly = new SoftAssertions();
     softly.assertThat(topicsList.isAlertWithMessageVisible(SUCCESS,
-            String.format("%s messages have been successfully cleared!", TOPIC_TO_CLEAR_MESSAGES.getName())))
+            String.format("%s messages have been successfully cleared!", TOPIC_TO_CLEAR_AND_PURGE_MESSAGES.getName())))
         .as("isAlertWithMessageVisible()").isTrue();
-    softly.assertThat(topicsList.getTopicItem(TOPIC_TO_CLEAR_MESSAGES.getName()).getNumberOfMessages())
+    softly.assertThat(topicsList.getTopicItem(TOPIC_TO_CLEAR_AND_PURGE_MESSAGES.getName()).getNumberOfMessages())
+        .as("getNumberOfMessages()").isEqualTo(0);
+    softly.assertAll();
+  }
+
+  @DisplayName("TopicTests.purgeMessagesOfTopics : Purge messages of topics")
+  @Suite(suiteId = SUITE_ID, title = SUITE_TITLE)
+  @AutomationStatus(status = Status.AUTOMATED)
+  @CaseId(10)
+  @Order(4)
+  @Test
+  void checkPurgeMessagePossibility(){
+    navigateToTopics();
+    int messageAmount = topicsList.getTopicItem(TOPIC_TO_CLEAR_AND_PURGE_MESSAGES.getName()).getNumberOfMessages();
+    topicsList
+        .openTopic(TOPIC_TO_CLEAR_AND_PURGE_MESSAGES.getName());
+    topicDetails
+        .openDetailsTab(OVERVIEW);
+    produceMessage(TOPIC_TO_CLEAR_AND_PURGE_MESSAGES);
+    navigateToTopics();
+    assertThat(topicsList.getTopicItem(TOPIC_TO_CLEAR_AND_PURGE_MESSAGES.getName()).getNumberOfMessages())
+        .as("getNumberOfMessages()").isEqualTo(messageAmount +1);
+    topicsList
+        .getTopicItem(TOPIC_TO_CLEAR_AND_PURGE_MESSAGES.getName())
+        .selectItem(true)
+        .clickPurgeMessagesOfSelectedTopicsBtn();
+    assertThat(topicsList.isConfirmationMdlVisible()).as("isConfirmationMdlVisible()").isTrue();
+    topicsList
+        .clickCancelBtnMdl()
+        .clickPurgeMessagesOfSelectedTopicsBtn()
+        .clickConfirmBtnMdl();
+    SoftAssertions softly = new SoftAssertions();
+    softly.assertThat(topicsList.isAlertWithMessageVisible(SUCCESS,
+            String.format("%s messages have been successfully cleared!",TOPIC_TO_CLEAR_AND_PURGE_MESSAGES.getName())))
+        .as("isAlertWithMessageVisible()").isTrue();
+    softly.assertThat(topicsList.getTopicItem(TOPIC_TO_CLEAR_AND_PURGE_MESSAGES.getName()).getNumberOfMessages())
         .as("getNumberOfMessages()").isEqualTo(0);
     softly.assertAll();
   }
@@ -137,7 +173,7 @@ void checkClearTopicMessage() {
   @Suite(suiteId = SUITE_ID, title = SUITE_TITLE)
   @AutomationStatus(status = Status.AUTOMATED)
   @CaseId(21)
-  @Order(4)
+  @Order(5)
   @Test
   void copyMessageFromTopicProfile() {
     navigateToTopicsAndOpenDetails(TOPIC_FOR_CHECKING_FILTERS.getName());
@@ -156,7 +192,7 @@ void copyMessageFromTopicProfile() {
   @Suite(suiteId = SUITE_ID, title = SUITE_TITLE)
   @AutomationStatus(status = Status.AUTOMATED)
   @CaseId(15)
-  @Order(5)
+  @Order(6)
   @Test
   void checkingMessageFilteringByOffset() {
     navigateToTopicsAndOpenDetails(TOPIC_FOR_CHECKING_FILTERS.getName());
@@ -183,7 +219,7 @@ void checkingMessageFilteringByOffset() {
   @Suite(suiteId = SUITE_ID, title = SUITE_TITLE)
   @AutomationStatus(status = Status.AUTOMATED)
   @CaseId(16)
-  @Order(6)
+  @Order(7)
   @Test
   void checkingMessageFilteringByTimestamp() {
     navigateToTopicsAndOpenDetails(TOPIC_FOR_CHECKING_FILTERS.getName());
@@ -215,7 +251,7 @@ void checkingMessageFilteringByTimestamp() {
   @Suite(suiteId = SUITE_ID, title = SUITE_TITLE)
   @AutomationStatus(status = Status.AUTOMATED)
   @CaseId(246)
-  @Order(7)
+  @Order(8)
   @Test
   void checkClearTopicMessageFromOverviewTab() {
     navigateToTopicsAndOpenDetails(TOPIC_FOR_CHECKING_FILTERS.getName());
@@ -237,7 +273,7 @@ void checkClearTopicMessageFromOverviewTab() {
   @Suite(suiteId = SUITE_ID, title = SUITE_TITLE)
   @AutomationStatus(status = Status.AUTOMATED)
   @CaseId(240)
-  @Order(8)
+  @Order(9)
   @Test
   void checkRecreateTopic(){
     navigateToTopicsAndOpenDetails(TOPIC_TO_RECREATE.getName());