Skip to content

Commit

Permalink
Fix the select resource bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ailiujiarui committed Oct 30, 2024
1 parent dececfa commit 535815a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.dolphinscheduler.e2e.cases;

import static org.assertj.core.api.Assertions.assertThat;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;

import org.apache.dolphinscheduler.e2e.core.DolphinScheduler;
import org.apache.dolphinscheduler.e2e.core.WebDriverWaitFactory;
Expand Down Expand Up @@ -62,7 +63,6 @@
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testcontainers.shaded.org.awaitility.Awaitility;

@DolphinScheduler(composeFiles = "docker/basic/docker-compose.yaml")
@DisableIfTestFails
Expand Down Expand Up @@ -118,7 +118,7 @@ public static void setup() {
.create(project);

ProjectPage projectPage = new ProjectPage(browser);
Awaitility.await().untilAsserted(() -> assertThat(projectPage.projectList())
await().untilAsserted(() -> assertThat(projectPage.projectList())
.as("The project list should include newly created projects.")
.anyMatch(it -> it.getText().contains(project)));

Expand Down Expand Up @@ -171,6 +171,11 @@ private static void createJar(String classFile, String entryName, String mainPac

private static void getJar() {
compileJavaFlow();
await().atMost(Duration.ofMinutes(5))
.pollInterval(Duration.ofSeconds(5))
.until(() -> Files.exists(Paths.get("/tmp/common/Fat.class")) &&
Files.exists(Paths.get("/tmp/common/Normal1.class")) &&
Files.exists(Paths.get("/tmp/common/Normal2.class")));
createJar("Fat.class",
"common/Fat.class",
"common.Fat",
Expand Down Expand Up @@ -230,16 +235,11 @@ private static void compileJavaFlow() {
String workflowName = "compile";
String taskName = "compile";
String context =
"\n" +
"$JAVA_HOME/bin/javac -d /tmp Fat.java\n" +
"\n" +
"$JAVA_HOME/bin/javac -d /tmp Fat.java \n" +
"$JAVA_HOME/bin/javac -d /tmp Normal1.java Normal2.java \n" +
"\n" +
"$JAVA_HOME/bin/javac -d /tmp Normal2.java \n"; /*
* + "\n" + "ls \n" + "echo '%%%%%%%%%' \n" +
* "\n" + "ls /tmp \n" + "echo '%%%%%%%%%' \n" +
* "\n" + "ls /tmp/common \n";
*/
"$JAVA_HOME/bin/javac -d /tmp Normal2.java \n"
+ "echo '####当前目录 ####'\n" + "ls\n"
+ "echo '#### /tmp/common 目录 ####'\n" + "ls /tmp/common\n";
workflowDefinitionPage
.createWorkflow()
.<ShellTaskForm>addTask(WorkflowForm.TaskType.SHELL)
Expand All @@ -253,7 +253,7 @@ private static void compileJavaFlow() {
.name(workflowName)
.submit();

Awaitility.await().untilAsserted(() -> assertThat(workflowDefinitionPage.workflowList())
await().untilAsserted(() -> assertThat(workflowDefinitionPage.workflowList())
.as("Workflow list should contain newly-created workflow")
.anyMatch(it -> it.getText().contains(workflowName)));

Expand Down Expand Up @@ -286,6 +286,8 @@ void testCreateFatWorkflow() {

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='fat.jar']")));

file.delete("Fat.java").delete("Normal1.java").delete("Normal2.java");

ProjectPage projectPage = new NavBarPage(browser)
.goToNav(ProjectPage.class);

Expand All @@ -299,16 +301,16 @@ void testCreateFatWorkflow() {
workflow1.<JavaTaskForm>addTask(WorkflowForm.TaskType.JAVA)
.selectRunType("FAT_JAR")
.selectMainPackage("fat.jar")
.selectResource("fat.jar")
.selectResource("fat.jar")
.selectJavaResource("fat.jar")
.selectJavaResource("fat.jar")
.name("test-1")
.selectEnv(environmentName)
.submit()
.submit()
.name(workflow)
.submit();

Awaitility.await().untilAsserted(() -> assertThat(workflowDefinitionPage.workflowList())
await().untilAsserted(() -> assertThat(workflowDefinitionPage.workflowList())
.as("Workflow list should contain newly-created workflow")
.anyMatch(it -> it.getText().contains(workflow)));

Expand All @@ -331,7 +333,7 @@ void testRunFatWorkflow() {
.run(workflow)
.submit();

Awaitility.await()
await()
.atMost(Duration.ofMinutes(5))
.untilAsserted(() -> {
browser.navigate().refresh();
Expand Down Expand Up @@ -377,17 +379,17 @@ void testCreateNormalWorkflow() {
.<JavaTaskForm>addTask(WorkflowForm.TaskType.JAVA)
.selectRunType("NORMAL_JAR")
.selectMainPackage("normal1.jar")
.selectResource("normal1.jar")
.selectResource("normal1.jar")
.selectResource("normal2.jar")
.selectJavaResource("normal1.jar")
.selectJavaResource("normal1.jar")
.selectJavaResource("normal2.jar")
.name("test-2")
.selectEnv(environmentName)
.submit()
.submit()
.name(workflow2)
.submit();

Awaitility.await().untilAsserted(() -> assertThat(workflowDefinitionPage.workflowList())
await().untilAsserted(() -> assertThat(workflowDefinitionPage.workflowList())
.as("Workflow list should contain newly-created workflow")
.anyMatch(it -> it.getText().contains(workflow2)));

Expand All @@ -410,7 +412,7 @@ void testRunNormalWorkflow() {
.run(workflow2)
.submit();

Awaitility.await()
await()
.atMost(Duration.ofMinutes(5))
.untilAsserted(() -> {
browser.navigate().refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,24 @@ public JavaTaskForm(WorkflowForm parent) {
}

public JavaTaskForm selectJavaResource(String resourceName) {
((JavascriptExecutor) driver).executeScript("arguments[0].click();", selectResource);

final By optionsLocator = By.className("n-tree-node-content__text");

WebDriverWait wait = WebDriverWaitFactory.createWebDriverWait(driver());
wait.until(ExpectedConditions.elementToBeClickable(selectResource));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true); arguments[0].click();",
selectResource);
By optionsLocator = By.className("n-tree-node-content__text");
wait.until(ExpectedConditions.visibilityOfElementLocated(optionsLocator));

List<WebElement> options = driver.findElements(optionsLocator);
boolean found = false;
for (WebElement option : options) {
if (option.getText().trim().startsWith(resourceName)) {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true); arguments[0].click();",
option);
found = true;
break;
}
}

if (!found) {
throw new RuntimeException("Cannot Found: " + resourceName);
}
List<WebElement> elements = driver.findElements(optionsLocator);

WebElement targetElement = elements.stream()
.filter(it -> it.getText().trim().equals(resourceName))
.findFirst()
.orElseThrow(() -> new RuntimeException("No such package: " + resourceName));

targetElement.click();

driver.switchTo().activeElement().sendKeys(Keys.ESCAPE);

return this;
}

Expand Down

0 comments on commit 535815a

Please sign in to comment.