Repository: provectus/kafka-ui
Issue: [e2e]Checking messages filtering by Offset within Topic/Messages
Labels: scope/QA
status/accepted
scope/AQA

Autotest implementation for:

https://app.qase.io/case/KAFKAUI-15

Description:
Checking messages filtering by Offset within Messages/Topic

Pre-conditions:

- Login to Kafka-ui application
- Open the 'Local' section
- Select the 'Topics'
- Open the Topic profile
- Turn to Messages tab

Steps:
1. Enter the value in Offset input field
Input data:
"1"
2. Click 'Submit' button
Expected result:
Messages which have the entered Offset should be filtered

Issue comments:

Pull request review comments:
why do we need to define variable? topic name is used only once, so let's specify it directly to openTopic(). fix it also at 104 line pls
we already made methods like navigateToTopicsAndOpenDetails() and I've asked u to use them when the navigation is not the main scope of test
does it have only @id='offset' or it depends on seekTypeDdl?
1. add linebreak before forEach() pls
2. ur assertion doesn't work because u missed isTrue() at the end
3. u missed as() method to add assertion description
4. offset instance as far as i know is always integer, that's why i made getOffset() return int. why did u set setOffsetMessagesField() to handle string? Integer.parseInt(offsetValue) looks kinky
is there any //select element in DOM?
change method to handle integer
done
Done
refactored to $x("//label[text()='Seek Type']//..//input");
1. done
2. done
3. done
4. done
done

nothing elements with select
as we discussed, this field also can get date value, so we need to change int argument to String and set String.valueOf(seekTypeValue) from test
done
ok but what about method name?
renamed to setSeekTypeValueFldMessagesTab()

Patch that resolved the issue:
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 4a38e7909d7..6b328ab22e0 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
@@ -1,18 +1,20 @@
 package com.provectus.kafka.ui.pages.topic;
 
+import static com.codeborne.selenide.Selenide.$;
+import static com.codeborne.selenide.Selenide.$$x;
+import static com.codeborne.selenide.Selenide.$x;
+import static org.apache.commons.lang.math.RandomUtils.nextInt;
+
 import com.codeborne.selenide.CollectionCondition;
 import com.codeborne.selenide.Condition;
 import com.codeborne.selenide.ElementsCollection;
 import com.codeborne.selenide.SelenideElement;
 import com.provectus.kafka.ui.pages.BasePage;
 import io.qameta.allure.Step;
