-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement playwright tests for Web IDE
- Loading branch information
Showing
18 changed files
with
902 additions
and
1 deletion.
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
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,27 @@ | ||
name: Web IDE Browser Tests | ||
on: | ||
push: | ||
branches: ['**'] | ||
pull_request: | ||
branches: ['**'] | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: npx playwright test | ||
- uses: actions/upload-artifact@v4 | ||
if: ${{ !cancelled() }} | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
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
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
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,79 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// import dotenv from 'dotenv'; | ||
// import path from 'path'; | ||
// dotenv.config({ path: path.resolve(__dirname, '.env') }); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './tests', | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'html', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://127.0.0.1:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
|
||
{ | ||
name: 'webkit', | ||
use: { ...devices['Desktop Safari'] }, | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'npm run start', | ||
// url: 'http://127.0.0.1:3000', | ||
// reuseExistingServer: !process.env.CI, | ||
// }, | ||
}); |
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,27 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { randomUUID } from 'crypto'; | ||
import { DELETE_PROJECT_LOCATOR } from 'tests/locators'; | ||
import { createProject, ProjectType } from 'tests/utils'; | ||
|
||
test('Create Blank Contract in Web IDE then delete', async ({ page }) => { | ||
// Open Web IDE | ||
await page.goto('https://ide.ton.org/'); | ||
const projectName = randomUUID(); | ||
// Create project | ||
await createProject(page, projectName, ProjectType.BlankContract); | ||
|
||
// Delete project | ||
await expect(page.locator(DELETE_PROJECT_LOCATOR)).toBeVisible(); | ||
await page.locator(DELETE_PROJECT_LOCATOR).first().click(); | ||
|
||
await expect( | ||
page.getByText(`Delete my \`${projectName}\` Project?`), | ||
).toBeVisible(); | ||
await expect(page.getByRole('button', { name: 'Cancel' })).toBeVisible(); | ||
await expect(page.getByRole('button', { name: 'Delete' })).toBeVisible(); | ||
await page.getByRole('button', { name: 'Delete' }).click(); | ||
// Check that project is deleted | ||
await expect( | ||
page.getByRole('button', { name: 'Create a new project' }), | ||
).toBeVisible(); | ||
}); |
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,52 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { randomUUID } from 'crypto'; | ||
import { XTERM_LOGS_LOCATOR } from 'tests/locators'; | ||
import { | ||
getElementContent, | ||
isCodeEditorLoaded, | ||
logsContain, | ||
openBuildAndDeployTab, | ||
} from 'tests/utils'; | ||
|
||
test('Create Blank Contract in Web IDE then build', async ({ page }) => { | ||
// Open Web IDE | ||
await page.goto('https://ide.ton.org/'); | ||
await expect( | ||
page.getByRole('button', { name: 'Create a new project' }), | ||
).toBeVisible(); | ||
// Create new project | ||
await page.getByRole('button', { name: 'Create a new project' }).click(); | ||
|
||
// Select Blank Contract | ||
const projectName = randomUUID(); | ||
await page.getByRole('textbox', { name: 'Project name' }).click(); | ||
await page.getByRole('textbox', { name: 'Project name' }).fill(projectName); | ||
|
||
await expect(page.getByText('TactFunc')).toBeVisible(); | ||
await expect(page.getByText('Blank ContractCounter Contract')).toBeVisible(); | ||
await expect( | ||
page.getByRole('button', { name: 'Create', exact: true }), | ||
).toBeVisible(); | ||
|
||
await page.getByText('Blank Contract').click(); | ||
await page.getByRole('button', { name: 'Create', exact: true }).click(); | ||
|
||
await isCodeEditorLoaded(page); | ||
await openBuildAndDeployTab(page); | ||
|
||
const getLogs = () => getElementContent(page, XTERM_LOGS_LOCATOR); | ||
await logsContain(await getLogs(), [`Project '${projectName}' is opened`]); | ||
|
||
// Build contract | ||
await expect(page.getByRole('button', { name: 'Build' })).toBeVisible(); | ||
await page.getByRole('button', { name: 'Build' }).click(); | ||
await page.waitForTimeout(2000); | ||
|
||
// Check build logs | ||
await logsContain(await getLogs(), [ | ||
/Message sent: Deploy, from [A-Za-z0-9._-]{1,10}, to [A-Za-z0-9._-]{1,10}, value 0\.05, not bounced/, | ||
/Transaction Executed: success, Exit Code: 0, Gas: 0.0028824/, | ||
/Message sent: DeployOk, from [A-Za-z0-9._-]{1,10}, to [A-Za-z0-9._-]{1,10}, value 0.0466392/, | ||
/Transaction Executed: success, Exit Code: 0, Gas: 0.0001236/, | ||
]); | ||
}); |
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,32 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { randomUUID } from 'crypto'; | ||
import { XTERM_LOGS_LOCATOR } from 'tests/locators'; | ||
import { | ||
createProject, | ||
getElementContent, | ||
isCodeEditorLoaded, | ||
logsContain, | ||
openBuildAndDeployTab, | ||
ProjectType, | ||
} from 'tests/utils'; | ||
|
||
test('Create Counter Contract in Web IDE then build', async ({ page }) => { | ||
// Open Web IDE | ||
await page.goto('https://ide.ton.org/'); | ||
const projectName = randomUUID(); | ||
// Create project | ||
await createProject(page, projectName, ProjectType.CounterContract); | ||
|
||
await isCodeEditorLoaded(page); | ||
await openBuildAndDeployTab(page); | ||
|
||
const getLogs = () => getElementContent(page, XTERM_LOGS_LOCATOR); | ||
await logsContain(await getLogs(), [`Project '${projectName}' is opened`]); | ||
|
||
// Build contract | ||
await expect(page.getByRole('button', { name: 'Build' })).toBeVisible(); | ||
await page.getByRole('button', { name: 'Build' }).click(); | ||
await page.waitForTimeout(2000); | ||
// Check build logs | ||
await logsContain(await getLogs(), [/Built Successfully/]); | ||
}); |
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,28 @@ | ||
export const EDITOR_CONTAINER_LOCATOR = | ||
"//div[contains(@class, 'Editor_container_')]"; | ||
|
||
export const CLONE_PROJECT_LOCATOR = | ||
"//div[contains(@class, 'CloneProject_root')]"; | ||
|
||
export const MONACO_LINES_LOCATOR = | ||
"//div[contains(@class, 'view-lines monaco-mouse-cursor-text')]"; | ||
|
||
export const XTERM_LOGS_LOCATOR = "//div[contains(@class, 'xterm-rows')]"; | ||
|
||
export const CODE_TAB_LOCATOR = | ||
'//div[contains(@class, "WorkspaceSidebar_action_")][1]'; | ||
|
||
export const BUILD_AND_DEPLOY_LOCATOR = | ||
'//div[contains(@class, "WorkspaceSidebar_action_")][2]'; | ||
|
||
export const UNIT_TESTS_LOCATOR = | ||
'//div[contains(@class, "WorkspaceSidebar_action_")][3]'; | ||
|
||
export const GIT_TAB_LOCATOR = | ||
'//div[contains(@class, "WorkspaceSidebar_action_")][4]'; | ||
|
||
export const DELETE_PROJECT_LOCATOR = | ||
'//div[contains(@class, "ManageProject_deleteProject")]'; | ||
|
||
export const PROJECT_DROPDOWN_LOCATOR = | ||
'(//span[contains(@class, "ant-select-selection-item") and @title])[1]'; |
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,53 @@ | ||
import { encodeBase64 } from '@/utility/utils'; | ||
import { expect, test } from '@playwright/test'; | ||
import { randomUUID } from 'crypto'; | ||
import { CLONE_PROJECT_LOCATOR, MONACO_LINES_LOCATOR } from 'tests/locators'; | ||
import { | ||
getActiveProject, | ||
getActiveProjectLocator, | ||
getElementContent, | ||
isCodeEditorLoaded, | ||
normalizeString, | ||
} from 'tests/utils'; | ||
|
||
test('Clone code from shared link to local', async ({ page, context }) => { | ||
// Grant clipboard permissions to browser context | ||
await context.grantPermissions(['clipboard-read', 'clipboard-write']); | ||
|
||
// Generate share code | ||
const shareCode = `contract ${randomUUID()} with Deployable {\n\n\n}`; | ||
const url = `https://ide.ton.org/?code=${encodeBase64(shareCode)}&lang=tact`; | ||
const projectName = randomUUID(); | ||
|
||
// Open page with share code | ||
await page.goto(url); | ||
await isCodeEditorLoaded(page); | ||
const ideCodeBefore = await getElementContent(page, MONACO_LINES_LOCATOR); | ||
|
||
// Validate that project name is "temp" is active | ||
await expect(await getActiveProject(page)).toBe('temp'); | ||
await expect(normalizeString(ideCodeBefore)).toBe(normalizeString(shareCode)); | ||
await page.locator(CLONE_PROJECT_LOCATOR).click(); | ||
|
||
await expect( | ||
page.getByRole('textbox', { name: 'Project name' }), | ||
).toBeVisible(); | ||
await expect(page.getByRole('button', { name: 'Save' })).toBeVisible(); | ||
await page.getByRole('textbox', { name: 'Project name' }).click(); | ||
await page.getByRole('textbox', { name: 'Project name' }).fill(projectName); | ||
await page.getByRole('button', { name: 'Save' }).click(); | ||
|
||
// Validate that project name is new | ||
await expect(await getActiveProjectLocator(page)).toHaveText(projectName); | ||
await page | ||
.locator('div') | ||
.filter({ hasText: /^main\.tact$/ }) | ||
.nth(1) | ||
.click(); | ||
await page.waitForTimeout(200); | ||
|
||
// Validate IDE code | ||
const ideCodeAfter = await getElementContent(page, MONACO_LINES_LOCATOR); | ||
|
||
await expect(normalizeString(ideCodeAfter)).toBe(normalizeString(shareCode)); | ||
}); |
Oops, something went wrong.