From fc9a31f81375fff820a6a718b606b359073cd892 Mon Sep 17 00:00:00 2001 From: wind Date: Thu, 10 Feb 2022 10:00:50 +0800 Subject: [PATCH] [E2E] add switch task case (#8180) * fix switch bug * add switch e2e test * add switch workflow * pre task option * selectPreTask id * update * switch task e2e * naming optimization Co-authored-by: caishunfeng <534328519@qq.com> --- .github/workflows/e2e.yml | 2 + .../task/switchtask/SwitchParameters.java | 4 + .../e2e/cases/WorkflowSwitchE2ETest.java | 185 ++++++++++++++++++ .../e2e/pages/project/ProjectDetailPage.java | 7 + .../project/workflow/TaskInstanceTab.java | 65 ++++++ .../pages/project/workflow/WorkflowForm.java | 36 +++- .../workflow/WorkflowFormatDialog.java | 64 ++++++ .../project/workflow/task/SwitchTaskForm.java | 94 +++++++++ .../workflow/task/SwitchTaskIfBranch.java | 52 +++++ .../project/workflow/task/TaskNodeForm.java | 29 +++ .../dag/_source/formModel/tasks/pre_tasks.vue | 2 + .../dag/_source/formModel/tasks/switch.vue | 8 +- .../pages/taskInstance/_source/list.vue | 6 +- .../components/secondaryMenu/_source/menu.js | 3 +- 14 files changed, 548 insertions(+), 9 deletions(-) create mode 100644 dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowSwitchE2ETest.java create mode 100644 dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/TaskInstanceTab.java create mode 100644 dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowFormatDialog.java create mode 100644 dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/SwitchTaskForm.java create mode 100644 dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/SwitchTaskIfBranch.java diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 74ec3a83de..e5ceb91e2c 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -85,6 +85,8 @@ jobs: class: org.apache.dolphinscheduler.e2e.cases.TokenE2ETest - name: Workflow class: org.apache.dolphinscheduler.e2e.cases.WorkflowE2ETest + - name: WorkflowForSwitch + class: org.apache.dolphinscheduler.e2e.cases.WorkflowSwitchE2ETest - name: FileManage class: org.apache.dolphinscheduler.e2e.cases.FileManageE2ETest - name: UdfManage diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/switchtask/SwitchParameters.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/switchtask/SwitchParameters.java index dc59795308..e3c9b6e26a 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/switchtask/SwitchParameters.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/switchtask/SwitchParameters.java @@ -84,6 +84,10 @@ public class SwitchParameters extends AbstractParameters { List nextNodeList = new ArrayList<>(); nextNodeList.add(String.valueOf(nextNode)); this.nextNode = nextNodeList; + } else if (nextNode instanceof Number) { + List nextNodeList = new ArrayList<>(); + nextNodeList.add(nextNode.toString()); + this.nextNode = nextNodeList; } else { this.nextNode = (ArrayList) nextNode; } diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowSwitchE2ETest.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowSwitchE2ETest.java new file mode 100644 index 0000000000..f50c708ac3 --- /dev/null +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/WorkflowSwitchE2ETest.java @@ -0,0 +1,185 @@ +/* + * Licensed to Apache Software Foundation (ASF) under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Apache Software Foundation (ASF) licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.dolphinscheduler.e2e.cases; + +import org.apache.dolphinscheduler.e2e.core.DolphinScheduler; +import org.apache.dolphinscheduler.e2e.pages.LoginPage; +import org.apache.dolphinscheduler.e2e.pages.common.NavBarPage; +import org.apache.dolphinscheduler.e2e.pages.project.ProjectDetailPage; +import org.apache.dolphinscheduler.e2e.pages.project.ProjectPage; +import org.apache.dolphinscheduler.e2e.pages.project.workflow.TaskInstanceTab; +import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowDefinitionTab; +import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowForm; +import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowForm.TaskType; +import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowInstanceTab; +import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowInstanceTab.Row; +import org.apache.dolphinscheduler.e2e.pages.project.workflow.task.ShellTaskForm; +import org.apache.dolphinscheduler.e2e.pages.project.workflow.task.SwitchTaskForm; +import org.apache.dolphinscheduler.e2e.pages.security.SecurityPage; +import org.apache.dolphinscheduler.e2e.pages.security.TenantPage; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.remote.RemoteWebDriver; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +@DolphinScheduler(composeFiles = "docker/basic/docker-compose.yaml") +class WorkflowSwitchE2ETest { + private static final String project = "test-workflow-1"; + private static final String workflow = "test-workflow-1"; + private static final String ifBranchName = "key==1"; + private static final String elseBranchName = "key!=1"; + + private static final String tenant = System.getProperty("user.name"); + + private static RemoteWebDriver browser; + + @BeforeAll + public static void setup() { + new LoginPage(browser) + .login("admin", "dolphinscheduler123") + .goToNav(SecurityPage.class) + .goToTab(TenantPage.class) + .create(tenant) + .goToNav(ProjectPage.class) + .create(project) + ; + } + + @AfterAll + public static void cleanup() { + new NavBarPage(browser) + .goToNav(ProjectPage.class) + .goTo(project) + .goToTab(WorkflowDefinitionTab.class) + .cancelPublishAll() + .deleteAll() + ; + new NavBarPage(browser) + .goToNav(ProjectPage.class) + .delete(project) + .goToNav(SecurityPage.class) + .goToTab(TenantPage.class) + .delete(tenant) + ; + } + + @Test + @Order(1) + void testCreateSwitchWorkflow() { + + final WorkflowDefinitionTab workflowDefinitionPage = + new ProjectPage(browser) + .goTo(project) + .goToTab(WorkflowDefinitionTab.class); + + WorkflowForm workflowForm = workflowDefinitionPage.createWorkflow(); + + workflowForm. addTask(TaskType.SHELL) + .script("echo ${today}\necho ${global_param}\n") + .name("pre-task") + .submit(); + + SwitchTaskForm switchTaskForm = workflowForm.addTask(TaskType.SWITCH); + switchTaskForm.preTask("pre-task") + .name("switch") + .submit(); + + workflowForm.addTask(TaskType.SHELL) + .script("echo ${key}") + .preTask("switch") + .name(ifBranchName) + .submit(); + + workflowForm.addTask(TaskType.SHELL) + .script("echo ${key}") + .preTask("switch") + .name(elseBranchName) + .submit(); + + // format dag + workflowForm.formatDAG().confirm(); + + // add branch for switch task + workflowForm.getTask("switch"); + switchTaskForm.addIfBranch("${key}==1", ifBranchName); + switchTaskForm.elseBranch(elseBranchName); + switchTaskForm.submit(); + + workflowForm.submit() + .name(workflow) + .tenant(tenant) + .addGlobalParam("key", "1") + .submit(); + + await().untilAsserted(() -> assertThat( + workflowDefinitionPage.workflowList() + ).anyMatch(it -> it.getText().contains(workflow))); + + workflowDefinitionPage.publish(workflow); + } + + @Test + @Order(10) + void testRunWorkflow() { + final ProjectDetailPage projectPage = + new ProjectPage(browser) + .goToNav(ProjectPage.class) + .goTo(project); + + projectPage + .goToTab(WorkflowInstanceTab.class) + .deleteAll(); + + projectPage + .goToTab(WorkflowDefinitionTab.class) + .run(workflow) + .submit(); + + await().untilAsserted(() -> { + browser.navigate().refresh(); + + final Row row = projectPage + .goToTab(WorkflowInstanceTab.class) + .instances() + .iterator() + .next(); + + assertThat(row.isSuccess()).isTrue(); + assertThat(row.executionTime()).isEqualTo(1); + }); + + // check task for switch + List taskInstances = projectPage + .goToTab(TaskInstanceTab.class) + .instances(); + + await().untilAsserted(() -> { + assertThat(taskInstances.size()).isEqualTo(3); + assertThat(taskInstances.stream().filter(row -> row.name().contains(ifBranchName)).count()).isEqualTo(1); + assertThat(taskInstances.stream().noneMatch(row -> row.name().contains(elseBranchName))).isTrue(); + }); + } +} diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/ProjectDetailPage.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/ProjectDetailPage.java index f4440cca0a..aad086385a 100644 --- a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/ProjectDetailPage.java +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/ProjectDetailPage.java @@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.e2e.pages.project; import org.apache.dolphinscheduler.e2e.pages.common.NavBarPage; +import org.apache.dolphinscheduler.e2e.pages.project.workflow.TaskInstanceTab; import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowDefinitionTab; import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowInstanceTab; @@ -35,6 +36,8 @@ public final class ProjectDetailPage extends NavBarPage { private WebElement menuProcessDefinition; @FindBy(className = "tab-process-instance") private WebElement menuProcessInstances; + @FindBy(className = "tab-task-instance") + private WebElement menuTaskInstances; public ProjectDetailPage(RemoteWebDriver driver) { super(driver); @@ -49,6 +52,10 @@ public final class ProjectDetailPage extends NavBarPage { menuProcessInstances().click(); return tab.cast(new WorkflowInstanceTab(driver)); } + if (tab == TaskInstanceTab.class) { + menuTaskInstances().click(); + return tab.cast(new TaskInstanceTab(driver)); + } throw new UnsupportedOperationException("Unknown tab: " + tab.getName()); } diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/TaskInstanceTab.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/TaskInstanceTab.java new file mode 100644 index 0000000000..cbaa036e21 --- /dev/null +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/TaskInstanceTab.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.dolphinscheduler.e2e.pages.project.workflow; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.apache.dolphinscheduler.e2e.pages.common.NavBarPage; +import org.apache.dolphinscheduler.e2e.pages.project.ProjectDetailPage; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.FindBys; + +import java.util.List; +import java.util.stream.Collectors; + +@Getter +public final class TaskInstanceTab extends NavBarPage implements ProjectDetailPage.Tab { + @FindBy(className = "items-task-instances") + private List instanceList; + + public TaskInstanceTab(RemoteWebDriver driver) { + super(driver); + } + + public List instances() { + return instanceList() + .stream() + .filter(WebElement::isDisplayed) + .map(Row::new) + .filter(row -> !row.name().isEmpty()) + .collect(Collectors.toList()); + } + + @RequiredArgsConstructor + public static class Row { + private final WebElement row; + + public String state() { + return row.findElement(By.className("task-instance-state")).getText(); + } + + public String name() { + return row.findElement(By.className("task-instance-name")).getText(); + } + } +} diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowForm.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowForm.java index 87da7823df..72acbd00bf 100644 --- a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowForm.java +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowForm.java @@ -23,11 +23,14 @@ import org.apache.dolphinscheduler.e2e.pages.project.workflow.task.ShellTaskForm import org.apache.dolphinscheduler.e2e.pages.project.workflow.task.SubWorkflowTaskForm; import java.nio.charset.StandardCharsets; +import java.util.List; +import org.apache.dolphinscheduler.e2e.pages.project.workflow.task.SwitchTaskForm; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; @@ -35,12 +38,18 @@ import com.google.common.io.Resources; import lombok.Getter; import lombok.SneakyThrows; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; @SuppressWarnings("UnstableApiUsage") @Getter public final class WorkflowForm { private final WebDriver driver; private final WorkflowSaveDialog saveForm; + private final WorkflowFormatDialog formatDialog; + + @FindBy(className = "graph-format") + private WebElement formatBtn; @FindBy(id = "btnSave") private WebElement buttonSave; @@ -48,6 +57,7 @@ public final class WorkflowForm { public WorkflowForm(WebDriver driver) { this.driver = driver; this.saveForm = new WorkflowSaveDialog(this); + this.formatDialog = new WorkflowFormatDialog(this); PageFactory.initElements(driver, this); } @@ -60,7 +70,7 @@ public final class WorkflowForm { final JavascriptExecutor js = (JavascriptExecutor) driver; final String dragAndDrop = String.join("\n", - Resources.readLines(Resources.getResource("dragAndDrop.js"), StandardCharsets.UTF_8)); + Resources.readLines(Resources.getResource("dragAndDrop.js"), StandardCharsets.UTF_8)); js.executeScript(dragAndDrop, task, canvas); switch (type) { @@ -68,18 +78,42 @@ public final class WorkflowForm { return (T) new ShellTaskForm(this); case SUB_PROCESS: return (T) new SubWorkflowTaskForm(this); + case SWITCH: + return (T) new SwitchTaskForm(this); } throw new UnsupportedOperationException("Unknown task type"); } + public WebElement getTask(String taskName) { + List tasks = new WebDriverWait(driver, 10) + .until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("svg > g > g[class^='x6-graph-svg-stage'] > g[data-shape^='dag-task']"))); + + WebElement task = tasks.stream() + .filter(t -> t.getText().contains(taskName)) + .findFirst() + .orElseThrow(() -> new RuntimeException("No such task: " + taskName)); + + Actions action = new Actions(driver); + action.doubleClick(task).build().perform(); + + return task; + } + public WorkflowSaveDialog submit() { buttonSave().click(); return new WorkflowSaveDialog(this); } + public WorkflowFormatDialog formatDAG() { + formatBtn.click(); + + return new WorkflowFormatDialog(this); + } + public enum TaskType { SHELL, SUB_PROCESS, + SWITCH, } } diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowFormatDialog.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowFormatDialog.java new file mode 100644 index 0000000000..f0ecf53b46 --- /dev/null +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/WorkflowFormatDialog.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.dolphinscheduler.e2e.pages.project.workflow; + +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.FindBys; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.pagefactory.ByChained; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.util.List; +import java.util.stream.Stream; + +@Getter +public final class WorkflowFormatDialog { + private final WebDriver driver; + private final WorkflowForm parent; + + @FindBys({ + @FindBy(className = "el-dialog__wrapper"), + @FindBy(className = "el-button--primary"), + }) + private List buttonConfirm; + + public WorkflowFormatDialog(WorkflowForm parent) { + this.parent = parent; + this.driver = parent.driver(); + + PageFactory.initElements(driver, this); + } + + public WorkflowForm confirm() { + buttonConfirm() + .stream() + .filter(WebElement::isDisplayed) + .findFirst() + .orElseThrow(() -> new RuntimeException("No confirm button when confirm")) + .click(); + + return parent; + } +} diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/SwitchTaskForm.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/SwitchTaskForm.java new file mode 100644 index 0000000000..7dc3497e41 --- /dev/null +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/SwitchTaskForm.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.dolphinscheduler.e2e.pages.project.workflow.task; + +import lombok.Getter; +import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowForm; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.FindBys; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.util.List; + +@Getter +public final class SwitchTaskForm extends TaskNodeForm { + + @FindBy(id = "btnAddIfBranch") + private WebElement buttonAddBranch; + + @FindBys({ + @FindBy(className = "switch-task"), + @FindBy(className = "switch-else"), + @FindBy(className = "el-input__inner") + }) + private WebElement inputElseBranch; + + public SwitchTaskForm(WorkflowForm parent) { + super(parent); + } + + public SwitchTaskForm elseBranch(String elseBranchName) { + ((JavascriptExecutor)parent().driver()).executeScript("arguments[0].click();", inputElseBranch()); + + final By optionsLocator = By.className("option-else-branches"); + + new WebDriverWait(parent().driver(), 10) + .until(ExpectedConditions.visibilityOfElementLocated(optionsLocator)); + + List webElements = parent().driver().findElements(optionsLocator); + webElements.stream() + .filter(it -> it.getText().contains(elseBranchName)) + .findFirst() + .orElseThrow(() -> new RuntimeException("No such else branch: " + elseBranchName)) + .click(); + + inputNodeName().click(); + + return this; + } + + public SwitchTaskForm addIfBranch(String switchScript, String ifBranchName) { + ((JavascriptExecutor)parent().driver()).executeScript("arguments[0].click();", buttonAddBranch); + + SwitchTaskIfBranch switchTaskIfBranch = new SwitchTaskIfBranch(this); + switchTaskIfBranch.codeEditor().content(switchScript); + + ((JavascriptExecutor)parent().driver()).executeScript("arguments[0].click();", switchTaskIfBranch.inputIfBranch()); + + final By optionsLocator = By.className("option-if-branches"); + + new WebDriverWait(parent().driver(), 10) + .until(ExpectedConditions.visibilityOfElementLocated(optionsLocator)); + + List webElements = parent().driver().findElements(optionsLocator); + webElements.stream() + .filter(it -> it.getText().contains(ifBranchName)) + .findFirst() + .orElseThrow(() -> new RuntimeException("No such if branch: " + ifBranchName)) + .click(); + + inputNodeName().click(); + return this; + } +} diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/SwitchTaskIfBranch.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/SwitchTaskIfBranch.java new file mode 100644 index 0000000000..593778f431 --- /dev/null +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/SwitchTaskIfBranch.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.dolphinscheduler.e2e.pages.project.workflow.task; + +import lombok.Getter; +import org.apache.dolphinscheduler.e2e.pages.common.CodeEditor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.FindBys; +import org.openqa.selenium.support.PageFactory; + +@Getter +public final class SwitchTaskIfBranch { + private final WebDriver driver; + private final SwitchTaskForm parent; + + private final CodeEditor codeEditor; + + @FindBys({ + @FindBy(className = "switch-task"), + @FindBy(className = "switch-list"), + @FindBy(className = "el-input") + }) + private WebElement inputIfBranch; + + public SwitchTaskIfBranch(SwitchTaskForm parent) { + this.parent = parent; + this.driver = parent.parent().driver(); + + this.codeEditor = new CodeEditor(driver); + + PageFactory.initElements(driver, this); + } +} diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/TaskNodeForm.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/TaskNodeForm.java index 4537985890..8eb1e73ace 100644 --- a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/TaskNodeForm.java +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/project/workflow/task/TaskNodeForm.java @@ -22,12 +22,15 @@ package org.apache.dolphinscheduler.e2e.pages.project.workflow.task; import lombok.Getter; import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowForm; import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBys; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.pagefactory.ByChained; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; import java.util.List; import java.util.stream.Stream; @@ -49,6 +52,12 @@ public abstract class TaskNodeForm { }) private List inputParamVal; + @FindBys({ + @FindBy(className = "pre_tasks-model"), + @FindBy(tagName = "input"), + }) + private WebElement selectPreTasks; + private final WorkflowForm parent; TaskNodeForm(WorkflowForm parent) { @@ -84,6 +93,26 @@ public abstract class TaskNodeForm { return this; } + public TaskNodeForm preTask(String preTaskName) { + ((JavascriptExecutor)parent().driver()).executeScript("arguments[0].click();", selectPreTasks); + + final By optionsLocator = By.className("option-pre-tasks"); + + new WebDriverWait(parent.driver(), 10) + .until(ExpectedConditions.visibilityOfElementLocated(optionsLocator)); + + List webElements = parent.driver().findElements(optionsLocator); + webElements.stream() + .filter(it -> it.getText().contains(preTaskName)) + .findFirst() + .orElseThrow(() -> new RuntimeException("No such task: " + preTaskName)) + .click(); + + inputNodeName().click(); + + return this; + } + public WorkflowForm submit() { buttonSubmit.click(); diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/pre_tasks.vue b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/pre_tasks.vue index 5ffd2c8c03..05d1178079 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/pre_tasks.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/dag/_source/formModel/tasks/pre_tasks.vue @@ -20,6 +20,7 @@
{{ $t("Pre tasks") }}
- +
@@ -35,7 +35,7 @@ {{$t('Branch flow')}} - + @@ -51,9 +51,9 @@
{{$t('Branch flow')}}
-
+
- +
diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/taskInstance/_source/list.vue b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/taskInstance/_source/list.vue index 40b20f8754..306e757449 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/taskInstance/_source/list.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/taskInstance/_source/list.vue @@ -17,9 +17,9 @@