From 197accc60107370600719a7ade7e86bd80f69d26 Mon Sep 17 00:00:00 2001 From: xiangzihao <460888207@qq.com> Date: Tue, 22 Mar 2022 14:11:50 +0800 Subject: [PATCH] [Feature][e2e] Suggest e2e test adapt M1 chip (#9077) --- .../project/workflow/WorkflowRunDialog.java | 4 ++ .../e2e/core/DolphinSchedulerExtension.java | 68 +++++++++++++------ 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowRunDialog.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowRunDialog.java index 8d5e065465..493f729b1d 100644 --- a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowRunDialog.java +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowRunDialog.java @@ -24,6 +24,8 @@ import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; import lombok.Getter; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; @Getter public final class WorkflowRunDialog { @@ -39,6 +41,8 @@ public final class WorkflowRunDialog { } public WorkflowDefinitionTab submit() { + new WebDriverWait(parent().driver(), 5).until(ExpectedConditions.elementToBeClickable(buttonSubmit())); + buttonSubmit().click(); return parent(); diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/DolphinSchedulerExtension.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/DolphinSchedulerExtension.java index 55f6c302a5..21e2f129db 100644 --- a/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/DolphinSchedulerExtension.java +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/DolphinSchedulerExtension.java @@ -59,13 +59,14 @@ import com.google.common.base.Strings; import com.google.common.net.HostAndPort; import lombok.extern.slf4j.Slf4j; +import org.testcontainers.utility.DockerImageName; @Slf4j -final class DolphinSchedulerExtension - implements BeforeAllCallback, AfterAllCallback, - BeforeEachCallback { +final class DolphinSchedulerExtension implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback { private final boolean LOCAL_MODE = Objects.equals(System.getProperty("local"), "true"); + private final boolean M1_CHIP_FLAG = Objects.equals(System.getProperty("m1_chip"), "true"); + private RemoteWebDriver driver; private DockerComposeContainer compose; private BrowserWebDriverContainer browser; @@ -73,36 +74,24 @@ final class DolphinSchedulerExtension private HostAndPort address; private String rootPath; + private Path record; + @Override @SuppressWarnings("UnstableApiUsage") public void beforeAll(ExtensionContext context) throws IOException { Awaitility.setDefaultTimeout(Duration.ofSeconds(60)); Awaitility.setDefaultPollInterval(Duration.ofSeconds(10)); + setRecordPath(); + if (LOCAL_MODE) { runInLocal(); } else { runInDockerContainer(context); } - final Path record; - if (!Strings.isNullOrEmpty(System.getenv("RECORDING_PATH"))) { - record = Paths.get(System.getenv("RECORDING_PATH")); - if (!record.toFile().exists()) { - if (!record.toFile().mkdir()) { - throw new IOException("Failed to create recording directory: " + record.toAbsolutePath()); - } - } - } else { - record = Files.createTempDirectory("record-"); - } + setBrowserContainerByOsName(); - browser = new BrowserWebDriverContainer<>() - .withCapabilities(new ChromeOptions()) - .withCreateContainerCmdModifier(cmd -> cmd.withUser("root")) - .withFileSystemBind(Constants.HOST_CHROME_DOWNLOAD_PATH.toFile().getAbsolutePath(), - Constants.SELENIUM_CONTAINER_CHROME_DOWNLOAD_PATH) - .withRecordingMode(RECORD_ALL, record.toFile(), MP4); if (network != null) { browser.withNetwork(network); } @@ -128,8 +117,8 @@ final class DolphinSchedulerExtension } private void runInLocal() { - Testcontainers.exposeHostPorts(8888); - address = HostAndPort.fromParts("host.testcontainers.internal", 8888); + Testcontainers.exposeHostPorts(3000); + address = HostAndPort.fromParts("host.testcontainers.internal", 3000); rootPath = "/"; } @@ -159,6 +148,41 @@ final class DolphinSchedulerExtension rootPath = "/dolphinscheduler/ui/"; } + private void setBrowserContainerByOsName() { + DockerImageName imageName; + + if (LOCAL_MODE && M1_CHIP_FLAG) { + imageName = DockerImageName.parse("seleniarm/standalone-chromium:4.1.2-20220227") + .asCompatibleSubstituteFor("selenium/standalone-chrome"); + + browser = new BrowserWebDriverContainer<>(imageName) + .withCapabilities(new ChromeOptions()) + .withCreateContainerCmdModifier(cmd -> cmd.withUser("root")) + .withFileSystemBind(Constants.HOST_CHROME_DOWNLOAD_PATH.toFile().getAbsolutePath(), + Constants.SELENIUM_CONTAINER_CHROME_DOWNLOAD_PATH); + } else { + browser = new BrowserWebDriverContainer<>() + .withCapabilities(new ChromeOptions()) + .withCreateContainerCmdModifier(cmd -> cmd.withUser("root")) + .withFileSystemBind(Constants.HOST_CHROME_DOWNLOAD_PATH.toFile().getAbsolutePath(), + Constants.SELENIUM_CONTAINER_CHROME_DOWNLOAD_PATH) + .withRecordingMode(RECORD_ALL, record.toFile(), MP4); + } + } + + private void setRecordPath() throws IOException { + if (!Strings.isNullOrEmpty(System.getenv("RECORDING_PATH"))) { + record = Paths.get(System.getenv("RECORDING_PATH")); + if (!record.toFile().exists()) { + if (!record.toFile().mkdir()) { + throw new IOException("Failed to create recording directory: " + record.toAbsolutePath()); + } + } + } else { + record = Files.createTempDirectory("record-"); + } + } + @Override public void afterAll(ExtensionContext context) { browser.afterTest(new TestDescription(context), Optional.empty());