Repository: provectus/kafka-ui
Issue: [e2e] Checking Filter adding within Topics/Topic/Messages with filled required fields
Labels: scope/AQA

Autotest implementation for:
https://app.qase.io/project/KAFKAUI?view=1&suite=5&previewMode=side&case=12

Description:
Checking Filter adding within Topics/Topic profile/Messages tab

Preconditions:
Login to Kafka-ui application

Open the 'Local' section

Select the 'Topics'

Steps:
1 Open any Topic's profile
2 Turn to 'Messages' tab
3 Press 'Add Filters'

Expected result
'Add filter ' pop up should open with following information:
''Saved filters' link, 'Filter code' field, 'Save this filter' checkbox (unchecked by default), 'Display name' input field, 'Cancel' active and 'Add' disabled by default buttons

4 Fill 'Filter code' input field

Expected result
'Add' button should become active

5 Press 'Add' button

Expected result:
1 'Add filter' pop up should disappear
2 New filter should appear near '+Add Filters' button
3 Corresponding data should display



Issue comments:

Pull request review comments:
you're getting text from le element found by that text? no reason in this method, we need or to find filter name by another locator and assert text or assert that element found by text is visible
1 we agreed use assertions only inside test classes
2I meant create this method with modal element(s) (for example use addFilterCodeModalTitle) shouldBe(visible) only
3 do not forget that we're waiting enabled and disabled elements are visible too
4 looks according to AC disabled element is only addFilterBtnAddFilterMdl, so we can create isAddFilterBtnAddFilterModalEnable() method instead of getAllAddFilterModalDisabledElements()

Done
I refactored assertion block of code, and hope that I understood you correctly

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 9ac485c26b7..e968d4f9372 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
@@ -13,6 +13,7 @@
 import com.provectus.kafka.ui.utilities.WaitUtils;
 import io.qameta.allure.Step;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import lombok.experimental.ExtensionMethod;
 import org.openqa.selenium.By;
@@ -24,6 +25,14 @@ 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 addFiltersBtn = $x("//button[text()='Add Filters']");
+  protected SelenideElement savedFiltersField = $x("//div[text()='Saved Filters']");
+  protected SelenideElement addFilterCodeModalTitle = $x("//label[text()='Filter code']");
+  protected SelenideElement addFilterCodeInput = $x("//div[@id='ace-editor']//textarea");
+  protected SelenideElement saveThisFilterCheckBoxAddFilterMdl = $x("//input[@name='saveFilter']");
+  protected SelenideElement displayNameInputAddFilterMdl = $x("//input[@placeholder='Enter Name']");
+  protected SelenideElement cancelBtnAddFilterMdl = $x("//button[text()='Cancel']");
+  protected SelenideElement addFilterBtnAddFilterMdl = $x("//button[text()='Add filter']");
   protected SelenideElement editSettingsMenu = $x("//li[@role][contains(text(),'Edit settings')]");
   protected SelenideElement removeTopicBtn = $x("//ul[@role='menu']//div[contains(text(),'Remove Topic')]");
   protected SelenideElement confirmBtn = $x("//div[@role='dialog']//button[contains(text(),'Confirm')]");
