This is an automated email from the ASF dual-hosted git repository.
benjobs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
The following commit(s) were added to refs/heads/dev by this push:
new ad0a7aaf9 Introduce variable management e2e test (#3835)
ad0a7aaf9 is described below
commit ad0a7aaf91268beabfa4d01317925d52b49315df
Author: Zhengke Zhou <[email protected]>
AuthorDate: Sat Jul 6 08:44:36 2024 +0800
Introduce variable management e2e test (#3835)
---
.github/workflows/e2e.yml | 2 +
.../e2e/cases/resource/VariableManagementTest.java | 124 +++++++++++++++++
.../streampark/e2e/pages/common/NavBarPage.java | 12 ++
.../e2e/pages/resource/ResourcePage.java | 57 ++++++++
.../e2e/pages/resource/VariableManagementPage.java | 153 +++++++++++++++++++++
5 files changed, 348 insertions(+)
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index a70adbbee..853f431b5 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -105,6 +105,8 @@ jobs:
strategy:
matrix:
case:
+ - name: VariableManagementTest
+ class:
org.apache.streampark.e2e.pages.resource.VariableManagementTest
- name: RoleManagementTest
class: org.apache.streampark.e2e.cases.RoleManagementTest
- name: UserManagementTest
diff --git
a/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/cases/resource/VariableManagementTest.java
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/cases/resource/VariableManagementTest.java
new file mode 100644
index 000000000..c3a596cc8
--- /dev/null
+++
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/cases/resource/VariableManagementTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.streampark.e2e.cases.resource;
+
+import org.apache.streampark.e2e.core.StreamPark;
+import org.apache.streampark.e2e.pages.LoginPage;
+import org.apache.streampark.e2e.pages.resource.ResourcePage;
+import org.apache.streampark.e2e.pages.resource.VariableManagementPage;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.remote.RemoteWebDriver;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+;import static org.assertj.core.api.Assertions.assertThat;
+
+@StreamPark(composeFiles = "docker/basic/docker-compose.yaml")
+public class VariableManagementTest {
+
+ private static RemoteWebDriver browser;
+
+ private static final String userName = "admin";
+
+ private static final String password = "streampark";
+
+ private static final String teamName = "default";
+
+ private static final String variableCode = "10000";
+
+ private static final String variableValue = "3306";
+
+ private static final String description = "MySQL default port";
+
+ private static final boolean isNotVisible = true;
+
+ @BeforeAll
+ public static void setup() {
+ new LoginPage(browser)
+ .login(userName, password, teamName)
+ .goToNav(ResourcePage.class)
+ .goToTab(VariableManagementPage.class);
+ }
+
+ @Test
+ @Order(10)
+ void testCreateVariable() {
+ final VariableManagementPage variableManagementPage = new
VariableManagementPage(browser);
+ variableManagementPage.createVariable(variableCode, variableValue,
description, isNotVisible);
+
+ Awaitility.await()
+ .untilAsserted(
+ () -> assertThat(variableManagementPage.variableList())
+ .as("Variable list should contain newly-created variable")
+ .extracting(WebElement::getText)
+ .anyMatch(it -> it.contains(variableCode)));
+ }
+
+ @Test
+ @Order(20)
+ void testCreateDuplicateVariable() {
+ final VariableManagementPage variableManagementPage = new
VariableManagementPage(browser);
+ variableManagementPage.createVariable(variableCode, variableValue,
description, isNotVisible);
+
+ Awaitility.await()
+ .untilAsserted(
+ () -> assertThat(variableManagementPage.errorMessageList())
+ .as("Variable Code Duplicated Error message should be
displayed")
+ .extracting(WebElement::getText)
+ .anyMatch(it -> it.contains("The variable code already
exists.")));
+
+ variableManagementPage.errorMessageConfirmButton().click();
+ variableManagementPage.createVariableForm().buttonCancel().click();
+ }
+
+ @Test
+ @Order(30)
+ void testEditVariable() {
+ final VariableManagementPage variableManagementPage = new
VariableManagementPage(browser);
+ String editVariableValue = "6379";
+ String editDescription = "Redis default port";
+
+ variableManagementPage.editVariable(variableCode, editVariableValue,
editDescription, isNotVisible);
+ Awaitility.await()
+ .untilAsserted(
+ () -> assertThat(variableManagementPage.variableList())
+ .as("Variable list should contain edited variable")
+ .extracting(WebElement::getText)
+ .anyMatch(it -> it.contains(editVariableValue))
+ .anyMatch(it -> it.contains(editDescription)));
+ }
+
+ @Test
+ @Order(40)
+ void testDeleteTeam() {
+ final VariableManagementPage variableManagementPage = new
VariableManagementPage(browser);
+
+ variableManagementPage.deleteVariable(variableCode);
+
+ Awaitility.await()
+ .untilAsserted(
+ () -> assertThat(variableManagementPage.variableList())
+ .extracting(WebElement::getText)
+ .noneMatch(it -> it.contains(variableCode))
+ );
+ }
+}
diff --git
a/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/common/NavBarPage.java
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/common/NavBarPage.java
index 6ba975e14..919a5485e 100644
---
a/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/common/NavBarPage.java
+++
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/common/NavBarPage.java
@@ -21,6 +21,7 @@
package org.apache.streampark.e2e.pages.common;
import org.apache.streampark.e2e.pages.flink.ApacheFlinkPage;
+import org.apache.streampark.e2e.pages.resource.ResourcePage;
import org.apache.streampark.e2e.pages.system.SystemPage;
import lombok.Getter;
@@ -79,6 +80,17 @@ public class NavBarPage {
return nav.cast(new SystemPage(driver));
}
+ if (nav == ResourcePage.class) {
+ new WebDriverWait(driver, Duration.ofSeconds(10))
+
.until(ExpectedConditions.elementToBeClickable(resourcesTab));
+ String tabOpenStateXpath =
+ "//span[contains(@class, 'ml-2') and contains(@class,
'streampark-simple-menu-sub-title') and contains(text(),
'Resource')]/../parent::li[contains(@class, 'streampark-menu-opened')]";
+ if (driver.findElements(By.xpath(tabOpenStateXpath)).isEmpty()) {
+ resourcesTab.click();
+ }
+ return nav.cast(new ResourcePage(driver));
+ }
+
throw new UnsupportedOperationException("Unknown nav bar");
}
diff --git
a/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/resource/ResourcePage.java
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/resource/ResourcePage.java
new file mode 100644
index 000000000..0472863c2
--- /dev/null
+++
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/resource/ResourcePage.java
@@ -0,0 +1,57 @@
+/*
+ * 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.streampark.e2e.pages.resource;
+
+import org.apache.streampark.e2e.pages.common.NavBarPage;
+import org.apache.streampark.e2e.pages.common.NavBarPage.NavBarItem;
+
+import lombok.Getter;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.remote.RemoteWebDriver;
+import org.openqa.selenium.support.FindBy;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+import java.time.Duration;
+
+@Getter
+public final class ResourcePage extends NavBarPage implements NavBarItem {
+
+ @FindBy(xpath = "//span[contains(@class,
'streampark-simple-menu-sub-title') and contains(text(), 'Variables')]//..")
+ private WebElement resourceVariableManagement;
+
+ public ResourcePage(RemoteWebDriver driver) {
+ super(driver);
+ }
+
+ public <T extends ResourcePage.Tab> T goToTab(Class<T> tab) {
+ if (tab == VariableManagementPage.class) {
+ new WebDriverWait(driver, Duration.ofSeconds(10))
+
.until(ExpectedConditions.elementToBeClickable(resourceVariableManagement));
+ resourceVariableManagement.click();
+ return tab.cast(new VariableManagementPage(driver));
+ }
+
+ throw new UnsupportedOperationException("Unknown tab: " +
tab.getName());
+ }
+
+ public interface Tab {
+ }
+}
diff --git
a/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/resource/VariableManagementPage.java
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/resource/VariableManagementPage.java
new file mode 100644
index 000000000..66edb588e
--- /dev/null
+++
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/resource/VariableManagementPage.java
@@ -0,0 +1,153 @@
+/*
+ * 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.streampark.e2e.pages.resource;
+
+import org.apache.streampark.e2e.pages.common.NavBarPage;
+
+import lombok.Getter;
+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.PageFactory;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+import java.time.Duration;
+import java.util.List;
+
+@Getter
+public class VariableManagementPage extends NavBarPage implements
ResourcePage.Tab {
+
+ @FindBy(xpath = "//span[contains(., 'Variable
List')]/..//button[contains(@class, 'ant-btn-primary')]/span[contains(text(),
'Add New')]")
+ private WebElement buttonCreateVariable;
+
+ @FindBy(xpath = "//tbody[contains(@class, 'ant-table-tbody')]")
+ private List<WebElement> variableList;
+
+ @FindBy(className = "swal2-html-container")
+ private List<WebElement> errorMessageList;
+
+ @FindBy(xpath = "//button[contains(text(), 'OK')]")
+ private WebElement errorMessageConfirmButton;
+
+ @FindBy(xpath = "//button[contains(@class, 'ant-btn')]/span[contains(.,
'OK')]")
+ private WebElement deleteConfirmButton;
+
+ private final CreateVariableForm createVariableForm = new
CreateVariableForm();
+
+ public VariableManagementPage(RemoteWebDriver driver) {
+ super(driver);
+ }
+
+ public VariableManagementPage createVariable(String variableCode, String
variableValue, String description,
+ boolean notVisible) {
+ waitForPageLoading();
+
+ new WebDriverWait(driver, Duration.ofSeconds(10))
+
.until(ExpectedConditions.elementToBeClickable(buttonCreateVariable));
+ buttonCreateVariable.click();
+ createVariableForm.inputVariableCode().sendKeys(variableCode);
+ createVariableForm.inputVariableValue().sendKeys(variableValue);
+ createVariableForm.inputDescription().sendKeys(description);
+ if (notVisible) {
+ createVariableForm.buttonDesensitization.click();
+ }
+
+ createVariableForm.buttonSubmit().click();
+ return this;
+ }
+
+ public VariableManagementPage editVariable(String variableCode, String
variableValue, String description,
+ boolean notVisible) {
+ waitForPageLoading();
+
+ variableList().stream()
+ .filter(it -> it.getText().contains(variableCode))
+ .flatMap(
+ it ->
it.findElements(By.xpath("//button[contains(@tooltip,'Modify
Variable')]")).stream())
+ .filter(WebElement::isDisplayed)
+ .findFirst()
+ .orElseThrow(() -> new RuntimeException("No edit button in
variable list"))
+ .click();
+
+ new WebDriverWait(driver, Duration.ofSeconds(10))
+
.until(ExpectedConditions.elementToBeClickable(createVariableForm.buttonSubmit));
+ createVariableForm.inputVariableValue().sendKeys(variableValue);
+ createVariableForm.inputDescription().clear();
+ createVariableForm.inputDescription().sendKeys(description);
+ if (notVisible) {
+ createVariableForm.buttonDesensitization.click();
+ }
+ createVariableForm.buttonSubmit().click();
+
+ return this;
+ }
+
+ public VariableManagementPage deleteVariable(String variableCode) {
+ waitForPageLoading();
+
+ variableList().stream()
+ .filter(it -> it.getText().contains(variableCode))
+ .flatMap(
+ it ->
it.findElements(By.xpath("//button[contains(@tooltip,'Delete
Variable')]")).stream())
+ .filter(WebElement::isDisplayed)
+ .findFirst()
+ .orElseThrow(() -> new RuntimeException("No delete button in
variable list"))
+ .click();
+
+ new WebDriverWait(driver, Duration.ofSeconds(10))
+
.until(ExpectedConditions.elementToBeClickable(deleteConfirmButton));
+
+ deleteConfirmButton.click();
+ return this;
+ }
+
+ private void waitForPageLoading() {
+ new WebDriverWait(driver, Duration.ofSeconds(10))
+ .until(ExpectedConditions.urlContains("/resource/variable"));
+ }
+
+ @Getter
+ public class CreateVariableForm {
+
+ CreateVariableForm() {
+ PageFactory.initElements(driver, this);
+ }
+
+ @FindBy(id = "VariableForm_variableCode")
+ private WebElement inputVariableCode;
+
+ @FindBy(id = "VariableForm_variableValue")
+ private WebElement inputVariableValue;
+
+ @FindBy(id = "VariableForm_description")
+ private WebElement inputDescription;
+
+ @FindBy(id = "VariableForm_desensitization")
+ private WebElement buttonDesensitization;
+
+ @FindBy(xpath = "//button[contains(@class,
'ant-btn')]//span[contains(., 'Submit')]")
+ private WebElement buttonSubmit;
+
+ @FindBy(xpath = "//button[contains(@class,
'ant-btn')]//span[contains(., 'Cancel')]")
+ private WebElement buttonCancel;
+ }
+}