Repository: provectus/kafka-ui
Issue: [e2e] Prepare steps for topic
Labels: type/enhancement
scope/QA
status/accepted

create a separate Class with steps src/test/java/com/provectus/kafka/ui/steps/kafka (TopicSteps.java)

 1. create steps such createTopic, deleteTopic, isTopicExist etc
See tests that should be automated https://docs.google.com/spreadsheets/d/1Vf6yZSqCYwh33t-pTy1PiYewk-jFSfPZppzIuUVVyO0/edit#gid=0
2. Remove all sleeps, if needed to some wait, all asserts should be in test

Refactor test class src/test/java/com/provectus/kafka/ui/tests/TopicTests.java with new steps


Issue comments:
is not actual as we agreed with the team due to useless of Steps class on current framework stage

Pull request review comments:

Patch that resolved the issue:
diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicCreateEditSettingsView.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicCreateEditSettingsView.java
index bd6bc8fc0de..b22821db44a 100644
--- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicCreateEditSettingsView.java
+++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicCreateEditSettingsView.java
@@ -21,7 +21,7 @@ public TopicCreateEditSettingsView setTopicName(String topicName) {
     }
 
     public TopicCreateEditSettingsView setMinInsyncReplicas(Integer minInsyncReplicas) {
-        $("input[name=minInsyncReplicas]").setValue(minInsyncReplicas.toString());
+        $("input[name=minInSyncReplicas]").setValue(minInsyncReplicas.toString());
         return this;
     }
 
diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicView.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicView.java
index a71d49e0f51..46e9d130ba5 100644
--- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicView.java
+++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicView.java
@@ -30,8 +30,8 @@ public TopicView goTo(String cluster, String topic) {
 
     @Step
     public TopicView isOnTopicViewPage() {
-        $(By.linkText("Overview")).shouldBe(Condition.visible);
-        return this;
+       $(By.linkText("Overview")).shouldBe(Condition.visible);
+       return this;
     }
 
     @SneakyThrows
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 cfd120f3a01..82a5bd37028 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
@@ -3,8 +3,8 @@
 import com.codeborne.selenide.CollectionCondition;
 import com.codeborne.selenide.Condition;
 import com.codeborne.selenide.Selenide;
-import com.provectus.kafka.ui.helpers.TestConfiguration;
 import com.provectus.kafka.ui.extensions.WaitUtils;
+import com.provectus.kafka.ui.helpers.TestConfiguration;
 import com.provectus.kafka.ui.utils.BrowserUtils;
 import io.qameta.allure.Step;
 import lombok.SneakyThrows;
@@ -32,18 +32,17 @@ public TopicsList isOnPage() {
     }
 
     @Step
-    public TopicCreateEditSettingsView pressCreateNewTopic(){
+    public TopicCreateEditSettingsView pressCreateNewTopic() {
         BrowserUtils.javaExecutorClick($x("//button[normalize-space(text()) ='Add a Topic']"));
         return new TopicCreateEditSettingsView();
     }
 
     @Step
-    public TopicsList isTopicVisible(String topicName) {
-        $$("tbody td>a")
+    public boolean isTopicVisible(String topicName) {
+        return $$("tbody td>a")
                 .shouldBe(CollectionCondition.sizeGreaterThan(4))
                 .find(Condition.exactText(topicName))
-                .shouldBe(Condition.visible);
-        return this;
+                .is(Condition.visible);
     }
 
     @SneakyThrows
@@ -53,12 +52,8 @@ public TopicView openTopic(String topicName) {
     }
 
     @SneakyThrows
-    public TopicsList isTopicNotVisible(String topicName) {
-        $$x("//table/tbody/tr/td[2]")
-                .shouldBe(CollectionCondition.sizeGreaterThanOrEqual(4))
-                .find(Condition.exactText(topicName))
-                .shouldBe(Condition.not(Condition.visible));
-        return this;
+    public boolean isTopicNotVisible(String topicName) {
+        return $$x("//table/tbody/tr/td[2]")
+                .find(Condition.exactText(topicName)).is(Condition.visible);
     }
-
 }


Test patch:
diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/steps/kafka/TopicSteps.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/steps/kafka/TopicSteps.java
new file mode 100644
index 00000000000..d179c33e5bb
--- /dev/null
+++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/steps/kafka/TopicSteps.java
@@ -0,0 +1,106 @@
+package com.provectus.kafka.ui.steps.kafka;
+
+import com.provectus.kafka.ui.pages.Pages;
+import com.provectus.kafka.ui.pages.topic.TopicView;
+import com.provectus.kafka.ui.pages.topic.TopicsList;
+import io.qameta.allure.Step;
+import lombok.SneakyThrows;
+
+import static org.apache.kafka.common.utils.Utils.readFileAsString;
+
+public class TopicSteps extends Pages {
+    private static final TopicSteps INSTANSE = new TopicSteps();
+
+    @Step("Create new topic")
+    public static TopicSteps createNewTopic(String topicName) {
+        new TopicsList().pressCreateNewTopic()
+                .setTopicName(topicName)
+                .sendData();
+        return INSTANSE;
+    }
+
+    @Step("Open topic list")
+    public static TopicSteps openTopicList(String topicName) {
+        new TopicsList().openTopic(topicName);
+        return INSTANSE;
+    }
+
+    @Step("Update topic")
+    public static TopicSteps updateTopic(String topicName, String policyValue, String timeToRetainValue, String maxSizeOnDisk, String MaxMessageBytes) {
+        new TopicsList().openTopic(topicName)
+                .isOnTopicViewPage()
+                .openEditSettings()
+                .selectCleanupPolicy(policyValue)
+                .setMinInsyncReplicas(10)
+                .setTimeToRetainDataInMs(timeToRetainValue)
+                .setMaxSizeOnDiskInGB(maxSizeOnDisk)
+                .setMaxMessageBytes(MaxMessageBytes)
+                .sendData()
+                .isOnTopicViewPage();
+        return INSTANSE;
+    }
+
+    @SneakyThrows
+    @Step("Produce message")
+    public static TopicSteps produceMessage(String topicName, String contentMessage, String keyMessage) {
+        new TopicsList().openTopic(topicName)
+                .openTopicMenu(TopicView.TopicMenu.MESSAGES)
+                .clickOnButton("Produce Message")
+                .setContentFiled(readFileAsString(contentMessage))
+                .setKeyField(readFileAsString(keyMessage))
+                .submitProduceMessage();
+        return INSTANSE;
+    }
+
+
+    @Step("Delete topic")
+    public static TopicSteps deleteTopic(String topicName) {
+        new TopicsList().openTopic(topicName)
+                .isOnTopicViewPage()
+                .deleteTopic();
+        return INSTANSE;
+    }
+
+
+    @Step("Is on topic view page")
+    public TopicView isOnTopicViewPage() {
+        return INSTANSE.topicView.isOnTopicViewPage();
+
+    }
+
+    @Step("Is on page")
+    public TopicsList isOnPage() {
+        return topicsList.isOnPage();
+    }
+
+    @Step("Is key message visible")
+    public static boolean isKeyMessageVisible(String messageText) {
+        return new TopicView().isKeyMessageVisible(messageText);
+    }
+
+    @Step("Is content message visible")
+    public static boolean isContentMessageVisible(String contentText) {
+        return new TopicView().isContentMessageVisible(contentText);
+    }
+
+
+    @Step("Is topic not visible")
+    public static boolean isTopicNotVisible(String topicName) {
+        return new TopicsList().isTopicNotVisible(topicName);
+
+    }
+
+
+    @Step("Is topic visible in the list")
+    public static boolean IsTopicVisible(String topicName) {
+        return new TopicsList().isTopicVisible(topicName);
+    }
+
+
+}
+
+
+
+
+
+
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 a962b8ceabb..260c23146ed 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
@@ -3,7 +3,7 @@
 import com.provectus.kafka.ui.base.BaseTest;
 import com.provectus.kafka.ui.helpers.Helpers;
 import com.provectus.kafka.ui.pages.MainPage;
-import com.provectus.kafka.ui.pages.topic.TopicView;
+import com.provectus.kafka.ui.steps.kafka.TopicSteps;
 import com.provectus.kafka.ui.utils.qaseIO.Status;
 import com.provectus.kafka.ui.utils.qaseIO.annotation.AutomationStatus;
 import com.provectus.kafka.ui.utils.qaseIO.annotation.Suite;
@@ -52,20 +52,14 @@ public static void afterAll() {
     public void createTopic() {
         pages.open()
                 .goToSideMenu(SECOND_LOCAL, MainPage.SideMenuOptions.TOPICS);
-        pages.topicsList.pressCreateNewTopic()
-                .setTopicName(NEW_TOPIC)
-                .sendData()
+        TopicSteps.createNewTopic(NEW_TOPIC)
                 .isOnTopicViewPage();
         pages.open()
-                .goToSideMenu(SECOND_LOCAL, MainPage.SideMenuOptions.TOPICS)
-                .topicIsVisible(NEW_TOPIC);
-        helpers.apiHelper.deleteTopic(SECOND_LOCAL, NEW_TOPIC);
-        pages.open()
-                .goToSideMenu(SECOND_LOCAL, MainPage.SideMenuOptions.TOPICS)
-                .topicIsNotVisible(NEW_TOPIC);
+                .goToSideMenu(SECOND_LOCAL, MainPage.SideMenuOptions.TOPICS);
+        Assertions.assertTrue(TopicSteps.IsTopicVisible(NEW_TOPIC));
     }
 
-    @Disabled("Due to issue https://github.com/provectus/kafka-ui/issues/1500 ignore this test")
+
     @SneakyThrows
     @DisplayName("should update a topic")
     @Issue("1500")
@@ -74,28 +68,9 @@ public void createTopic() {
     @CaseId(197)
     @Test
     public void updateTopic() {
-        pages.openTopicsList(SECOND_LOCAL)
-                .isOnPage();
-        pages.openTopicView(SECOND_LOCAL, TOPIC_TO_UPDATE)
-                .isOnTopicViewPage()
-                .openEditSettings()
-                .selectCleanupPolicy(COMPACT_POLICY_VALUE)
-                .setMinInsyncReplicas(10)
-                .setTimeToRetainDataInMs(UPDATED_TIME_TO_RETAIN_VALUE)
-                .setMaxSizeOnDiskInGB(UPDATED_MAX_SIZE_ON_DISK)
-                .setMaxMessageBytes(UPDATED_MAX_MESSAGE_BYTES)
-                .sendData()
-                .isOnTopicViewPage();
-
-        pages.openTopicsList(SECOND_LOCAL)
-                .isOnPage();
-        pages.openTopicView(SECOND_LOCAL, TOPIC_TO_UPDATE)
-                .openEditSettings()
-                // Assertions
-                .cleanupPolicyIs(COMPACT_POLICY_VALUE)
-                .timeToRetainIs(UPDATED_TIME_TO_RETAIN_VALUE)
-                .maxSizeOnDiskIs(UPDATED_MAX_SIZE_ON_DISK)
-                .maxMessageBytesIs(UPDATED_MAX_MESSAGE_BYTES);
+        pages.open()
+                .goToSideMenu(SECOND_LOCAL, MainPage.SideMenuOptions.TOPICS);
+        TopicSteps.updateTopic(TOPIC_TO_UPDATE, COMPACT_POLICY_VALUE, UPDATED_TIME_TO_RETAIN_VALUE, UPDATED_MAX_SIZE_ON_DISK, UPDATED_MAX_MESSAGE_BYTES);
     }
 
     @SneakyThrows
@@ -106,13 +81,10 @@ public void updateTopic() {
     @Test
     @Disabled // TODO: https://github.com/provectus/kafka-ui/issues/2373
     public void deleteTopic() {
-        pages.openTopicsList(SECOND_LOCAL)
-                .isOnPage()
-                .openTopic(TOPIC_TO_DELETE)
-                .isOnTopicViewPage()
-                .deleteTopic()
-                .isOnPage()
-                .isTopicNotVisible(TOPIC_TO_DELETE);
+        pages.open()
+                .goToSideMenu(SECOND_LOCAL, MainPage.SideMenuOptions.TOPICS);
+        TopicSteps.deleteTopic(TOPIC_TO_DELETE);
+        Assertions.assertFalse(TopicSteps.isTopicNotVisible(TOPIC_TO_DELETE));
     }
 
     @SneakyThrows
@@ -122,16 +94,10 @@ public void deleteTopic() {
     @CaseId(222)
     @Test
     void produceMessage() {
-        pages.openTopicsList(SECOND_LOCAL)
-                .isOnPage()
-                .openTopic(TOPIC_TO_UPDATE)
-                .isOnTopicViewPage()
-                .openTopicMenu(TopicView.TopicMenu.MESSAGES)
-                .clickOnButton("Produce Message")
-                .setContentFiled(readFileAsString(CONTENT_TO_PRODUCE_MESSAGE))
-                .setKeyField(readFileAsString(KEY_TO_PRODUCE_MESSAGE))
-                .submitProduceMessage();
-        Assertions.assertTrue(pages.topicView.isKeyMessageVisible(readFileAsString(KEY_TO_PRODUCE_MESSAGE)));
-        Assertions.assertTrue(pages.topicView.isContentMessageVisible(readFileAsString(CONTENT_TO_PRODUCE_MESSAGE).trim()));
+        pages.open()
+                .goToSideMenu(SECOND_LOCAL, MainPage.SideMenuOptions.TOPICS);
+        TopicSteps.produceMessage(TOPIC_TO_UPDATE, CONTENT_TO_PRODUCE_MESSAGE, KEY_TO_PRODUCE_MESSAGE);
+        Assertions.assertTrue(TopicSteps.isKeyMessageVisible(readFileAsString(KEY_TO_PRODUCE_MESSAGE)));
+        Assertions.assertTrue(TopicSteps.isContentMessageVisible(readFileAsString(CONTENT_TO_PRODUCE_MESSAGE).trim()));
     }
 }