Fix e2e run on m1/arm (#2371)

* Fix e2e run on m1

* Update README.md
This commit is contained in:
Roman Zabaluev 2022-08-01 20:18:24 +04:00 committed by GitHub
parent 70414d2279
commit 13d168c8a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 122 additions and 97 deletions

View file

@ -18,7 +18,7 @@ This repository is for E2E UI automation.
### Prerequisites ### Prerequisites
- Docker & Docker-compose - Docker & Docker-compose
- Java - Java (install aarch64 jdk if you have M1/arm chip)
- Maven - Maven
### How to install ### How to install

View file

@ -126,6 +126,12 @@
<artifactId>netty-transport-native-unix-common</artifactId> <artifactId>netty-transport-native-unix-common</artifactId>
<version>${netty.version}</version> <version>${netty.version}</version>
</dependency> </dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-resolver-dns-native-macos</artifactId>
<version>${netty.version}</version>
<classifier>osx-aarch_64</classifier>
</dependency>
<dependency> <dependency>
<groupId>org.testcontainers</groupId> <groupId>org.testcontainers</groupId>

View file

@ -14,10 +14,8 @@ public class TestConfiguration {
Boolean.parseBoolean(System.getProperty("SAVE_PAGE_SOURCE", "false")); Boolean.parseBoolean(System.getProperty("SAVE_PAGE_SOURCE", "false"));
public static Boolean REOPEN_BROWSER_ON_FAIL = public static Boolean REOPEN_BROWSER_ON_FAIL =
Boolean.parseBoolean(System.getProperty("REOPEN_BROWSER_ON_FAIL", "true")); Boolean.parseBoolean(System.getProperty("REOPEN_BROWSER_ON_FAIL", "true"));
public static String BROWSER = System.getProperty("BROWSER", "chrome"); public static String BROWSER = System.getProperty("BROWSER", "chromium");
public static String BROWSER_SIZE = System.getProperty("BROWSER_SIZE", "1920x1080"); public static String BROWSER_SIZE = System.getProperty("BROWSER_SIZE", "1920x1080");
public static Boolean ENABLE_VNC = Boolean.parseBoolean(System.getProperty("ENABLE_VNC", "true")); public static Boolean ENABLE_VNC = Boolean.parseBoolean(System.getProperty("ENABLE_VNC", "true"));
public static String IMAGE_NAME = System.getProperty("SELENIUM_DOCKER_IMAGE", "selenium/standalone-chrome");
public static String IMAGE_TAG = System.getProperty("SELENIUM_IMAGE_TAG", "103.0");
} }

View file

@ -12,10 +12,18 @@ import com.provectus.kafka.ui.utils.qaseIO.TestCaseGenerator;
import io.github.cdimascio.dotenv.Dotenv; import io.github.cdimascio.dotenv.Dotenv;
import io.qameta.allure.Allure; import io.qameta.allure.Allure;
import io.qameta.allure.selenide.AllureSelenide; 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.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils; 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.Dimension;
import org.openqa.selenium.OutputType; import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.TakesScreenshot;
@ -26,22 +34,17 @@ import org.testcontainers.containers.BrowserWebDriverContainer;
import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName; import org.testcontainers.utility.DockerImageName;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
@Slf4j @Slf4j
@DisplayNameGeneration(CamelCaseToSpacedDisplayNameGenerator.class) @DisplayNameGeneration(CamelCaseToSpacedDisplayNameGenerator.class)
public class BaseTest { public class BaseTest {
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 Pages pages = Pages.INSTANCE;
protected Helpers helpers = Helpers.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) { public void compareScreenshots(String name) {
@ -61,15 +64,27 @@ public class BaseTest {
@BeforeAll @BeforeAll
public static void start() { public static void start() {
DockerImageName image = DockerImageName.parse(IMAGE_NAME).withTag(IMAGE_TAG);
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());
webDriverContainer = new BrowserWebDriverContainer<>(image) webDriverContainer = new BrowserWebDriverContainer<>(image)
.withCapabilities(new ChromeOptions().addArguments("--disable-dev-shm-usage")) .withEnv("JAVA_OPTS", "-Dwebdriver.chrome.whitelistedIps=")
.withCapabilities(new ChromeOptions()
.addArguments("--disable-dev-shm-usage")
.addArguments("--verbose")
)
.waitingFor(Wait.forHttp("/")) .waitingFor(Wait.forHttp("/"))
//.withLogConsumer(new Slf4jLogConsumer(log).withPrefix("[CHROME]: ")) // uncomment for debugging
.waitingFor(Wait.forLogMessage(".*Started Selenium Standalone.*", 1)); .waitingFor(Wait.forLogMessage(".*Started Selenium Standalone.*", 1));
try {
Testcontainers.exposeHostPorts(8080); Testcontainers.exposeHostPorts(8080);
webDriverContainer.start(); webDriverContainer.start();
webDriverContainer.isRunning(); } catch (Throwable e) {
webDriverContainer.isHostAccessible(); log.error("Couldn't start a container", e);
}
} }
@AfterAll @AfterAll
@ -96,7 +111,8 @@ public class BaseTest {
setup(); setup();
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (TestCaseGenerator.FAILED) { if (TestCaseGenerator.FAILED) {
log.error("Tests FAILED because some problem with @CaseId annotation. Verify that all tests annotated with @CaseId and Id is correct!"); 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); Runtime.getRuntime().halt(100500);
} }
})); }));
@ -105,7 +121,8 @@ public class BaseTest {
@AfterEach @AfterEach
public void afterMethod() { public void afterMethod() {
Allure.addAttachment("Screenshot", Allure.addAttachment("Screenshot",
new ByteArrayInputStream(((TakesScreenshot) webDriverContainer.getWebDriver()).getScreenshotAs(OutputType.BYTES))); new ByteArrayInputStream(
((TakesScreenshot) webDriverContainer.getWebDriver()).getScreenshotAs(OutputType.BYTES)));
} }
@SneakyThrows @SneakyThrows
@ -134,4 +151,8 @@ public class BaseTest {
} }
} }
} }
private static boolean isARM64() {
return System.getProperty("os.arch").equals("aarch64");
}
} }