@@ -34,6 +43,7 @@ public class TopicDetails extends BasePage {
   protected ElementsCollection messageGridItems = $$x("//tbody//tr");
   protected String consumerIdLocator = "//a[@title='%s']";
   protected String topicHeaderLocator = "//h1[contains(text(),'%s')]";
+  protected String filterNameLocator = "//*[@data-testid='activeSmartFilter']";
 
   @Step
   public TopicDetails waitUntilScreenReady() {
@@ -106,6 +116,58 @@ public TopicDetails clickProduceMessageBtn() {
     return this;
   }
 
+  @Step
+  public TopicDetails clickMessagesAddFiltersBtn() {
+    addFiltersBtn.shouldBe(Condition.enabled).click();
+    return this;
+  }
+
+  @Step
+  public TopicDetails waitUntilAddFiltersMdlVisible() {
+    addFilterCodeModalTitle.shouldBe(Condition.visible);
+    return this;
+  }
+
+  @Step
+  public TopicDetails clickAddFilterBtnAddFilterMdl() {
+    addFilterBtnAddFilterMdl.shouldBe(Condition.enabled).click();
+    addFilterCodeModalTitle.shouldBe(Condition.hidden);
+    return this;
+  }
+
+  @Step
+  public TopicDetails setFilterCodeFieldAddFilterMdl(String filterCode) {
+    addFilterCodeInput.shouldBe(Condition.enabled).sendKeys(filterCode);
+    return this;
+  }
+
+  @Step
+  public boolean isSaveThisFilterCheckBoxSelected() {
+    return isSelected(saveThisFilterCheckBoxAddFilterMdl);
+  }
+
+  @Step
+  public boolean isAddFilterBtnAddFilterMdlEnabled() {
+    return isEnabled(addFilterBtnAddFilterMdl);
+  }
+
+  @Step
+  public String getFilterName() {
+    return $x(filterNameLocator).getText();
+  }
+
+  public List<SelenideElement> getAllAddFilterModalVisibleElements() {
+    return Arrays.asList(savedFiltersField, displayNameInputAddFilterMdl, addFilterBtnAddFilterMdl, cancelBtnAddFilterMdl);
+  }
+
+  public List<SelenideElement> getAllAddFilterModalEnabledElements() {
+    return Arrays.asList(displayNameInputAddFilterMdl, cancelBtnAddFilterMdl);
+  }
+
+  public List<SelenideElement> getAllAddFilterModalDisabledElements() {
+    return Arrays.asList(addFilterBtnAddFilterMdl);
+  }
+
   @Step
   public TopicDetails openConsumerGroup(String consumerId) {
     $x(String.format(consumerIdLocator, consumerId)).click();
@@ -146,6 +208,23 @@ public TopicDetails.MessageGridItem getRandomMessage() {
     return getMessage(nextInt(initItems().size() - 1));
   }
 
+  public enum TopicMenu {
+    OVERVIEW("Overview"),
+    MESSAGES("Messages"),
+    CONSUMERS("Consumers"),
+    SETTINGS("Settings");
+
+    private final String value;
+
+    TopicMenu(String value) {
+      this.value = value;
+    }
+
+    public String toString() {
+      return value;
+    }
+  }
+
   public static class MessageGridItem extends BasePage {
 
     private final SelenideElement element;
@@ -211,21 +290,4 @@ public MessageGridItem clickSaveAsFile() {
       return this;
     }
   }
-
-  public enum TopicMenu {
-    OVERVIEW("Overview"),
-    MESSAGES("Messages"),
-    CONSUMERS("Consumers"),
-    SETTINGS("Settings");
-
-    private final String value;
-
-    TopicMenu(String value) {
-      this.value = value;
-    }
-
-    public String toString() {
-      return value;
-    }
-  }
 }
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 4ce2721d6fd..dcda2ce4dff 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
@@ -17,7 +17,7 @@
 @ExtensionMethod(WaitUtils.class)
 public class TopicsList extends BasePage {
 
-    protected SelenideElement topicListHeader = $x("//h1[text()='Topics']");
+    protected SelenideElement topicListHeader = $x("//*[text()='Topics']");
     protected SelenideElement addTopicBtn = $x("//button[normalize-space(text()) ='Add a Topic']");
     protected SelenideElement searchField = $x("//input[@placeholder='Search by Topic Name']");
     protected SelenideElement showInternalRadioBtn = $x("//input[@name='ShowInternalTopics']");
diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/utilities/WebUtils.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/utilities/WebUtils.java
index 35a0a06f7a5..3ba6d053ecd 100644
--- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/utilities/WebUtils.java
+++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/utilities/WebUtils.java
@@ -57,4 +57,16 @@ public static boolean isEnabled(SelenideElement element) {
     }
     return isEnabled;
   }
+
+  public static boolean isSelected(SelenideElement element) {
+    log.debug("\nisSelected: {}", element.getSearchCriteria());
+    boolean isSelected = false;
+    try {
+      element.shouldBe(Condition.selected);
+      isSelected = true;
+    } catch (Throwable e) {
+      log.debug("{} is not selected", element.getSearchCriteria());
+    }
+    return isSelected;
+  }
 }


Test patch:
diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/suite/topics/TopicActionsTests.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/suite/topics/TopicsTests.java
similarity index 80%
rename from kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/suite/topics/TopicActionsTests.java
rename to kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/suite/topics/TopicsTests.java
index 3bc6dc07b4a..c342a216074 100644
--- a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/suite/topics/TopicActionsTests.java
+++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/suite/topics/TopicsTests.java
@@ -31,11 +31,11 @@
 import org.junit.jupiter.api.TestInstance;
 
 @TestInstance(TestInstance.Lifecycle.PER_CLASS)
-public class TopicActionsTests extends BaseTest {
+public class TopicsTests extends BaseTest {
   private static final long SUITE_ID = 2;
   private static final String SUITE_TITLE = "Topics";
   private static final Topic TOPIC_TO_CREATE = new Topic()
-      .setName("new-topic-"+ randomAlphabetic(5))
+      .setName("new-topic-" + randomAlphabetic(5))
       .setPartitions("1")
       .setCustomParameterType(COMPRESSION_TYPE)
       .setCustomParameterValue("producer")
@@ -83,8 +83,10 @@ public void createTopic() {
         .waitUntilScreenReady()
         .openTopic(TOPIC_TO_CREATE.getName());
     SoftAssertions softly = new SoftAssertions();
-    softly.assertThat(topicDetails.isTopicHeaderVisible(TOPIC_TO_CREATE.getName())).as("isTopicHeaderVisible()").isTrue();
-    softly.assertThat(topicDetails.getCleanUpPolicy()).as("getCleanUpPolicy()").isEqualTo(TOPIC_TO_CREATE.getCleanupPolicyValue().toString());
+    softly.assertThat(topicDetails.isTopicHeaderVisible(TOPIC_TO_CREATE.getName())).as("isTopicHeaderVisible()")
+        .isTrue();
+    softly.assertThat(topicDetails.getCleanUpPolicy()).as("getCleanUpPolicy()")
+        .isEqualTo(TOPIC_TO_CREATE.getCleanupPolicyValue().toString());
     softly.assertThat(topicDetails.getPartitions()).as("getPartitions()").isEqualTo(TOPIC_TO_CREATE.getPartitions());
     softly.assertAll();
     naviSideBar
@@ -132,10 +134,14 @@ public void updateTopic() {
         .openDotMenu()
         .clickEditSettingsMenu();
     SoftAssertions softly = new SoftAssertions();
-    softly.assertThat(topicCreateEditForm.getCleanupPolicy()).as("getCleanupPolicy()").isEqualTo(TOPIC_FOR_UPDATE.getCleanupPolicyValue().getVisibleText());
-    softly.assertThat(topicCreateEditForm.getTimeToRetain()).as("getTimeToRetain()").isEqualTo(TOPIC_FOR_UPDATE.getTimeToRetainData());
-    softly.assertThat(topicCreateEditForm.getMaxSizeOnDisk()).as("getMaxSizeOnDisk()").isEqualTo(TOPIC_FOR_UPDATE.getMaxSizeOnDisk().getVisibleText());
-    softly.assertThat(topicCreateEditForm.getMaxMessageBytes()).as("getMaxMessageBytes()").isEqualTo(TOPIC_FOR_UPDATE.getMaxMessageBytes());
+    softly.assertThat(topicCreateEditForm.getCleanupPolicy()).as("getCleanupPolicy()")
+        .isEqualTo(TOPIC_FOR_UPDATE.getCleanupPolicyValue().getVisibleText());
+    softly.assertThat(topicCreateEditForm.getTimeToRetain()).as("getTimeToRetain()")
+        .isEqualTo(TOPIC_FOR_UPDATE.getTimeToRetainData());
+    softly.assertThat(topicCreateEditForm.getMaxSizeOnDisk()).as("getMaxSizeOnDisk()")
+        .isEqualTo(TOPIC_FOR_UPDATE.getMaxSizeOnDisk().getVisibleText());
+    softly.assertThat(topicCreateEditForm.getMaxMessageBytes()).as("getMaxMessageBytes()")
+        .isEqualTo(TOPIC_FOR_UPDATE.getMaxMessageBytes());
     softly.assertAll();
   }
 
@@ -237,7 +243,7 @@ void checkCustomParametersWithinCreateNewTopic() {
   @AutomationStatus(status = Status.AUTOMATED)
   @CaseId(2)
   @Test
-  void checkTopicListElements(){
+  void checkTopicListElements() {
     naviSideBar
         .openSideMenu(TOPICS);
     topicsList
@@ -252,6 +258,45 @@ void checkTopicListElements(){
     softly.assertAll();
   }
 
+  @DisplayName("Filter adding within Topic")
+  @Suite(suiteId = SUITE_ID, title = SUITE_TITLE)
+  @AutomationStatus(status = Status.AUTOMATED)
+  @CaseId(12)
+  @Test
+  void addingNewFilterWithinTopic() {
+    String topicName = "_schemas";
+    String filterName = "123ABC";
+    naviSideBar
+        .openSideMenu(TOPICS);
+    topicsList
+        .waitUntilScreenReady()
+        .openTopic(topicName);
+    topicDetails
+        .openDetailsTab(TopicDetails.TopicMenu.MESSAGES)
+        .clickMessagesAddFiltersBtn()
+        .waitUntilAddFiltersMdlVisible();
+    SoftAssertions softly = new SoftAssertions();
+    topicDetails.getAllAddFilterModalVisibleElements().forEach(element ->
+        softly.assertThat(element.is(Condition.visible))
+            .as(element.getSearchCriteria() + " isVisible()").isTrue());
+    topicDetails.getAllAddFilterModalEnabledElements().forEach(element ->
+        softly.assertThat(element.is(Condition.enabled))
+            .as(element.getSearchCriteria() + " isEnabled()").isTrue());
+    topicDetails.getAllAddFilterModalDisabledElements().forEach(element ->
+        softly.assertThat(element.is(Condition.enabled))
+            .as(element.getSearchCriteria() + " isEnabled()").isFalse());
+    softly.assertThat(topicDetails.isSaveThisFilterCheckBoxSelected()).as("isSaveThisFilterCheckBoxSelected()")
+        .isFalse();
+    softly.assertAll();
+    topicDetails
+        .setFilterCodeFieldAddFilterMdl(filterName);
+    assertThat(topicDetails.isAddFilterBtnAddFilterMdlEnabled()).as("isMessagesAddFilterTabAddFilterBtnEnabled()")
+        .isTrue();
+    topicDetails.clickAddFilterBtnAddFilterMdl();
+    assertThat(topicDetails.getFilterName()).as("isFilterNameVisible(filterName)")
+        .isEqualTo(filterName);
+  }
+
   @AfterAll
   public void afterAll() {
     TOPIC_LIST.forEach(topic -> apiHelper.deleteTopic(CLUSTER_NAME, topic.getName()));