Browse Source

Checks/424 creating topic UI check (#508)

* kafka-create-topic-test

* waituntil

* steps

* topic tests

* fixed ui topic test(refresh page until element is present

* fixed refreshUntil method

* kafka-create-topic-test

* waituntil

* steps

* topic tests

* fixed ui topic test(refresh page until element is present

* fixed refreshUntil method

* changed test name for topic creation

* try comment afterAll to fix

* moved steps folder form main to test

Co-authored-by: marat <ttx013@gmail.com>
Co-authored-by: Bogdan Volodarskiy <bvolodarskiy@provectus.com>
Bogdan Volodarskiy 4 years ago
parent
commit
760149eb85

+ 1 - 1
kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/SmokeTests.java

@@ -13,7 +13,7 @@ public class SmokeTests extends BaseTest {
     @DisplayName("main page should load")
     @Issue("380")
     void mainPageLoads() {
-        pages.goTo("")
+        pages.open()
             .mainPage.shouldBeOnPage();
         compareScreenshots("main");
     }

+ 5 - 4
kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/base/BaseTest.java

@@ -4,6 +4,7 @@ import com.codeborne.selenide.Configuration;
 import com.codeborne.selenide.logevents.SelenideLogger;
 import com.provectus.kafka.ui.pages.Pages;
 import com.provectus.kafka.ui.screenshots.Screenshooter;
+import com.provectus.kafka.ui.steps.Steps;
 import io.github.cdimascio.dotenv.Dotenv;
 import io.qameta.allure.selenide.AllureSelenide;
 import lombok.SneakyThrows;
@@ -18,12 +19,11 @@ import org.testcontainers.utility.DockerImageName;
 import java.io.File;
 import java.util.Arrays;
 
-import static com.codeborne.selenide.Selenide.closeWebDriver;
-
 @Slf4j
 @DisplayNameGeneration(CamelCaseToSpacedDisplayNameGenerator.class)
 public class BaseTest {
 
+  protected Steps steps = Steps.INSTANCE;
   protected Pages pages = Pages.INSTANCE;
 
   private Screenshooter screenshooter = new Screenshooter();
@@ -59,8 +59,8 @@ public class BaseTest {
 
   @AfterAll
   public static void afterAll() {
-    closeWebDriver();
-    selenoid.close();
+//    closeWebDriver();
+//    selenoid.close();
   }
 
   @SneakyThrows
@@ -86,6 +86,7 @@ public class BaseTest {
     Configuration.baseUrl = TestConfiguration.BASE_URL;
     Configuration.browserSize = TestConfiguration.BROWSER_SIZE;
     var capabilities = new DesiredCapabilities();
+//    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
     capabilities.setCapability("enableVNC", TestConfiguration.ENABLE_VNC);
     Configuration.browserCapabilities = capabilities;
 

+ 48 - 5
kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/pages/MainPage.java

@@ -2,15 +2,58 @@ package com.provectus.kafka.ui.pages;
 
 import com.codeborne.selenide.Condition;
 import io.qameta.allure.Step;
+import lombok.SneakyThrows;
 import org.openqa.selenium.By;
 
-import static com.codeborne.selenide.Selenide.$;
+import static com.codeborne.selenide.Selenide.*;
 
 public class MainPage {
 
-    @Step
-    public void shouldBeOnPage(){
-        $(By.xpath("//*[contains(text(),'Loading')]")).shouldBe(Condition.disappear);
-        $(By.xpath("//h5[text()='Clusters']")).shouldBe(Condition.visible);
+  private static final long TIMEOUT = 25000;
+
+  @Step
+  public MainPage shouldBeOnPage() {
+    $(By.xpath("//*[contains(text(),'Loading')]")).shouldBe(Condition.disappear);
+    $(By.xpath("//h5[text()='Clusters']")).shouldBe(Condition.visible);
+    return this;
+  }
+
+
+  private void refreshUntil(By by){
+    int i =0;
+    do
+    {
+      refresh();
+      i++;
+      sleep(2000);
+    } while(getElements(by).size()<1 && i!=20);
+    $(by).shouldBe(Condition.visible);
+  }
+
+  @SneakyThrows
+  public void shouldBeTopic(String topicName) {
+    refreshUntil(By.xpath("//div[contains(@class,'section')]//table//a[text()='%s']".formatted(topicName)));
+  }
+
+
+
+  public enum SideMenuOptions {
+    BROKERS("Brokers"),
+    TOPICS("Topics"),
+    CONSUMERS("Consumers"),
+    SCHEMA_REGISTRY("Schema registry");
+
+    String value;
+
+    SideMenuOptions(String value) {
+      this.value = value;
     }
+  }
+
+  @Step
+  public MainPage goToSideMenu(String clusterName, SideMenuOptions option) {
+    $(By.xpath("//aside//*[a[text()='%s']]//a[text()='%s']".formatted(clusterName, option.value)))
+        .click();
+    return this;
+  }
 }

+ 4 - 1
kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/pages/Pages.java

@@ -9,8 +9,11 @@ public class Pages {
 
     public MainPage mainPage = new MainPage();
 
-    public Pages goTo(String path) {
+    private Pages goTo(String path) {
         Selenide.open(TestConfiguration.BASE_URL+path);
         return this;
     }
+    public Pages open() {
+       return goTo("");
+    }
 }

+ 12 - 0
kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/steps/Steps.java

@@ -0,0 +1,12 @@
+package com.provectus.kafka.ui.steps;
+
+import com.provectus.kafka.ui.steps.kafka.KafkaSteps;
+
+public class Steps {
+
+    public static final Steps INSTANCE = new Steps();
+
+    private Steps(){}
+
+    public KafkaSteps kafka = new KafkaSteps();
+}

+ 62 - 0
kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/steps/kafka/KafkaSteps.java

@@ -0,0 +1,62 @@
+package com.provectus.kafka.ui.steps.kafka;
+
+import lombok.SneakyThrows;
+import org.apache.kafka.clients.admin.*;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class KafkaSteps {
+
+  int partitions = 2;
+  short replicationFactor = 1;
+  public enum Cluster{
+    SECOND_LOCAL("secondLocal","localhost:9093"),LOCAL("local","localhost:9092");
+    private String name;
+    private String server;
+    private  Map<String, Object> config = new HashMap<>();
+    Cluster(String name,String server) {
+      this.name = name;
+      this.server = server;
+      this.config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, server);
+      this.config.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "5000");
+    }
+
+    public String getName() {
+      return name;
+    }
+  }
+
+
+  @SneakyThrows
+  public void createTopic(Cluster cluster,String topicName) {
+    try (AdminClient client = AdminClient.create(cluster.config)) {
+      client
+          .createTopics(
+              Collections.singleton(new NewTopic(topicName, partitions, replicationFactor)),
+              new CreateTopicsOptions().timeoutMs(1000))
+          .all()
+          .get();
+
+      assertTrue(client
+              .listTopics()
+              .names().get().contains(topicName));
+
+    }
+  }
+
+  @SneakyThrows
+  public void deleteTopic(Cluster cluster,String topicName) {
+    try (AdminClient client = AdminClient.create(cluster.config)) {
+      assertTrue(client.listTopics().names().get().contains(topicName));
+      client
+          .deleteTopics(
+              Collections.singleton(topicName), new DeleteTopicsOptions().timeoutMs(1000))
+          .all()
+          .get();
+    }
+  }
+}

+ 32 - 0
kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/topics/TopicTests.java

@@ -0,0 +1,32 @@
+package com.provectus.kafka.ui.topics;
+
+import com.provectus.kafka.ui.base.BaseTest;
+import com.provectus.kafka.ui.pages.MainPage;
+import com.provectus.kafka.ui.steps.kafka.KafkaSteps;
+import lombok.SneakyThrows;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class TopicTests extends BaseTest {
+
+
+    public static final String NEW_TOPIC = "new-topic";
+
+    @AfterEach
+    @SneakyThrows
+    void  afterEach(){
+        steps.kafka.deleteTopic(KafkaSteps.Cluster.SECOND_LOCAL,NEW_TOPIC);
+    }
+
+    @SneakyThrows
+    @DisplayName("should create a topic")
+    @Test
+    void createTopic(){
+        steps.kafka.createTopic(KafkaSteps.Cluster.SECOND_LOCAL,NEW_TOPIC);
+        pages.open()
+                .mainPage.shouldBeOnPage()
+        .goToSideMenu(KafkaSteps.Cluster.SECOND_LOCAL.getName(), MainPage.SideMenuOptions.TOPICS)
+        .shouldBeTopic(NEW_TOPIC);
+    }
+}