From c0d64d7c566abfdd3ceeaa9c09cd895f0fae3f60 Mon Sep 17 00:00:00 2001 From: Alexandr Nezboretskiy <88882353+anezboretskiy@users.noreply.github.com> Date: Mon, 22 Aug 2022 18:38:57 +0300 Subject: [PATCH] get rid of SheakyThrows annotation (#2470) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix unstable e2e test #2373 * Fix unstable e2e test #2373 * Prepare steps for Schema Registry and Connector fixed #2288 * Fix unstable e2e test #2373 * Revert "Prepare steps for Schema Registry and Connector fixed #2288" This reverts commit cfeb224e99f859d7278444555b1fee3028dcf7ee. * fix FileUtils * Update FileUtils #2431 * Resolved MConflicts #2431Сopy * Resolved MConflicts part2 #2431Сopy * Updated ApiHelper and added annotations #2431Сopy * Revert Objects.requireNonNull #2431Сopy * Last update #2431Сopy * Delete KaffkaSteps * Update ApiHelper Co-authored-by: anezboretskiy --- .../kafka/ui/extensions/FileUtils.java | 16 +- .../provectus/kafka/ui/pages/MainPage.java | 22 +- .../pages/connector/ConnectorCreateView.java | 6 +- .../ui/pages/connector/ConnectorsList.java | 11 +- .../ui/pages/schema/SchemaRegistryList.java | 4 +- .../kafka/ui/pages/topic/TopicView.java | 6 +- .../kafka/ui/pages/topic/TopicsList.java | 7 +- .../kafka/ui/screenshots/Screenshooter.java | 237 +++++++++--------- .../com/provectus/kafka/ui/SmokeTests.java | 2 - .../kafka/ui/tests/ConnectorsTests.java | 21 +- .../kafka/ui/tests/SchemasTests.java | 35 +-- .../provectus/kafka/ui/tests/TopicTests.java | 17 +- 12 files changed, 184 insertions(+), 200 deletions(-) diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/extensions/FileUtils.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/extensions/FileUtils.java index 2292622640..bbe4dbf0b4 100644 --- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/extensions/FileUtils.java +++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/extensions/FileUtils.java @@ -5,11 +5,23 @@ import org.testcontainers.shaded.org.apache.commons.io.IOUtils; import java.io.IOException; import java.nio.charset.StandardCharsets; +import static org.apache.kafka.common.utils.Utils.readFileAsString; public class FileUtils { - public static String getResourceAsString(String resourceFileName) throws IOException { - return IOUtils.resourceToString("/" + resourceFileName, StandardCharsets.UTF_8); + public static String getResourceAsString(String resourceFileName) { + try { + return IOUtils.resourceToString("/" + resourceFileName, StandardCharsets.UTF_8); + } catch (IOException e) { + throw new RuntimeException(e); + } } + public static String fileToString(String path) { + try { + return readFileAsString(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/MainPage.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/MainPage.java index 515ab60ffe..cfc15f105e 100644 --- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/MainPage.java +++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/MainPage.java @@ -3,11 +3,10 @@ package com.provectus.kafka.ui.pages; import com.codeborne.selenide.Condition; import com.codeborne.selenide.Selenide; import com.codeborne.selenide.SelenideElement; -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.pages.topic.TopicsList; import io.qameta.allure.Step; -import lombok.SneakyThrows; import lombok.experimental.ExtensionMethod; import org.openqa.selenium.By; @@ -32,7 +31,6 @@ public class MainPage { return this; } - @SneakyThrows @Step public void topicIsVisible(String topicName) { new TopicsList().isTopicVisible(topicName); @@ -43,18 +41,18 @@ public class MainPage { } - public enum SideMenuOptions { - BROKERS("Brokers"), - TOPICS("Topics"), - CONSUMERS("Consumers"), - SCHEMA_REGISTRY("Schema Registry"); + public enum SideMenuOptions { + BROKERS("Brokers"), + TOPICS("Topics"), + CONSUMERS("Consumers"), + SCHEMA_REGISTRY("Schema Registry"); - final String value; + final String value; - SideMenuOptions(String value) { - this.value = value; + SideMenuOptions(String value) { + this.value = value; + } } - } diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/connector/ConnectorCreateView.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/connector/ConnectorCreateView.java index 69f67a9a4a..a12aca5917 100644 --- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/connector/ConnectorCreateView.java +++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/connector/ConnectorCreateView.java @@ -2,15 +2,15 @@ package com.provectus.kafka.ui.pages.connector; import com.codeborne.selenide.Condition; import com.codeborne.selenide.SelenideElement; -import com.provectus.kafka.ui.utils.BrowserUtils; import com.provectus.kafka.ui.extensions.WaitUtils; +import com.provectus.kafka.ui.utils.BrowserUtils; import io.qameta.allure.Step; import lombok.experimental.ExtensionMethod; import org.openqa.selenium.By; import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.sleep; import static com.provectus.kafka.ui.screenshots.Screenshooter.log; -import static java.lang.Thread.sleep; @ExtensionMethod(WaitUtils.class) public class ConnectorCreateView { @@ -22,7 +22,7 @@ public class ConnectorCreateView { private static final String path = "/ui/clusters/secondLocal/connectors/create_new"; @Step("Set connector config JSON") - public ConnectorsView setConnectorConfig(String connectName, String configJson) throws InterruptedException { + public ConnectorsView setConnectorConfig(String connectName, String configJson) { nameField.setValue(connectName); $("#config").click(); contentTextArea.setValue(""); diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/connector/ConnectorsList.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/connector/ConnectorsList.java index 659a87da2c..f79f232776 100644 --- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/connector/ConnectorsList.java +++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/connector/ConnectorsList.java @@ -2,11 +2,10 @@ package com.provectus.kafka.ui.pages.connector; import com.codeborne.selenide.Condition; import com.codeborne.selenide.Selenide; +import com.provectus.kafka.ui.extensions.WaitUtils; import com.provectus.kafka.ui.helpers.TestConfiguration; import com.provectus.kafka.ui.utils.BrowserUtils; -import com.provectus.kafka.ui.extensions.WaitUtils; import io.qameta.allure.Step; -import lombok.SneakyThrows; import lombok.experimental.ExtensionMethod; import org.openqa.selenium.By; @@ -35,14 +34,14 @@ public class ConnectorsList { return new ConnectorCreateView(); } - @SneakyThrows + @Step public ConnectorsList openConnector(String connectorName) { $(By.linkText(connectorName)).click(); return this; } - @SneakyThrows + @Step public ConnectorsList isNotVisible(String connectorName) { $(By.xpath("//table")).shouldBe(Condition.visible); @@ -52,8 +51,8 @@ public class ConnectorsList { @Step("Verify that connector {connectorName} is visible in the list") public ConnectorsList connectorIsVisibleInList(String connectorName, String topicName) { - $x("//table//a[@href='/ui/clusters/local/connects/first/connectors/" + connectorName +"']").shouldBe(Condition.visible); - $$(By.linkText(topicName)); + $x("//table//a[@href='/ui/clusters/local/connects/first/connectors/" + connectorName + "']").shouldBe(Condition.visible); + $$(By.linkText(topicName)); return this; } @Step diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/schema/SchemaRegistryList.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/schema/SchemaRegistryList.java index 34ee71c7ff..a9cc45d92c 100644 --- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/schema/SchemaRegistryList.java +++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/schema/SchemaRegistryList.java @@ -4,7 +4,6 @@ import com.codeborne.selenide.Condition; import com.codeborne.selenide.SelenideElement; import com.provectus.kafka.ui.utils.BrowserUtils; import io.qameta.allure.Step; -import lombok.SneakyThrows; import org.openqa.selenium.By; import static com.codeborne.selenide.Selenide.*; @@ -23,10 +22,9 @@ public class SchemaRegistryList { return new SchemaView(); } - @SneakyThrows @Step public SchemaRegistryList isNotVisible(String schemaName) { - $x(String.format("//*[contains(text(),'%s')]",schemaName)).shouldNotBe(Condition.visible); + $x(String.format("//*[contains(text(),'%s')]", schemaName)).shouldNotBe(Condition.visible); 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 c3607fceab..7eccf23fe2 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 @@ -3,12 +3,11 @@ package com.provectus.kafka.ui.pages.topic; import com.codeborne.selenide.Condition; import com.codeborne.selenide.Selenide; import com.codeborne.selenide.SelenideElement; -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.pages.ProduceMessagePage; import com.provectus.kafka.ui.utils.BrowserUtils; import io.qameta.allure.Step; -import lombok.SneakyThrows; import lombok.experimental.ExtensionMethod; import org.openqa.selenium.By; @@ -34,7 +33,6 @@ public class TopicView { return this; } - @SneakyThrows @Step public TopicCreateEditSettingsView openEditSettings() { BrowserUtils.javaExecutorClick(dotMenuHeader); @@ -48,7 +46,6 @@ public class TopicView { return this; } - @SneakyThrows @Step public TopicsList deleteTopic() { BrowserUtils.javaExecutorClick(dotMenuHeader); @@ -57,7 +54,6 @@ public class TopicView { return new TopicsList(); } - @SneakyThrows @Step public ProduceMessagePage clickOnButton(String buttonName) { BrowserUtils.javaExecutorClick($(By.xpath(String.format("//div//button[text()='%s']", buttonName)))); 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 c39a3ca1b9..bbcb67effb 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,11 +3,10 @@ package com.provectus.kafka.ui.pages.topic; 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; import lombok.experimental.ExtensionMethod; import org.openqa.selenium.By; @@ -32,7 +31,7 @@ public class TopicsList { } @Step - public TopicCreateEditSettingsView pressCreateNewTopic(){ + public TopicCreateEditSettingsView pressCreateNewTopic() { BrowserUtils.javaExecutorClick($x("//button[normalize-space(text()) ='Add a Topic']")); return new TopicCreateEditSettingsView(); } @@ -46,14 +45,12 @@ public class TopicsList { return this; } - @SneakyThrows @Step public TopicView openTopic(String topicName) { $(By.linkText(topicName)).click(); return new TopicView(); } - @SneakyThrows @Step public TopicsList isTopicNotVisible(String topicName) { $$x("//table/tbody/tr/td[2]") diff --git a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/screenshots/Screenshooter.java b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/screenshots/Screenshooter.java index 66b016ba85..d412050b29 100644 --- a/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/screenshots/Screenshooter.java +++ b/kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/screenshots/Screenshooter.java @@ -16,6 +16,7 @@ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; import java.nio.file.FileSystems; import java.util.List; @@ -23,131 +24,139 @@ import static com.codeborne.selenide.WebDriverRunner.getWebDriver; public class Screenshooter { - public static Logger log = LoggerFactory.getLogger(Screenshooter.class); + public static Logger log = LoggerFactory.getLogger(Screenshooter.class); - private static final int PIXELS_THRESHOLD = - Integer.parseInt(System.getProperty("PIXELS_THRESHOLD", "200")); - private static final String SCREENSHOTS_FOLDER = - System.getProperty("SCREENSHOTS_FOLDER", "com/provectus/kafka/ui/screenshots/"); - private static final String DIFF_SCREENSHOTS_FOLDER = - System.getProperty("DIFF_SCREENSHOTS_FOLDER", "build/__diff__/"); - private static final String ACTUAL_SCREENSHOTS_FOLDER = - System.getProperty("ACTUAL_SCREENSHOTS_FOLDER", "build/__actual__/"); - private static final boolean SHOULD_SAVE_SCREENSHOTS_IF_NOT_EXIST = - Boolean.parseBoolean(System.getProperty("SHOULD_SAVE_SCREENSHOTS_IF_NOT_EXIST", "true")); - private static final boolean TURN_OFF_SCREENSHOTS = - Boolean.parseBoolean(System.getProperty("TURN_OFF_SCREENSHOTS", "false")); - private static final boolean USE_LOCAL_BROWSER = - Boolean.parseBoolean(System.getProperty("USE_LOCAL_BROWSER", "false")); + private static final int PIXELS_THRESHOLD = + Integer.parseInt(System.getProperty("PIXELS_THRESHOLD", "200")); + private static final String SCREENSHOTS_FOLDER = + System.getProperty("SCREENSHOTS_FOLDER", "com/provectus/kafka/ui/screenshots/"); + private static final String DIFF_SCREENSHOTS_FOLDER = + System.getProperty("DIFF_SCREENSHOTS_FOLDER", "build/__diff__/"); + private static final String ACTUAL_SCREENSHOTS_FOLDER = + System.getProperty("ACTUAL_SCREENSHOTS_FOLDER", "build/__actual__/"); + private static final boolean SHOULD_SAVE_SCREENSHOTS_IF_NOT_EXIST = + Boolean.parseBoolean(System.getProperty("SHOULD_SAVE_SCREENSHOTS_IF_NOT_EXIST", "true")); + private static final boolean TURN_OFF_SCREENSHOTS = + Boolean.parseBoolean(System.getProperty("TURN_OFF_SCREENSHOTS", "false")); + private static final boolean USE_LOCAL_BROWSER = + Boolean.parseBoolean(System.getProperty("USE_LOCAL_BROWSER", "false")); - private File newFile(String name) { - var file = new File(name); - if (!file.exists()) { - file.mkdirs(); + private File newFile(String name) { + var file = new File(name); + if (!file.exists()) { + file.mkdirs(); + } + return file; } - return file; - } - public Screenshooter() { - List.of(SCREENSHOTS_FOLDER, DIFF_SCREENSHOTS_FOLDER, ACTUAL_SCREENSHOTS_FOLDER) - .forEach(this::newFile); - } - - public void compareScreenshots(String name) { - compareScreenshots(name, false); - } - - @SneakyThrows - public void compareScreenshots(String name, boolean shouldUpdateScreenshotIfDiffer) { - if (TURN_OFF_SCREENSHOTS || USE_LOCAL_BROWSER) { - log.warn(String.format("compareScreenshots turned off due TURN_OFF_SCREENSHOTS || USE_LOCAL_BROWSER: %b || %b" - , TURN_OFF_SCREENSHOTS,USE_LOCAL_BROWSER)); - return; + public Screenshooter() { + List.of(SCREENSHOTS_FOLDER, DIFF_SCREENSHOTS_FOLDER, ACTUAL_SCREENSHOTS_FOLDER) + .forEach(this::newFile); } - if (!doesScreenshotExist(name)) { - if (SHOULD_SAVE_SCREENSHOTS_IF_NOT_EXIST) { - updateActualScreenshot(name); - } else { - throw new NoReferenceScreenshotFoundException(name); - } - } else { - makeImageDiff(name, shouldUpdateScreenshotIfDiffer); + + public void compareScreenshots(String name) { + compareScreenshots(name, false); } - } - @SneakyThrows - private void updateActualScreenshot(String name) { - Screenshot actual = - new AShot().coordsProvider(new WebDriverCoordsProvider()).takeScreenshot(getWebDriver()); - File file= newFile(SCREENSHOTS_FOLDER + name + ".png"); - ImageIO.write(actual.getImage(), "png", file); - log.debug(String.format("created screenshot: %s \n at %s", name, file.getAbsolutePath())); - } - private static boolean doesScreenshotExist(String name) { - return new File(SCREENSHOTS_FOLDER + name + ".png").exists(); - } - - @SneakyThrows - private void makeImageDiff(String expectedName, boolean shouldUpdateScreenshotIfDiffer) { - String fullPathNameExpected = SCREENSHOTS_FOLDER + expectedName + ".png"; - String fullPathNameActual = ACTUAL_SCREENSHOTS_FOLDER + expectedName + ".png"; - String fullPathNameDiff = DIFF_SCREENSHOTS_FOLDER + expectedName + ".png"; - - // activating allure plugin for showing diffs in report - Allure.label("testType", "screenshotDiff"); - - Screenshot actual = - new AShot().coordsProvider(new WebDriverCoordsProvider()).takeScreenshot(getWebDriver()); - ImageIO.write(actual.getImage(), "png", newFile(fullPathNameActual)); - - Screenshot expected = new Screenshot(ImageIO.read(newFile(fullPathNameExpected))); - ImageDiff diff = new ImageDiffer().makeDiff(actual, expected); - BufferedImage diffImage = diff.getMarkedImage(); - ImageIO.write(diffImage, "png", newFile(fullPathNameDiff)); - // adding to report - diff(fullPathNameDiff); - // adding to report - actual(fullPathNameActual); - // adding to report - expected(fullPathNameExpected); - - if (shouldUpdateScreenshotIfDiffer) { - if (diff.getDiffSize() > PIXELS_THRESHOLD) { - updateActualScreenshot(expectedName); - } - } else { - Assertions.assertTrue( - PIXELS_THRESHOLD >= diff.getDiffSize(), - String.format("Amount of differing pixels should be less or equals than %s, actual %s\n"+ - "diff file: %s", - PIXELS_THRESHOLD, diff.getDiffSize(), FileSystems.getDefault().getPath(fullPathNameDiff).normalize().toAbsolutePath())); + public void compareScreenshots(String name, boolean shouldUpdateScreenshotIfDiffer) { + if (TURN_OFF_SCREENSHOTS || USE_LOCAL_BROWSER) { + log.warn(String.format("compareScreenshots turned off due TURN_OFF_SCREENSHOTS || USE_LOCAL_BROWSER: %b || %b" + , TURN_OFF_SCREENSHOTS, USE_LOCAL_BROWSER)); + return; + } + if (!doesScreenshotExist(name)) { + if (SHOULD_SAVE_SCREENSHOTS_IF_NOT_EXIST) { + updateActualScreenshot(name); + } else { + try { + throw new NoReferenceScreenshotFoundException(name); + } catch (NoReferenceScreenshotFoundException e) { + e.printStackTrace(); + } + } + } else { + makeImageDiff(name, shouldUpdateScreenshotIfDiffer); + } } - } - @SneakyThrows - private byte[] imgToBytes(String filename) { - BufferedImage bImage2 = ImageIO.read(new File(filename)); - var bos2 = new ByteArrayOutputStream(); - ImageIO.write(bImage2, "png", bos2); - return bos2.toByteArray(); - } - @SneakyThrows - @Attachment - private byte[] actual(String actualFileName) { - return imgToBytes(actualFileName); - } + private void updateActualScreenshot(String name) { + Screenshot actual = + new AShot().coordsProvider(new WebDriverCoordsProvider()).takeScreenshot(getWebDriver()); + File file = newFile(SCREENSHOTS_FOLDER + name + ".png"); + try { + ImageIO.write(actual.getImage(), "png", file); + } catch (IOException e) { + e.printStackTrace(); + } + log.debug(String.format("created screenshot: %s \n at %s", name, file.getAbsolutePath())); + } - @SneakyThrows - @Attachment - private byte[] expected(String expectedFileName) { - return imgToBytes(expectedFileName); - } + private static boolean doesScreenshotExist(String name) { + return new File(SCREENSHOTS_FOLDER + name + ".png").exists(); + } - @SneakyThrows - @Attachment - private byte[] diff(String diffFileName) { - return imgToBytes(diffFileName); - } + @SneakyThrows + private void makeImageDiff(String expectedName, boolean shouldUpdateScreenshotIfDiffer) { + String fullPathNameExpected = SCREENSHOTS_FOLDER + expectedName + ".png"; + String fullPathNameActual = ACTUAL_SCREENSHOTS_FOLDER + expectedName + ".png"; + String fullPathNameDiff = DIFF_SCREENSHOTS_FOLDER + expectedName + ".png"; + + // activating allure plugin for showing diffs in report + Allure.label("testType", "screenshotDiff"); + + Screenshot actual = + new AShot().coordsProvider(new WebDriverCoordsProvider()).takeScreenshot(getWebDriver()); + ImageIO.write(actual.getImage(), "png", newFile(fullPathNameActual)); + + Screenshot expected = new Screenshot(ImageIO.read(newFile(fullPathNameExpected))); + ImageDiff diff = new ImageDiffer().makeDiff(actual, expected); + BufferedImage diffImage = diff.getMarkedImage(); + ImageIO.write(diffImage, "png", newFile(fullPathNameDiff)); + // adding to report + diff(fullPathNameDiff); + // adding to report + actual(fullPathNameActual); + // adding to report + expected(fullPathNameExpected); + + if (shouldUpdateScreenshotIfDiffer) { + if (diff.getDiffSize() > PIXELS_THRESHOLD) { + updateActualScreenshot(expectedName); + } + } else { + Assertions.assertTrue( + PIXELS_THRESHOLD >= diff.getDiffSize(), + String.format("Amount of differing pixels should be less or equals than %s, actual %s\n" + + "diff file: %s", + PIXELS_THRESHOLD, diff.getDiffSize(), FileSystems.getDefault().getPath(fullPathNameDiff).normalize().toAbsolutePath())); + } + } + + @SneakyThrows + private byte[] imgToBytes(String filename) { + BufferedImage bImage2 = ImageIO.read(new File(filename)); + var bos2 = new ByteArrayOutputStream(); + ImageIO.write(bImage2, "png", bos2); + return bos2.toByteArray(); + } + + + @Attachment + private byte[] actual(String actualFileName) { + return imgToBytes(actualFileName); + } + + + @Attachment + private byte[] expected(String expectedFileName) { + return imgToBytes(expectedFileName); + } + + + @Attachment + private byte[] diff(String diffFileName) { + return imgToBytes(diffFileName); + } } diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/SmokeTests.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/SmokeTests.java index 149acf4aa5..fbfb0990eb 100644 --- a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/SmokeTests.java +++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/SmokeTests.java @@ -4,7 +4,6 @@ import com.provectus.kafka.ui.base.BaseTest; import com.provectus.kafka.ui.utils.qaseIO.Status; import com.provectus.kafka.ui.utils.qaseIO.annotation.AutomationStatus; import io.qase.api.annotation.CaseId; -import lombok.SneakyThrows; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -12,7 +11,6 @@ public class SmokeTests extends BaseTest { @Test @AutomationStatus(status = Status.AUTOMATED) @CaseId(198) - @SneakyThrows @DisplayName("main page should load") void mainPageLoads() { pages.open() diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/ConnectorsTests.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/ConnectorsTests.java index fe0e468e45..379114fdd8 100644 --- a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/ConnectorsTests.java +++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/ConnectorsTests.java @@ -1,18 +1,18 @@ package com.provectus.kafka.ui.tests; import com.provectus.kafka.ui.base.BaseTest; -import com.provectus.kafka.ui.extensions.FileUtils; import com.provectus.kafka.ui.helpers.ApiHelper; import com.provectus.kafka.ui.helpers.Helpers; 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; import io.qase.api.annotation.CaseId; -import lombok.SneakyThrows; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import com.provectus.kafka.ui.utils.qaseIO.annotation.Suite; + +import static com.provectus.kafka.ui.extensions.FileUtils.getResourceAsString; public class ConnectorsTests extends BaseTest { @@ -28,13 +28,12 @@ public class ConnectorsTests extends BaseTest { public static final String CONNECTOR_FOR_UPDATE = "sink_postgres_activities_e2e_checks_for_update"; @BeforeAll - @SneakyThrows public static void beforeAll() { ApiHelper apiHelper = Helpers.INSTANCE.apiHelper; - String connectorToDelete = FileUtils.getResourceAsString("delete_connector_config.json"); - String connectorToUpdate = FileUtils.getResourceAsString("config_for_create_connector_via_api.json"); - String message = FileUtils.getResourceAsString("message_content_create_topic.json"); + String connectorToDelete = getResourceAsString("delete_connector_config.json"); + String connectorToUpdate = getResourceAsString("config_for_create_connector_via_api.json"); + String message = getResourceAsString("message_content_create_topic.json"); apiHelper.deleteTopic(LOCAL_CLUSTER, CONNECTOR_FOR_DELETE); @@ -52,7 +51,6 @@ public class ConnectorsTests extends BaseTest { } @AfterAll - @SneakyThrows public static void afterAll() { ApiHelper apiHelper = Helpers.INSTANCE.apiHelper; apiHelper.deleteConnector(LOCAL_CLUSTER, FIRST_CONNECTOR, SINK_CONNECTOR); @@ -62,7 +60,6 @@ public class ConnectorsTests extends BaseTest { apiHelper.deleteTopic(LOCAL_CLUSTER, TOPIC_FOR_UPDATE_CONNECTOR); } - @SneakyThrows @DisplayName("should create a connector") @Suite(suiteId = suiteId, title = suiteTitle) @AutomationStatus(status = Status.AUTOMATED) @@ -75,13 +72,12 @@ public class ConnectorsTests extends BaseTest { .waitUntilScreenReady() .setConnectorConfig( SINK_CONNECTOR, - FileUtils.getResourceAsString("config_for_create_connector.json")); + getResourceAsString("config_for_create_connector.json")); pages.openConnectorsList(LOCAL_CLUSTER) .waitUntilScreenReady() .connectorIsVisibleInList(SINK_CONNECTOR, TOPIC_FOR_CONNECTOR); } - @SneakyThrows @DisplayName("should update a connector") @Suite(suiteId = suiteId, title = suiteTitle) @AutomationStatus(status = Status.AUTOMATED) @@ -93,12 +89,11 @@ public class ConnectorsTests extends BaseTest { .openConnector(CONNECTOR_FOR_UPDATE); pages.connectorsView.connectorIsVisibleOnOverview(); pages.connectorsView.openEditConfig() - .updConnectorConfig(FileUtils.getResourceAsString("config_for_update_connector.json")); + .updConnectorConfig(getResourceAsString("config_for_update_connector.json")); pages.openConnectorsList(LOCAL_CLUSTER) .connectorIsVisibleInList(CONNECTOR_FOR_UPDATE, TOPIC_FOR_UPDATE_CONNECTOR); } - @SneakyThrows @DisplayName("should delete connector") @Suite(suiteId = suiteId, title = suiteTitle) @AutomationStatus(status = Status.AUTOMATED) diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/SchemasTests.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/SchemasTests.java index af14f10819..239f66f5cf 100644 --- a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/SchemasTests.java +++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/SchemasTests.java @@ -8,14 +8,11 @@ import com.provectus.kafka.ui.pages.MainPage; import com.provectus.kafka.ui.pages.schema.SchemaCreateView; import com.provectus.kafka.ui.utils.qaseIO.Status; import com.provectus.kafka.ui.utils.qaseIO.annotation.AutomationStatus; -import io.qase.api.annotation.CaseId; -import lombok.SneakyThrows; -import org.junit.jupiter.api.*; import com.provectus.kafka.ui.utils.qaseIO.annotation.Suite; +import io.qase.api.annotation.CaseId; +import org.junit.jupiter.api.*; -import java.io.IOException; - -import static org.apache.kafka.common.utils.Utils.readFileAsString; +import static com.provectus.kafka.ui.extensions.FileUtils.fileToString; @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class SchemasTests extends BaseTest { @@ -36,16 +33,14 @@ public class SchemasTests extends BaseTest { private static final String PATH_JSON_VALUE = System.getProperty("user.dir") + "/src/test/resources/schema_Json_Value.json"; @BeforeAll - @SneakyThrows public static void beforeAll() { - Helpers.INSTANCE.apiHelper.createSchema(SECOND_LOCAL, SCHEMA_AVRO_API_UPDATE, SchemaType.AVRO, readFileAsString(PATH_AVRO_VALUE)); - Helpers.INSTANCE.apiHelper.createSchema(SECOND_LOCAL, SCHEMA_AVRO_API, SchemaType.AVRO, readFileAsString(PATH_AVRO_VALUE)); - Helpers.INSTANCE.apiHelper.createSchema(SECOND_LOCAL, SCHEMA_JSON_API, SchemaType.JSON, readFileAsString(PATH_JSON_VALUE)); - Helpers.INSTANCE.apiHelper.createSchema(SECOND_LOCAL, SCHEMA_PROTOBUF_API, SchemaType.PROTOBUF, readFileAsString(PATH_PROTOBUF_VALUE)); + Helpers.INSTANCE.apiHelper.createSchema(SECOND_LOCAL, SCHEMA_AVRO_API_UPDATE, SchemaType.AVRO, fileToString(PATH_AVRO_VALUE)); + Helpers.INSTANCE.apiHelper.createSchema(SECOND_LOCAL, SCHEMA_AVRO_API, SchemaType.AVRO, fileToString(PATH_AVRO_VALUE)); + Helpers.INSTANCE.apiHelper.createSchema(SECOND_LOCAL, SCHEMA_JSON_API, SchemaType.JSON, fileToString(PATH_JSON_VALUE)); + Helpers.INSTANCE.apiHelper.createSchema(SECOND_LOCAL, SCHEMA_PROTOBUF_API, SchemaType.PROTOBUF, fileToString(PATH_PROTOBUF_VALUE)); } @AfterAll - @SneakyThrows public static void afterAll() { Helpers.INSTANCE.apiHelper.deleteSchema(SECOND_LOCAL, SCHEMA_AVRO_CREATE); Helpers.INSTANCE.apiHelper.deleteSchema(SECOND_LOCAL, SCHEMA_JSON_CREATE); @@ -63,12 +58,12 @@ public class SchemasTests extends BaseTest { @CaseId(43) @Test @Order(1) - void createSchemaAvro() throws IOException { + void createSchemaAvro() { pages.openMainPage() .goToSideMenu(SECOND_LOCAL, MainPage.SideMenuOptions.SCHEMA_REGISTRY); pages.schemaRegistry.clickCreateSchema() .setSubjectName(SCHEMA_AVRO_CREATE) - .setSchemaField(readFileAsString(PATH_AVRO_VALUE)) + .setSchemaField(fileToString(PATH_AVRO_VALUE)) .selectSchemaTypeFromDropdown(SchemaCreateView.SchemaType.AVRO) .clickSubmit() .waitUntilScreenReady(); @@ -77,7 +72,6 @@ public class SchemasTests extends BaseTest { pages.schemaRegistry.isSchemaVisible(SCHEMA_AVRO_CREATE); } - @SneakyThrows @DisplayName("should update AVRO schema") @Suite(suiteId = suiteId, title = suiteTitle) @AutomationStatus(status = Status.AUTOMATED) @@ -91,13 +85,12 @@ public class SchemasTests extends BaseTest { .waitUntilScreenReady() .openEditSchema() .selectCompatibilityLevelFromDropdown(CompatibilityLevel.CompatibilityEnum.NONE) - .setNewSchemaValue(readFileAsString(PATH_AVRO_FOR_UPDATE)) + .setNewSchemaValue(fileToString(PATH_AVRO_FOR_UPDATE)) .clickSubmit() .waitUntilScreenReady() .isCompatibility(CompatibilityLevel.CompatibilityEnum.NONE); } - @SneakyThrows @DisplayName("should delete AVRO schema") @Suite(suiteId = suiteId, title = suiteTitle) @AutomationStatus(status = Status.AUTOMATED) @@ -113,7 +106,6 @@ public class SchemasTests extends BaseTest { .isNotVisible(SCHEMA_AVRO_API); } - @SneakyThrows @DisplayName("should create JSON schema") @Suite(suiteId = suiteId, title = suiteTitle) @AutomationStatus(status = Status.AUTOMATED) @@ -125,7 +117,7 @@ public class SchemasTests extends BaseTest { .goToSideMenu(SECOND_LOCAL, MainPage.SideMenuOptions.SCHEMA_REGISTRY); pages.schemaRegistry.clickCreateSchema() .setSubjectName(SCHEMA_JSON_CREATE) - .setSchemaField(readFileAsString(PATH_JSON_VALUE)) + .setSchemaField(fileToString(PATH_JSON_VALUE)) .selectSchemaTypeFromDropdown(SchemaCreateView.SchemaType.JSON) .clickSubmit() .waitUntilScreenReady(); @@ -134,7 +126,6 @@ public class SchemasTests extends BaseTest { pages.schemaRegistry.isSchemaVisible(SCHEMA_JSON_CREATE); } - @SneakyThrows @DisplayName("should delete JSON schema") @Suite(suiteId = suiteId, title = suiteTitle) @AutomationStatus(status = Status.AUTOMATED) @@ -150,7 +141,6 @@ public class SchemasTests extends BaseTest { .isNotVisible(SCHEMA_JSON_API); } - @SneakyThrows @DisplayName("should create PROTOBUF schema") @Suite(suiteId = suiteId, title = suiteTitle) @AutomationStatus(status = Status.AUTOMATED) @@ -162,7 +152,7 @@ public class SchemasTests extends BaseTest { .goToSideMenu(SECOND_LOCAL, MainPage.SideMenuOptions.SCHEMA_REGISTRY); pages.schemaRegistry.clickCreateSchema() .setSubjectName(SCHEMA_PROTOBUF_CREATE) - .setSchemaField(readFileAsString(PATH_PROTOBUF_VALUE)) + .setSchemaField(fileToString(PATH_PROTOBUF_VALUE)) .selectSchemaTypeFromDropdown(SchemaCreateView.SchemaType.PROTOBUF) .clickSubmit() .waitUntilScreenReady(); @@ -171,7 +161,6 @@ public class SchemasTests extends BaseTest { pages.schemaRegistry.isSchemaVisible(SCHEMA_PROTOBUF_CREATE); } - @SneakyThrows @DisplayName("should delete PROTOBUF schema") @Suite(suiteId = suiteId, title = suiteTitle) @AutomationStatus(status = Status.AUTOMATED) 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 0d6026e1ed..b799e6580b 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 @@ -9,10 +9,9 @@ import com.provectus.kafka.ui.utils.qaseIO.annotation.AutomationStatus; import com.provectus.kafka.ui.utils.qaseIO.annotation.Suite; import io.qameta.allure.Issue; import io.qase.api.annotation.CaseId; -import lombok.SneakyThrows; import org.junit.jupiter.api.*; -import static org.apache.kafka.common.utils.Utils.readFileAsString; +import static com.provectus.kafka.ui.extensions.FileUtils.fileToString; public class TopicTests extends BaseTest { @@ -29,21 +28,18 @@ public class TopicTests extends BaseTest { @BeforeAll - @SneakyThrows public static void beforeAll() { Helpers.INSTANCE.apiHelper.createTopic(SECOND_LOCAL, TOPIC_TO_UPDATE); Helpers.INSTANCE.apiHelper.createTopic(SECOND_LOCAL, TOPIC_TO_DELETE); } @AfterAll - @SneakyThrows public static void afterAll() { Helpers.INSTANCE.apiHelper.deleteTopic(SECOND_LOCAL, TOPIC_TO_UPDATE); Helpers.INSTANCE.apiHelper.deleteTopic(SECOND_LOCAL, TOPIC_TO_DELETE); Helpers.INSTANCE.apiHelper.deleteTopic(SECOND_LOCAL, NEW_TOPIC); } - @SneakyThrows @DisplayName("should create a topic") @Suite(suiteId = 4, title = "Create new Topic") @AutomationStatus(status = Status.AUTOMATED) @@ -65,7 +61,6 @@ public class TopicTests extends BaseTest { .topicIsNotVisible(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") @Suite(suiteId = 2, title = "Topics") @@ -97,7 +92,6 @@ public class TopicTests extends BaseTest { .maxMessageBytesIs(UPDATED_MAX_MESSAGE_BYTES); } - @SneakyThrows @DisplayName("should delete topic") @Suite(suiteId = 2, title = "Topics") @AutomationStatus(status = Status.AUTOMATED) @@ -113,7 +107,6 @@ public class TopicTests extends BaseTest { .isTopicNotVisible(TOPIC_TO_DELETE); } - @SneakyThrows @DisplayName("produce message") @Suite(suiteId = 2, title = "Topics") @AutomationStatus(status = Status.AUTOMATED) @@ -126,10 +119,10 @@ public class TopicTests extends BaseTest { .waitUntilScreenReady() .openTopicMenu(TopicView.TopicMenu.MESSAGES) .clickOnButton("Produce Message") - .setContentFiled(readFileAsString(CONTENT_TO_PRODUCE_MESSAGE)) - .setKeyField(readFileAsString(KEY_TO_PRODUCE_MESSAGE)) + .setContentFiled(fileToString(CONTENT_TO_PRODUCE_MESSAGE)) + .setKeyField(fileToString(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())); + Assertions.assertTrue(pages.topicView.isKeyMessageVisible(fileToString(KEY_TO_PRODUCE_MESSAGE))); + Assertions.assertTrue(pages.topicView.isContentMessageVisible(fileToString(CONTENT_TO_PRODUCE_MESSAGE).trim())); } }