-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce variable management e2e test (#3835)
- Loading branch information
Showing
5 changed files
with
348 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...e-case/src/test/java/org/apache/streampark/e2e/cases/resource/VariableManagementTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...eampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/resource/ResourcePage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
} | ||
} |
153 changes: 153 additions & 0 deletions
153
...e-case/src/test/java/org/apache/streampark/e2e/pages/resource/VariableManagementPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |