Skip to content

Commit

Permalink
[Improve] project-page e2e flindElement improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfboys committed Sep 23, 2024
1 parent c8083cc commit 408c1ef
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@
>
<template #formFooter>
<div class="flex items-center w-full justify-center">
<a-button @click="router.go(-1)">
<a-button id="e2e-project-cancel-btn" @click="router.go(-1)">
{{ t('common.cancelText') }}
</a-button>
<a-button class="ml-4" :loading="getLoading" type="primary" @click="submit()">
<a-button
id="e2e-project-submit-btn"
class="ml-4"
:loading="getLoading"
type="primary"
@click="submit()"
>
{{ t('common.submitText') }}
</a-button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,38 @@
onClick: handleViewLog.bind(null, record),
},
{
class: 'e2e-project-build-btn',
icon: 'ant-design:thunderbolt-outlined',
auth: 'project:build',
ifShow: record.buildState !== BuildStateEnum.BUILDING,
popConfirm: {
okButtonProps: {
class: 'e2e-project-build-confirm',
},
title: t('flink.project.operationTips.buildProjectMessage'),
placement: 'left',
confirm: handleBuild.bind(null, record),
},
},
{
class: 'e2e-project-edit-btn',
icon: 'clarity:note-edit-line',
ifShow: record.buildState !== BuildStateEnum.BUILDING,
auth: 'project:update',
tooltip: t('common.edit'),
onClick: handleEdit.bind(null, record),
},
{
class: 'e2e-project-delete-btn',
icon: 'ant-design:delete-outlined',
color: 'error',
tooltip: t('common.delText'),
ifShow: record.buildState !== BuildStateEnum.BUILDING,
auth: 'project:delete',
popConfirm: {
okButtonProps: {
class: 'e2e-project-delete-confirm',
},
title: t('flink.project.operationTips.deleteProjectMessage'),
placement: 'left',
confirm: handleDelete.bind(null, record),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public class ProjectsManagementTest {

private static final String editedProjectName = "e2e_test_project_edited";

private static final String cvs = "GitHub/GitLab";

private static final String url = "https://github.com/apache/incubator-streampark-quickstart";

private static final String branch = "dev";
Expand All @@ -56,7 +54,7 @@ public class ProjectsManagementTest {

@BeforeAll
public static void setup() {
ProjectsPage projectsPage = new LoginPage(browser)
new LoginPage(browser)
.login()
.goToNav(ResourcePage.class)
.goToTab(ProjectsPage.class);
Expand All @@ -67,7 +65,7 @@ public static void setup() {
void testCreateProject() {
final ProjectsPage projectsPage = new ProjectsPage(browser);

projectsPage.createProject(projectName, cvs, url, branch, buildArgument, description);
projectsPage.createProject(projectName, url, branch, buildArgument, description);

await()
.untilAsserted(
Expand All @@ -82,7 +80,7 @@ void testCreateProject() {
void testEditProject() {
final ProjectsPage projectsPage = new ProjectsPage(browser);

projectsPage.editProject(projectName, editedProjectName, cvs, url, branch, buildArgument, description);
projectsPage.editProject(projectName, editedProjectName);

await()
.untilAsserted(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ public class ProjectsPage extends NavBarPage implements ResourcePage.Tab {
@FindBy(id = "e2e-project-create-btn")
public WebElement buttonCreateProject;

@FindBy(xpath = "//div[contains(@class, 'ant-list')]")
@FindBy(className = "ant-table-tbody")
public List<WebElement> projectList;

@FindBy(xpath = "//button[contains(@class, 'ant-btn')]/span[contains(., 'OK')]")
public WebElement popupConfirmButton;
@FindBy(className = "e2e-project-build-btn")
public WebElement buildButton;

@FindBy(className = "e2e-project-delete-confirm")
public WebElement deleteConfirmButton;

@FindBy(className = "e2e-project-build-confirm")
public WebElement buildConfirmButton;

public CreateProjectForm createProjectForm;

Expand All @@ -55,9 +61,8 @@ public ProjectsPage(RemoteWebDriver driver) {

@SneakyThrows
public ProjectsPage createProject(String projectName,
String projectCvs,
String projectUrl,
String projectBranch,
String projectRefs,
String projectBuildArgument,
String projectDescription) {
waitForPageLoading();
Expand All @@ -70,21 +75,27 @@ public ProjectsPage createProject(String projectName,
.until(ExpectedConditions.urlContains("/project/add"));

createProjectForm.inputProjectName.sendKeys(projectName);

createProjectForm.selectCveDropdown.click();
createProjectForm.selectCveText.stream()
.filter(e -> e.getText().equalsIgnoreCase(projectCvs))

new WebDriverWait(driver, Constants.DEFAULT_WEBDRIVER_WAIT_DURATION)
.until(ExpectedConditions.visibilityOfAllElements(createProjectForm.selectCve));

createProjectForm.selectCve.stream()
.filter(e -> e.getText().equalsIgnoreCase("GitHub/GitLab"))
.findFirst()
.orElseThrow(() -> new Exception(String.format("Cvs not found: %s", projectCvs)))
.orElseThrow(() -> new Exception("Cvs not found"))
.click();

createProjectForm.inputProjectUrl.sendKeys(projectUrl);
createProjectForm.selectBranchDropdown.click();

new WebDriverWait(driver, Constants.DEFAULT_WEBDRIVER_WAIT_DURATION)
.until(ExpectedConditions.visibilityOfAllElements(createProjectForm.selectBranchText));
createProjectForm.selectBranchText.stream()
.filter(e -> e.getText().equalsIgnoreCase(projectBranch))
.until(ExpectedConditions.visibilityOfAllElements(createProjectForm.selectRefs));
createProjectForm.selectRefs.stream()
.filter(e -> e.getText().equalsIgnoreCase(projectRefs))
.findFirst()
.orElseThrow(() -> new Exception(String.format("Branch not found: %s", projectBranch)))
.orElseThrow(() -> new Exception(String.format("Branch not found: %s", projectRefs)))
.click();

createProjectForm.inputBuildArgument.sendKeys(projectBuildArgument);
Expand All @@ -95,54 +106,27 @@ public ProjectsPage createProject(String projectName,
}

@SneakyThrows
public ProjectsPage editProject(String oldProjectName,
String newProjectName,
String projectCvs,
String projectUrl,
String projectBranch,
String projectBuildArgument,
String projectDescription) {
public ProjectsPage editProject(String projectName,
String newProjectName) {
waitForPageLoading();

projectList.stream()
.filter(project -> project.getText().contains(oldProjectName))
.filter(it -> it.getText().contains(projectName))
.flatMap(
it -> it.findElements(
By.className("e2e-project-edit-btn"))
.stream())
.filter(WebElement::isDisplayed)
.findFirst()
.orElseThrow(() -> new Exception("Project edit button not found"))
.findElement(
By.xpath("//..//li[contains(@class, 'ant-list-item')]//button[contains(@class, 'ant-btn')][3]"))
.orElseThrow(() -> new RuntimeException("No edit button in project list"))
.click();

new WebDriverWait(driver, Constants.DEFAULT_WEBDRIVER_WAIT_DURATION)
.until(ExpectedConditions.urlContains("/project/edit"));

createProjectForm.inputProjectName.sendKeys(Keys.CONTROL + "a");
createProjectForm.inputProjectName.sendKeys(Keys.BACK_SPACE);
createProjectForm.inputProjectName.sendKeys(newProjectName);
createProjectForm.selectCveDropdown.click();
new WebDriverWait(driver, Constants.DEFAULT_WEBDRIVER_WAIT_DURATION)
.until(ExpectedConditions.visibilityOfAllElements(createProjectForm.selectCveText));
createProjectForm.selectCveText.stream()
.filter(e -> e.getText().equalsIgnoreCase(projectCvs))
.findFirst()
.orElseThrow(() -> new Exception(String.format("Cvs not found: %s", projectCvs)))
.click();

createProjectForm.inputProjectUrl.sendKeys(Keys.CONTROL + "a");
createProjectForm.inputProjectUrl.sendKeys(Keys.BACK_SPACE);
createProjectForm.inputProjectUrl.sendKeys(projectUrl);
createProjectForm.selectBranchDropdown.click();
new WebDriverWait(driver, Constants.DEFAULT_WEBDRIVER_WAIT_DURATION)
.until(ExpectedConditions.visibilityOfAllElements(createProjectForm.selectBranchText));
createProjectForm.selectBranchText.stream()
.filter(e -> e.getText().equalsIgnoreCase(projectBranch))
.findFirst()
.orElseThrow(() -> new Exception(String.format("Branch not found: %s", projectBranch)))
.click();

createProjectForm.inputBuildArgument.sendKeys(Keys.CONTROL + "a");
createProjectForm.inputBuildArgument.sendKeys(Keys.BACK_SPACE);
createProjectForm.inputBuildArgument.sendKeys(projectBuildArgument);
createProjectForm.inputDescription.sendKeys(Keys.CONTROL + "a");
createProjectForm.inputDescription.sendKeys(Keys.BACK_SPACE);
createProjectForm.inputDescription.sendKeys(projectDescription);
createProjectForm.buttonSubmit.click();

return this;
Expand All @@ -151,41 +135,41 @@ public ProjectsPage editProject(String oldProjectName,
@SneakyThrows
public ProjectsPage buildProject(String projectName) {
waitForPageLoading();

projectList.stream()
.filter(project -> project.getText().contains(projectName))
.filter(it -> it.getText().contains(projectName))
.flatMap(
it -> it.findElements(By.className("e2e-project-build-btn")).stream())
.filter(WebElement::isDisplayed)
.findFirst()
.orElseThrow(() -> new Exception("Project build button not found"))
.findElement(
By.xpath("//..//li[contains(@class, 'ant-list-item')]//button[contains(@class, 'ant-btn')][2]"))
.orElseThrow(() -> new RuntimeException("No build button in project list"))
.click();
popupConfirmButton.click();

new WebDriverWait(driver, Constants.DEFAULT_WEBDRIVER_WAIT_DURATION)
.until(ExpectedConditions.elementToBeClickable(deleteConfirmButton));

buildConfirmButton.click();

return this;
}

@SneakyThrows
public ProjectsPage deleteProject(String projectName) {
waitForPageLoading();

projectList.stream()
.filter(project -> project.getText().contains(projectName))
.filter(it -> it.getText().contains(projectName))
.flatMap(
it -> it.findElements(By.className("e2e-project-delete-btn")).stream())
.filter(WebElement::isDisplayed)
.findFirst()
.orElseThrow(() -> new Exception("Project delete button not found"))
.findElement(
By.xpath("//..//li[contains(@class, 'ant-list-item')]//button[contains(@class, 'ant-btn')][4]"))
.orElseThrow(() -> new RuntimeException("No delete button in project list"))
.click();
popupConfirmButton.click();
String deletePopUpMessage = "delete successful";
new WebDriverWait(driver, Constants.DEFAULT_WEBDRIVER_WAIT_DURATION)
.until(
ExpectedConditions.visibilityOfElementLocated(
By.xpath(String.format("//*[contains(text(),'%s')]",
deletePopUpMessage))));

new WebDriverWait(driver, Constants.DEFAULT_WEBDRIVER_WAIT_DURATION)
.until(
ExpectedConditions.invisibilityOfElementLocated(
By.xpath(String.format("//*[contains(text(),'%s')]",
deletePopUpMessage))));
Thread.sleep(Constants.DEFAULT_SLEEP_MILLISECONDS);
.until(ExpectedConditions.elementToBeClickable(deleteConfirmButton));

deleteConfirmButton.click();

return this;
}
Expand All @@ -212,30 +196,27 @@ private class CreateProjectForm {
@FindBy(css = "[codefield=repository]"),
@FindBy(className = "ant-select-item-option-content")
})
public List<WebElement> selectCveText;
public List<WebElement> selectCve;

@FindBy(name = "url")
public WebElement inputProjectUrl;

@FindBy(xpath = "//div[contains(@codefield, 'branches')]//div[contains(@class, 'ant-select-selector')]")
@FindBy(xpath = "//div[contains(@codefield, 'refs')]//div[contains(@class, 'ant-select-selector')]")
public WebElement selectBranchDropdown;

@FindBys({
@FindBy(css = "[codefield=branches]"),
@FindBy(css = "[codefield=refs]"),
@FindBy(className = "ant-select-item-option-content")
})
public List<WebElement> selectBranchText;
public List<WebElement> selectRefs;

@FindBy(id = "form_item_buildArgs")
public WebElement inputBuildArgument;

@FindBy(id = "form_item_description")
public WebElement inputDescription;

@FindBy(xpath = "//button[contains(@class, 'ant-btn')]//span[contains(text(), 'Submit')]")
@FindBy(id = "e2e-project-submit-btn")
public WebElement buttonSubmit;

@FindBy(xpath = "//button[contains(@class, 'ant-btn')]//span[contains(text(), 'Cancel')]")
public WebElement buttonCancel;
}
}

0 comments on commit 408c1ef

Please sign in to comment.