Skip to content

Commit

Permalink
Introduce variable management e2e test (#3835)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzk1 authored Jul 6, 2024
1 parent df8ca3a commit ad0a7aa
Show file tree
Hide file tree
Showing 5 changed files with 348 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,6 +80,17 @@ public <T extends NavBarItem> T goToNav(Class<T> nav) {
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");
}

Expand Down
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 {
}
}
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;
}
}

0 comments on commit ad0a7aa

Please sign in to comment.