Repository: provectus/kafka-ui
Issue: [e2e]Checking Messages count per page within Topic
Labels: scope/QA
scope/AQA

Autotest implementation for:

https://app.qase.io/case/KAFKAUI-267

Pre-conditions:
-Create a Topic
-Add more than 100 messages to Topic

Steps:
- Login to Kafka-ui
- Navigate to Topics
- Select the previously added Topic
- Turn to Messages tab
- Press Next to turn second page

Expected results:
- First 100 messages should be displayed within first page with active Next button and disabled Back button
- Messages (from 101) should be displayed within second page

Issue comments:

Pull request review comments:
1. lets's remove signs from locators -> use 'contains'
2. seems that buttons could be shared in several page classes, suggest to store them in BasePage.class from the start
1. we need to add some wait until message list loaded after opening tab or navigation between pages, because getAllMessages().size() will not be 100 at the time you open the tab Messages (inspect the UI behavior)
2. also here we need to add assertion that page is really changed, current implementation will not face linked issue
Fixed
Fixed
get(messagesPerPage) -> get(messagesPerPage - 1)
assertNotEquals -> assertEquals
signs still there
Fixed.
Removed.
Fixed.
fix the link pls
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 e51942a39ce..c131bd8e0d1 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
@@ -23,6 +23,8 @@ public abstract class BasePage extends WebUtils {
     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 SelenideElement backBtn = $x("//button[contains(text(),'Back')]");
+    protected SelenideElement nextBtn = $x("//button[contains(text(),'Next')]");
     protected ElementsCollection ddlOptions = $$x("//li[@value]");
     protected ElementsCollection gridItems = $$x("//tr[@class]");
     protected String summaryCellLocator = "//div[contains(text(),'%s')]";
diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topics/TopicDetails.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topics/TopicDetails.java
index 980a66b791d..a99afd903b6 100644
--- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topics/TopicDetails.java
+++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topics/TopicDetails.java
@@ -170,6 +170,13 @@ public TopicDetails clickMessagesAddFiltersBtn() {
         return this;
     }
 
+    @Step
+    public TopicDetails clickNextButton() {
+      nextBtn.shouldBe(Condition.enabled).click();
+      waitUntilSpinnerDisappear();
+      return this;
+    }
+
     @Step
     public TopicDetails openSavedFiltersListMdl() {
         savedFiltersLink.shouldBe(Condition.enabled).click();
@@ -240,6 +247,16 @@ public boolean isAddFilterBtnAddFilterMdlEnabled() {
         return isEnabled(addFilterBtnAddFilterMdl);
     }
 
+    @Step
+    public boolean isBackButtonEnabled() {
+        return isEnabled(backBtn);
+    }
+
+    @Step
+    public boolean isNextButtonEnabled() {
+      return isEnabled(nextBtn);
+    }
+
     @Step
     public boolean isActiveFilterVisible(String activeFilterName) {
         return isVisible($x(String.format(activeFilterNameLocator, activeFilterName)));


Test patch:
diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/smokeSuite/topics/MessagesTest.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/smokeSuite/topics/MessagesTest.java
index 2dee8588d79..5e5af5c0448 100644
--- a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/smokeSuite/topics/MessagesTest.java
+++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/smokeSuite/topics/MessagesTest.java
@@ -9,6 +9,7 @@
 import io.qameta.allure.Issue;
 import io.qameta.allure.Step;
 import io.qase.api.annotation.CaseId;
+import io.qase.api.annotation.QaseId;
 import org.testng.Assert;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
@@ -48,16 +49,21 @@ public class MessagesTest extends BaseTest {
             .setName("topic-to-recreate-attribute-" + randomAlphabetic(5))
             .setMessageKey(randomAlphabetic(5))
             .setMessageContent(randomAlphabetic(10));
+    private static final Topic TOPIC_FOR_CHECK_MESSAGES_COUNT = new Topic()
+             .setName("topic-for-check-messages-count" + randomAlphabetic(5))
+             .setMessageKey(randomAlphabetic(5))
+             .setMessageContent(randomAlphabetic(10));
     private static final List<Topic> TOPIC_LIST = new ArrayList<>();
 
     @BeforeClass(alwaysRun = true)
     public void beforeClass() {
         TOPIC_LIST.addAll(List.of(TOPIC_FOR_MESSAGES, TOPIC_FOR_CHECKING_FILTERS, TOPIC_TO_CLEAR_AND_PURGE_MESSAGES,
-                TOPIC_TO_RECREATE));
+                TOPIC_TO_RECREATE, TOPIC_FOR_CHECK_MESSAGES_COUNT));
         TOPIC_LIST.forEach(topic -> apiService.createTopic(topic.getName()));
         IntStream.range(1, 3).forEach(i -> apiService.sendMessage(TOPIC_FOR_CHECKING_FILTERS));
         waitUntilNewMinuteStarted();
         IntStream.range(1, 3).forEach(i -> apiService.sendMessage(TOPIC_FOR_CHECKING_FILTERS));
+        IntStream.range(1, 110).forEach(i -> apiService.sendMessage(TOPIC_FOR_CHECK_MESSAGES_COUNT));
     }
 
     @Suite(suiteId = SUITE_ID, title = SUITE_TITLE)
@@ -272,6 +278,31 @@ public void checkRecreateTopic() {
         softly.assertAll();
     }
 
+    @Ignore
+    @Issue("https://github.com/provectus/kafka-ui/issues/3129")
+    @QaseId(267)
+    @Test(priority = 10)
+    public void CheckMessagesCountPerPageWithinTopic() {
+        navigateToTopicsAndOpenDetails(TOPIC_FOR_CHECK_MESSAGES_COUNT.getName());
+        topicDetails
+                .openDetailsTab(MESSAGES);
+        int messagesPerPage = topicDetails.getAllMessages().size();
+        SoftAssert softly = new SoftAssert();
+        softly.assertEquals(messagesPerPage, 100, "getAllMessages()");
+        softly.assertFalse(topicDetails.isBackButtonEnabled(), "isBackButtonEnabled()");
+        softly.assertTrue(topicDetails.isNextButtonEnabled(), "isNextButtonEnabled()");
+        softly.assertAll();
+        int lastOffsetOnPage = topicDetails.getAllMessages()
+                        .get(messagesPerPage -1).getOffset();
+        topicDetails
+                .clickNextButton();
+        softly.assertEquals(topicDetails.getAllMessages().stream().findFirst().orElseThrow().getOffset(),
+                lastOffsetOnPage + 1, "findFirst().getOffset()");
+        softly.assertTrue(topicDetails.isBackButtonEnabled(), "isBackButtonEnabled()");
+        softly.assertFalse(topicDetails.isNextButtonEnabled(), "isNextButtonEnabled()");
+        softly.assertAll();
+    }
+
     @Step
     protected void produceMessage(Topic topic) {
         topicDetails