-
Notifications
You must be signed in to change notification settings - Fork 2.6k
test(workspace):Automation script for Renaming and removing the Workspace #8356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c17dacd
0eb788a
7039255
f00746d
7ef9fbf
606cd06
067ffa6
de13061
e44fc35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { Page, test } from '../../../../playwright'; | ||
|
|
||
| import { buildTitleBarLocators } from '../title-bar'; | ||
|
|
||
| export const buildManageWorkspaceLocators = (page: Page) => ({ | ||
| myWorkspaceDropdownItem: () => page.locator('.dropdown-item'), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| manageWorkspaceTitle: () => page.getByText('Manage Workspace', { exact: true }), | ||
| defaultWorkspaceItem: () => page.locator('.workspace-item'), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not reliable. |
||
| moreActionsBtn: () => page.locator('.more-actions-btn'), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use datatest-id |
||
| workspaceListItem: () => page.locator('.dropdown-item'), | ||
| terminalSession: () => page.getByTestId('session-list-0'), | ||
| workspaceItem: () => page.locator('.workspace-item'), | ||
| dropdownItem: () => page.locator('.dropdown-item'), | ||
| modalCard: () => page.locator('.bruno-modal-card'), | ||
| workspaceFileNameInput: () => page.locator('#workspace-name'), | ||
| submitRenameBtn: () => page.getByTestId('modal-submit-btn'), | ||
| renamedWorkspaceItem: () => page.getByTestId('workspace-name'), | ||
| submitRemoveBtn: () => page.getByTestId('modal-submit-btn') | ||
|
Comment on lines
+16
to
+18
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }); | ||
|
|
||
| export const manageWorkspace = async (page: Page) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function name can be more specific like |
||
| const locators = buildManageWorkspaceLocators(page); | ||
| await test.step('Open manage workspaces', async () => { | ||
| await buildTitleBarLocators(page).workspaceMenuTrigger().click(); | ||
| await locators.myWorkspaceDropdownItem().filter({ hasText: 'Manage workspaces' }).click(); | ||
| }); | ||
| }; | ||
|
|
||
| export const openTerminalFromWorkspaceActions = async (page: Page, workspaceName: string) => { | ||
| const locators = buildManageWorkspaceLocators(page); | ||
| await test.step('Open terminal from workspace actions', async () => { | ||
| const workspaceItem = locators.defaultWorkspaceItem().filter({ hasText: workspaceName }); | ||
| await workspaceItem.locator(locators.moreActionsBtn()).click(); | ||
| await locators.workspaceListItem().filter({ hasText: 'Open in Terminal' }).click(); | ||
| }); | ||
| }; | ||
|
|
||
| export const clickOnMoreActionsButton = async (page: Page, workspaceName: string) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename it to |
||
| const locators = buildManageWorkspaceLocators(page); | ||
| await test.step('Click on the more actions button', async () => { | ||
| const workspaceItem = locators.workspaceItem().filter({ hasText: workspaceName }); | ||
| await workspaceItem.locator(locators.moreActionsBtn()).click(); | ||
| }); | ||
| }; | ||
|
|
||
| export const renameOrRemoveWorkspaceOnPopup = async (page: Page, optionName: string) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change it to |
||
| const locators = buildManageWorkspaceLocators(page); | ||
| await test.step('Rename or remove workspace on popup', async () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. step description is not accurate to action performed |
||
| await locators.dropdownItem().filter({ hasText: optionName }).click(); | ||
| await locators.modalCard().waitFor({ state: 'visible' }); | ||
| }); | ||
| }; | ||
|
|
||
| export const enterNewWorkspaceFilename = async (page: Page, workspaceName: string, btnName: string) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change the name to |
||
| const locators = buildManageWorkspaceLocators(page); | ||
| await test.step('Enter a new name for the workspace in the editing field.', async () => { | ||
| await locators.workspaceFileNameInput().fill(workspaceName); | ||
| await locators.submitRenameBtn().filter({ hasText: btnName }).click(); | ||
| }); | ||
| }; | ||
|
|
||
| export const clickOnRemoveButtonOnPopup = async (page: Page) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please rename it to |
||
| const locators = buildManageWorkspaceLocators(page); | ||
| await test.step('Verify the workspace name is updated in the workspace list.', async () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Step description is not accurate to action performed. Actions cannot have verify steps. |
||
| await locators.submitRemoveBtn().click(); | ||
| }); | ||
| }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All tests are passing when run in parallel with multiple workers. But when run using single worker ( |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,68 +1,55 @@ | ||
| import path from 'path'; | ||
| import fs from 'fs'; | ||
| import { test, expect, closeElectronApp } from '../../../playwright'; | ||
|
|
||
| const initUserDataPath = path.join(__dirname, '../create-workspace/init-user-data'); | ||
|
|
||
| function findCreatedWorkspaceDirs(location: string): string[] { | ||
| return fs.readdirSync(location).filter((e) => { | ||
| const fullPath = path.join(location, e); | ||
| return ( | ||
| fs.statSync(fullPath).isDirectory() | ||
| && e !== 'default-workspace' | ||
| && fs.existsSync(path.join(fullPath, 'workspace.yml')) | ||
| ); | ||
| import { test, expect } from '../../../playwright'; | ||
| import { createWorkspace } from '../../utils/page/actions'; | ||
| import { | ||
| clickOnMoreActionsButton, | ||
| manageWorkspace, | ||
| buildManageWorkspaceLocators, | ||
| openTerminalFromWorkspaceActions, | ||
| renameOrRemoveWorkspaceOnPopup, | ||
| enterNewWorkspaceFilename, | ||
| clickOnRemoveButtonOnPopup | ||
| } from '../../utils/page/workspace/manage-workspace'; | ||
|
|
||
| test.describe('Manage workspace', () => { | ||
| test.beforeEach(async ({ page }) => { | ||
| await test.step('Create a workspace', async () => { | ||
| await createWorkspace(page, 'Custom Workspace'); | ||
| }); | ||
|
|
||
| await test.step('Open manage workspaces', async () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repeated/Duplicate step. |
||
| const locators = buildManageWorkspaceLocators(page); | ||
| await manageWorkspace(page); | ||
| await expect(locators.manageWorkspaceTitle()).toBeVisible(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. beforeEach block cannot have test assertions. |
||
| }); | ||
| }); | ||
| } | ||
|
|
||
| test.describe('Manage Workspace', () => { | ||
| test('should open terminal from the workspace actions menu', async ({ launchElectronApp, createTmpDir }) => { | ||
| const wsLocation = await createTmpDir('ws-location-terminal'); | ||
|
|
||
| const app = await launchElectronApp({ initUserDataPath, templateVars: { wsLocation } }); | ||
| const page = await app.firstWindow(); | ||
|
|
||
| try { | ||
| await page.locator('[data-app-state="loaded"]').waitFor({ timeout: 30000 }); | ||
|
|
||
| await test.step('Create a workspace', async () => { | ||
| await page.locator('.workspace-name-container').click(); | ||
| await page.locator('.dropdown-item').filter({ hasText: 'Create workspace' }).click(); | ||
| const renameInput = page.locator('.workspace-name-input'); | ||
| await expect(renameInput).toBeVisible({ timeout: 5000 }); | ||
| await renameInput.fill('Terminal Workspace'); | ||
| await renameInput.press('Enter'); | ||
| await expect(page.getByText('Workspace created!')).toBeVisible({ timeout: 10000 }); | ||
| }); | ||
|
|
||
| const wsDirs = findCreatedWorkspaceDirs(wsLocation); | ||
| expect(wsDirs).toHaveLength(1); | ||
|
|
||
| await test.step('Open Manage Workspaces', async () => { | ||
| await page.locator('.workspace-name-container').click(); | ||
| await page.locator('.dropdown-item').filter({ hasText: 'Manage workspaces' }).click(); | ||
| await expect(page.getByText('Manage Workspace')).toBeVisible({ timeout: 5000 }); | ||
| }); | ||
|
|
||
| await test.step('Verify default workspace has no actions menu', async () => { | ||
| const defaultWorkspaceItem = page.locator('.workspace-item').filter({ hasText: 'My Workspace' }); | ||
| await expect(defaultWorkspaceItem.locator('.more-actions-btn')).toHaveCount(0); | ||
| }); | ||
| test.describe('Manage workspace actions-open in terminal', () => { | ||
| test('TC-3109: Verify that the workspace should open terminal from the workspace actions menu', { tag: '@sanity' }, async ({ page }) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Descriptions can be improved. |
||
| await openTerminalFromWorkspaceActions(page, 'Custom Workspace'); | ||
| const locators = buildManageWorkspaceLocators(page); | ||
| await expect(locators.terminalSession()).toBeVisible(); | ||
| await expect(locators.terminalSession()).toContainText('Custom Workspace'); | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Open terminal from workspace actions', async () => { | ||
| const workspaceItem = page.locator('.workspace-item').filter({ hasText: 'Terminal Workspace' }); | ||
| await expect(workspaceItem).toBeVisible({ timeout: 5000 }); | ||
| await workspaceItem.locator('.more-actions-btn').click(); | ||
| await page.locator('.dropdown-item').filter({ hasText: 'Open in Terminal' }).click(); | ||
| }); | ||
| test.describe('Manage workspace actions-rename workspace', () => { | ||
| test('TC-2612: Verify renaming a workspace from manage workspace section.', { tag: '@sanity' }, async ({ page }) => { | ||
| const locators = buildManageWorkspaceLocators(page); | ||
| await clickOnMoreActionsButton(page, 'Custom Workspace'); | ||
| await renameOrRemoveWorkspaceOnPopup(page, 'Rename'); | ||
| await enterNewWorkspaceFilename(page, 'New Workspace Name', 'Rename'); | ||
| await expect(locators.renamedWorkspaceItem()).toHaveText('New Workspace Name'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can rename non-active workspaces too. Fix accordingly. |
||
| await expect(locators.workspaceItem().filter({ hasText: 'New Workspace Name' })).toBeVisible(); | ||
| }); | ||
| }); | ||
|
|
||
| await test.step('Verify terminal session opens at the workspace folder', async () => { | ||
| const terminalSession = page.getByTestId('session-list-0'); | ||
| await expect(terminalSession).toBeVisible({ timeout: 5000 }); | ||
| await expect(terminalSession).toContainText(wsDirs[0]); | ||
| }); | ||
| } finally { | ||
| await closeElectronApp(app); | ||
| } | ||
| test.describe('Manage Workspace Actions - Remove Workspace', () => { | ||
| test('TC-2611: Verify removing a Workspace from manage workspace section', { tag: '@sanity' }, async ({ page }) => { | ||
| const locators = buildManageWorkspaceLocators(page); | ||
| await clickOnMoreActionsButton(page, 'Custom Workspace'); | ||
| await renameOrRemoveWorkspaceOnPopup(page, 'Remove'); | ||
| await clickOnRemoveButtonOnPopup(page); | ||
| await expect(locators.workspaceItem().filter({ hasText: 'Custom Workspace' })).not.toBeVisible({ timeout: 10000 }); | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
locaters structure and name can be improved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further minor enhancement
workspaceItems: (name?: string) => {terminalSession: (index: number = 0) => page.getByTestId(`session-list-${index}`)