|
@@ -12,10 +12,18 @@ import com.provectus.kafka.ui.utils.qaseIO.TestCaseGenerator;
|
|
|
import io.github.cdimascio.dotenv.Dotenv;
|
|
|
import io.qameta.allure.Allure;
|
|
|
import io.qameta.allure.selenide.AllureSelenide;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Arrays;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
-import org.junit.jupiter.api.*;
|
|
|
+import org.junit.jupiter.api.AfterAll;
|
|
|
+import org.junit.jupiter.api.AfterEach;
|
|
|
+import org.junit.jupiter.api.BeforeAll;
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.DisplayNameGeneration;
|
|
|
import org.openqa.selenium.Dimension;
|
|
|
import org.openqa.selenium.OutputType;
|
|
|
import org.openqa.selenium.TakesScreenshot;
|
|
@@ -26,112 +34,125 @@ import org.testcontainers.containers.BrowserWebDriverContainer;
|
|
|
import org.testcontainers.containers.wait.strategy.Wait;
|
|
|
import org.testcontainers.utility.DockerImageName;
|
|
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.Arrays;
|
|
|
-
|
|
|
@Slf4j
|
|
|
@DisplayNameGeneration(CamelCaseToSpacedDisplayNameGenerator.class)
|
|
|
public class BaseTest {
|
|
|
|
|
|
- protected Pages pages = Pages.INSTANCE;
|
|
|
- protected Helpers helpers = Helpers.INSTANCE;
|
|
|
+ public static final String SELENIUM_IMAGE_NAME = "selenium/standalone-chrome";
|
|
|
+ public static final String SELENIARM_STANDALONE_CHROMIUM = "seleniarm/standalone-chromium";
|
|
|
+ protected Pages pages = Pages.INSTANCE;
|
|
|
+ protected Helpers helpers = Helpers.INSTANCE;
|
|
|
|
|
|
- private Screenshooter screenshooter = new Screenshooter();
|
|
|
+ private Screenshooter screenshooter = new Screenshooter();
|
|
|
|
|
|
- private static final String IMAGE_NAME = TestConfiguration.IMAGE_NAME;
|
|
|
- private static final String IMAGE_TAG = TestConfiguration.IMAGE_TAG;
|
|
|
- protected static BrowserWebDriverContainer<?> webDriverContainer = null;
|
|
|
+ protected static BrowserWebDriverContainer<?> webDriverContainer = null;
|
|
|
|
|
|
- public void compareScreenshots(String name) {
|
|
|
- screenshooter.compareScreenshots(name);
|
|
|
- }
|
|
|
+ public void compareScreenshots(String name) {
|
|
|
+ screenshooter.compareScreenshots(name);
|
|
|
+ }
|
|
|
|
|
|
- public void compareScreenshots(String name, Boolean shouldUpdateScreenshots) {
|
|
|
- screenshooter.compareScreenshots(name, shouldUpdateScreenshots);
|
|
|
- }
|
|
|
+ public void compareScreenshots(String name, Boolean shouldUpdateScreenshots) {
|
|
|
+ screenshooter.compareScreenshots(name, shouldUpdateScreenshots);
|
|
|
+ }
|
|
|
|
|
|
- @BeforeEach
|
|
|
- public void setWebDriver() {
|
|
|
- RemoteWebDriver remoteWebDriver = webDriverContainer.getWebDriver();
|
|
|
- WebDriverRunner.setWebDriver(remoteWebDriver);
|
|
|
- remoteWebDriver.manage().window().setSize(new Dimension(1440, 1024));
|
|
|
- }
|
|
|
+ @BeforeEach
|
|
|
+ public void setWebDriver() {
|
|
|
+ RemoteWebDriver remoteWebDriver = webDriverContainer.getWebDriver();
|
|
|
+ WebDriverRunner.setWebDriver(remoteWebDriver);
|
|
|
+ remoteWebDriver.manage().window().setSize(new Dimension(1440, 1024));
|
|
|
+ }
|
|
|
|
|
|
- @BeforeAll
|
|
|
- public static void start() {
|
|
|
- DockerImageName image = DockerImageName.parse(IMAGE_NAME).withTag(IMAGE_TAG);
|
|
|
- webDriverContainer = new BrowserWebDriverContainer<>(image)
|
|
|
- .withCapabilities(new ChromeOptions().addArguments("--disable-dev-shm-usage"))
|
|
|
- .waitingFor(Wait.forHttp("/"))
|
|
|
- .waitingFor(Wait.forLogMessage(".*Started Selenium Standalone.*", 1));
|
|
|
- Testcontainers.exposeHostPorts(8080);
|
|
|
- webDriverContainer.start();
|
|
|
- webDriverContainer.isRunning();
|
|
|
- webDriverContainer.isHostAccessible();
|
|
|
- }
|
|
|
+ @BeforeAll
|
|
|
+ public static void start() {
|
|
|
|
|
|
- @AfterAll
|
|
|
- public static void tearDown() {
|
|
|
- if (webDriverContainer.isRunning()) {
|
|
|
- webDriverContainer.close();
|
|
|
- webDriverContainer.stop();
|
|
|
- }
|
|
|
- }
|
|
|
+ DockerImageName image = isARM64()
|
|
|
+ ? DockerImageName.parse(SELENIARM_STANDALONE_CHROMIUM).asCompatibleSubstituteFor(SELENIUM_IMAGE_NAME)
|
|
|
+ : DockerImageName.parse(SELENIUM_IMAGE_NAME);
|
|
|
+ log.info("Using [{}] as image name for chrome", image.getUnversionedPart());
|
|
|
|
|
|
- static {
|
|
|
- if (!new File("./.env").exists()) {
|
|
|
- try {
|
|
|
- FileUtils.copyFile(new File(".env.example"), new File(".env"));
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("couldn't copy .env.example to .env. Please add .env");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- Dotenv.load().entries().forEach(env -> System.setProperty(env.getKey(), env.getValue()));
|
|
|
- if (TestConfiguration.CLEAR_REPORTS_DIR) {
|
|
|
- clearReports();
|
|
|
- }
|
|
|
- setup();
|
|
|
- Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
|
- if (TestCaseGenerator.FAILED) {
|
|
|
- log.error("Tests FAILED because some problem with @CaseId annotation. Verify that all tests annotated with @CaseId and Id is correct!");
|
|
|
- Runtime.getRuntime().halt(100500);
|
|
|
- }
|
|
|
- }));
|
|
|
+ webDriverContainer = new BrowserWebDriverContainer<>(image)
|
|
|
+ .withEnv("JAVA_OPTS", "-Dwebdriver.chrome.whitelistedIps=")
|
|
|
+ .withCapabilities(new ChromeOptions()
|
|
|
+ .addArguments("--disable-dev-shm-usage")
|
|
|
+ .addArguments("--verbose")
|
|
|
+ )
|
|
|
+ .waitingFor(Wait.forHttp("/"))
|
|
|
+ //.withLogConsumer(new Slf4jLogConsumer(log).withPrefix("[CHROME]: ")) // uncomment for debugging
|
|
|
+ .waitingFor(Wait.forLogMessage(".*Started Selenium Standalone.*", 1));
|
|
|
+ try {
|
|
|
+ Testcontainers.exposeHostPorts(8080);
|
|
|
+ webDriverContainer.start();
|
|
|
+ } catch (Throwable e) {
|
|
|
+ log.error("Couldn't start a container", e);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- @AfterEach
|
|
|
- public void afterMethod() {
|
|
|
- Allure.addAttachment("Screenshot",
|
|
|
- new ByteArrayInputStream(((TakesScreenshot) webDriverContainer.getWebDriver()).getScreenshotAs(OutputType.BYTES)));
|
|
|
+ @AfterAll
|
|
|
+ public static void tearDown() {
|
|
|
+ if (webDriverContainer.isRunning()) {
|
|
|
+ webDriverContainer.close();
|
|
|
+ webDriverContainer.stop();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- @SneakyThrows
|
|
|
- private static void setup() {
|
|
|
- Configuration.reportsFolder = TestConfiguration.REPORTS_FOLDER;
|
|
|
- Configuration.screenshots = TestConfiguration.SCREENSHOTS;
|
|
|
- Configuration.savePageSource = TestConfiguration.SAVE_PAGE_SOURCE;
|
|
|
- Configuration.reopenBrowserOnFail = TestConfiguration.REOPEN_BROWSER_ON_FAIL;
|
|
|
- Configuration.browser = TestConfiguration.BROWSER;
|
|
|
- Configuration.baseUrl = TestConfiguration.BASE_WEB_URL;
|
|
|
- Configuration.timeout = 10000;
|
|
|
- Configuration.browserSize = TestConfiguration.BROWSER_SIZE;
|
|
|
- SelenideLogger.addListener("allure", new AllureSelenide().savePageSource(false));
|
|
|
+ static {
|
|
|
+ if (!new File("./.env").exists()) {
|
|
|
+ try {
|
|
|
+ FileUtils.copyFile(new File(".env.example"), new File(".env"));
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("couldn't copy .env.example to .env. Please add .env");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
+ Dotenv.load().entries().forEach(env -> System.setProperty(env.getKey(), env.getValue()));
|
|
|
+ if (TestConfiguration.CLEAR_REPORTS_DIR) {
|
|
|
+ clearReports();
|
|
|
+ }
|
|
|
+ setup();
|
|
|
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
|
+ if (TestCaseGenerator.FAILED) {
|
|
|
+ log.error(
|
|
|
+ "Tests FAILED because some problem with @CaseId annotation. Verify that all tests annotated with @CaseId and Id is correct!");
|
|
|
+ Runtime.getRuntime().halt(100500);
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ @AfterEach
|
|
|
+ public void afterMethod() {
|
|
|
+ Allure.addAttachment("Screenshot",
|
|
|
+ new ByteArrayInputStream(
|
|
|
+ ((TakesScreenshot) webDriverContainer.getWebDriver()).getScreenshotAs(OutputType.BYTES)));
|
|
|
+ }
|
|
|
|
|
|
- public static void clearReports() {
|
|
|
- log.info(String.format("Clearing reports dir [%s]...", TestConfiguration.REPORTS_FOLDER));
|
|
|
- File allureResults = new File(TestConfiguration.REPORTS_FOLDER);
|
|
|
- if (allureResults.isDirectory()) {
|
|
|
- File[] list = allureResults.listFiles();
|
|
|
- if (list != null) {
|
|
|
- Arrays.stream(list)
|
|
|
- .sequential()
|
|
|
- .filter(e -> !e.getName().equals("categories.json"))
|
|
|
- .forEach(File::delete);
|
|
|
- }
|
|
|
- }
|
|
|
+ @SneakyThrows
|
|
|
+ private static void setup() {
|
|
|
+ Configuration.reportsFolder = TestConfiguration.REPORTS_FOLDER;
|
|
|
+ Configuration.screenshots = TestConfiguration.SCREENSHOTS;
|
|
|
+ Configuration.savePageSource = TestConfiguration.SAVE_PAGE_SOURCE;
|
|
|
+ Configuration.reopenBrowserOnFail = TestConfiguration.REOPEN_BROWSER_ON_FAIL;
|
|
|
+ Configuration.browser = TestConfiguration.BROWSER;
|
|
|
+ Configuration.baseUrl = TestConfiguration.BASE_WEB_URL;
|
|
|
+ Configuration.timeout = 10000;
|
|
|
+ Configuration.browserSize = TestConfiguration.BROWSER_SIZE;
|
|
|
+ SelenideLogger.addListener("allure", new AllureSelenide().savePageSource(false));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void clearReports() {
|
|
|
+ log.info(String.format("Clearing reports dir [%s]...", TestConfiguration.REPORTS_FOLDER));
|
|
|
+ File allureResults = new File(TestConfiguration.REPORTS_FOLDER);
|
|
|
+ if (allureResults.isDirectory()) {
|
|
|
+ File[] list = allureResults.listFiles();
|
|
|
+ if (list != null) {
|
|
|
+ Arrays.stream(list)
|
|
|
+ .sequential()
|
|
|
+ .filter(e -> !e.getName().equals("categories.json"))
|
|
|
+ .forEach(File::delete);
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean isARM64() {
|
|
|
+ return System.getProperty("os.arch").equals("aarch64");
|
|
|
+ }
|
|
|
}
|