-import org.openqa.selenium.By;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-
-import static com.codeborne.selenide.Selenide.*;
-import static org.apache.commons.lang.math.RandomUtils.nextInt;
+import org.openqa.selenium.By;
 
 public class TopicDetails extends BasePage {
 
@@ -20,6 +22,8 @@ public class TopicDetails extends BasePage {
   protected SelenideElement messageAmountCell = $x("//tbody/tr/td[5]");
   protected SelenideElement overviewTab = $x("//a[contains(text(),'Overview')]");
   protected SelenideElement messagesTab = $x("//a[contains(text(),'Messages')]");
+  protected SelenideElement seekTypeDdl = $x("//ul[@id='selectSeekType']/li");
+  protected SelenideElement seekTypeField = $x("//label[text()='Seek Type']//..//input");
   protected SelenideElement addFiltersBtn = $x("//button[text()='Add Filters']");
   protected SelenideElement savedFiltersLink = $x("//div[text()='Saved Filters']");
   protected SelenideElement addFilterCodeModalTitle = $x("//label[text()='Filter code']");
@@ -38,6 +42,7 @@ public class TopicDetails extends BasePage {
   protected SelenideElement partitionsField = $x("//div[contains(text(),'Partitions')]/../span");
   protected SelenideElement backToCreateFiltersLink = $x("//div[text()='Back To create filters']");
   protected ElementsCollection messageGridItems = $$x("//tbody//tr");
+  protected String seekFilterDdlLocator = "//ul[@id='selectSeekType']/ul/li[text()='%s']";
   protected String savedFilterNameLocator = "//div[@role='savedFilter']/div[contains(text(),'%s')]";
   protected String consumerIdLocator = "//a[@title='%s']";
   protected String topicHeaderLocator = "//h1[contains(text(),'%s')]";
@@ -120,6 +125,26 @@ public TopicDetails clickProduceMessageBtn() {
     return this;
   }
 
+  @Step
+  public TopicDetails selectSeekTypeDdlMessagesTab(String seekTypeName){
+    seekTypeDdl.shouldBe(Condition.enabled).click();
+    $x(String.format(seekFilterDdlLocator, seekTypeName)).shouldBe(Condition.visible).click();
+    return this;
+  }
+
+  @Step
+  public TopicDetails setSeekTypeValueFldMessagesTab(String seekTypeValue){
+    seekTypeField.shouldBe(Condition.enabled).sendKeys(seekTypeValue);
+    return this;
+  }
+
+  @Step
+  public TopicDetails clickSubmitFiltersBtnMessagesTab(){
+    clickByJavaScript(submitBtn);
+    waitUntilSpinnerDisappear();
+    return this;
+  }
+
   @Step
   public TopicDetails clickMessagesAddFiltersBtn() {
     addFiltersBtn.shouldBe(Condition.enabled).click();
@@ -248,6 +273,11 @@ public TopicDetails.MessageGridItem getMessage(int offset) {
         .findFirst().orElse(null);
   }
 
+  @Step
+  public List<MessageGridItem> getAllMessages(){
+    return initItems();
+  }
+
   @Step
   public TopicDetails.MessageGridItem getRandomMessage() {
     return getMessage(nextInt(initItems().size() - 1));


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 8fbf915d543..67d531c8a67 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
@@ -1,7 +1,7 @@
 package com.provectus.kafka.ui.suite.topics;
 
 import static com.provectus.kafka.ui.pages.BasePage.AlertHeader.SUCCESS;
-import static com.provectus.kafka.ui.pages.NaviSideBar.SideMenuOption.TOPICS;
+import static com.provectus.kafka.ui.pages.topic.TopicDetails.TopicMenu.MESSAGES;
 import static com.provectus.kafka.ui.settings.Source.CLUSTER_NAME;
 import static com.provectus.kafka.ui.utilities.FileUtils.fileToString;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
@@ -59,8 +59,10 @@ void produceMessage() {
     topicDetails
         .waitUntilScreenReady();
     SoftAssertions softly = new SoftAssertions();
-    softly.assertThat(topicDetails.isKeyMessageVisible((TOPIC_FOR_MESSAGES.getMessageKey()))).withFailMessage("isKeyMessageVisible()").isTrue();
-    softly.assertThat(topicDetails.isContentMessageVisible((TOPIC_FOR_MESSAGES.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();
   }
 
@@ -100,8 +102,7 @@ void clearMessage() {
   @CaseId(21)
   @Test
   void copyMessageFromTopicProfile() {
-    String topicName = "_schemas";
-    navigateToTopicsAndOpenDetails(topicName);
+    navigateToTopicsAndOpenDetails("_schemas");
     topicDetails
         .openDetailsTab(TopicDetails.TopicMenu.MESSAGES)
         .getRandomMessage()
@@ -111,6 +112,28 @@ void copyMessageFromTopicProfile() {
         "isAlertWithMessageVisible()");
   }
 
+  @Disabled
+  @Issue("https://github.com/provectus/kafka-ui/issues/2856")
+  @DisplayName("Checking messages filtering by Offset within Topic/Messages")
+  @Suite(suiteId = SUITE_ID, title = SUITE_TITLE)
+  @AutomationStatus(status = Status.AUTOMATED)
+  @CaseId(15)
+  @Test
+  void checkingMessageFilteringByOffset() {
+    String offsetValue = "2";
+    navigateToTopicsAndOpenDetails("_schemas");
+    topicDetails
+        .openDetailsTab(MESSAGES)
+        .selectSeekTypeDdlMessagesTab("Offset")
+        .setSeekTypeValueFldMessagesTab(offsetValue)
+        .clickSubmitFiltersBtnMessagesTab();
+    SoftAssertions softly = new SoftAssertions();
+    topicDetails.getAllMessages()
+        .forEach(messages -> softly.assertThat(messages.getOffset() == Integer.parseInt(offsetValue))
+        .as("getAllMessages()").isTrue());
+    softly.assertAll();
+  }
+
   @AfterAll
   public void afterAll() {
     TOPIC_LIST.forEach(topic -> apiHelper.deleteTopic(CLUSTER_NAME, topic.getName()));