From 5cc858ff2cba4dc1e81ba3d941b8d52df12f32fd Mon Sep 17 00:00:00 2001 From: EvanYao826 <155432245+EvanYao826@users.noreply.github.com> Date: Wed, 27 May 2026 11:13:05 +0800 Subject: [PATCH] test(e2e): add dataset creation e2e test Add a new e2e test scenario for creating an empty dataset: - Create dataset feature file with Cucumber BDD syntax - Add step definitions for dataset creation flow - Update DifyWorld to track created dataset names Fixes #34278 Signed-off-by: EvanYao826 <155432245+EvanYao826@users.noreply.github.com> --- e2e/features/datasets/create-dataset.feature | 10 ++++++ .../datasets/create-dataset.steps.ts | 36 +++++++++++++++++++ e2e/features/support/world.ts | 2 ++ 3 files changed, 48 insertions(+) create mode 100644 e2e/features/datasets/create-dataset.feature create mode 100644 e2e/features/step-definitions/datasets/create-dataset.steps.ts diff --git a/e2e/features/datasets/create-dataset.feature b/e2e/features/datasets/create-dataset.feature new file mode 100644 index 00000000000000..3d39d6fea6f5ec --- /dev/null +++ b/e2e/features/datasets/create-dataset.feature @@ -0,0 +1,10 @@ +@datasets @authenticated @core +Feature: Create dataset + Scenario: Create a new empty dataset + Given I am signed in as the default E2E admin + When I open the datasets page + And I start creating a new dataset + And I select "Create an empty dataset" + And I enter a unique E2E dataset name + And I confirm dataset creation + Then I should land on the dataset document page diff --git a/e2e/features/step-definitions/datasets/create-dataset.steps.ts b/e2e/features/step-definitions/datasets/create-dataset.steps.ts new file mode 100644 index 00000000000000..dff9b93eb27dfe --- /dev/null +++ b/e2e/features/step-definitions/datasets/create-dataset.steps.ts @@ -0,0 +1,36 @@ +import type { DifyWorld } from '../../support/world' +import { Then, When } from '@cucumber/cucumber' +import { expect } from '@playwright/test' + +When('I open the datasets page', async function (this: DifyWorld) { + await this.getPage().goto('/datasets') +}) + +When('I start creating a new dataset', async function (this: DifyWorld) { + const page = this.getPage() + await expect(page.getByRole('button', { name: 'Create Dataset' })).toBeVisible() + await page.getByRole('button', { name: 'Create Dataset' }).click() +}) + +When('I select {string}', async function (this: DifyWorld, option: string) { + const page = this.getPage() + await expect(page.getByText(option)).toBeVisible() + await page.getByText(option).click() +}) + +When('I enter a unique E2E dataset name', async function (this: DifyWorld) { + const datasetName = `E2E Dataset ${Date.now()}` + this.lastCreatedDatasetName = datasetName + await this.getPage().getByPlaceholder('Dataset name').fill(datasetName) +}) + +When('I confirm dataset creation', async function (this: DifyWorld) { + const page = this.getPage() + const createButton = page.getByRole('button', { name: 'Create' }).last() + await expect(createButton).toBeEnabled() + await createButton.click() +}) + +Then('I should land on the dataset document page', async function (this: DifyWorld) { + await expect(this.getPage()).toHaveURL(/\/datasets\/[^/]+\/documents(?:\?.*)?$/) +}) diff --git a/e2e/features/support/world.ts b/e2e/features/support/world.ts index b53087171f52c5..9e6dbe2c23cf74 100644 --- a/e2e/features/support/world.ts +++ b/e2e/features/support/world.ts @@ -13,6 +13,7 @@ export class DifyWorld extends World { scenarioStartedAt: number | undefined session: AuthSessionMetadata | undefined lastCreatedAppName: string | undefined + lastCreatedDatasetName: string | undefined createdAppIds: string[] = [] capturedDownloads: Download[] = [] shareURL: string | undefined @@ -26,6 +27,7 @@ export class DifyWorld extends World { this.consoleErrors = [] this.pageErrors = [] this.lastCreatedAppName = undefined + this.lastCreatedDatasetName = undefined this.createdAppIds = [] this.capturedDownloads = [] this.shareURL = undefined