Skip to content

Commit

Permalink
fix(test): improve waiters for locators, added permissions for chromium
Browse files Browse the repository at this point in the history
  • Loading branch information
xpyctumo committed Feb 11, 2025
1 parent 107a905 commit 4df470a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 40 deletions.
2 changes: 0 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { all } = require("axios");

/* eslint-env node */
module.exports = {
extends: [
Expand Down
8 changes: 7 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ export default defineConfig({
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
use: {
...devices['Desktop Chrome'],
contextOptions: {
// chromium-specific permissions
permissions: ['clipboard-read', 'clipboard-write'],
},
},
},

{
Expand Down
7 changes: 2 additions & 5 deletions tests/contract/create-blank-contract-and-build.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { expect, test } from '@playwright/test';
import { randomUUID } from 'crypto';
import { XTERM_LOGS_LOCATOR } from 'tests/locators';
import {
getElementContent,
isCodeEditorLoaded,
logsContain,
openBuildAndDeployTab,
Expand Down Expand Up @@ -34,16 +32,15 @@ test('Create Blank Contract in Web IDE then build', async ({ page }) => {
await isCodeEditorLoaded(page);
await openBuildAndDeployTab(page);

const getLogs = () => getElementContent(page, XTERM_LOGS_LOCATOR);
await logsContain(await getLogs(), [`Project '${projectName}' is opened`]);
await logsContain(page, [`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(), [
await logsContain(page, [
/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/,
Expand Down
7 changes: 2 additions & 5 deletions tests/contract/create-counter-contract-and-build.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { expect, test } from '@playwright/test';
import { randomUUID } from 'crypto';
import { XTERM_LOGS_LOCATOR } from 'tests/locators';
import {
createProject,
getElementContent,
isCodeEditorLoaded,
logsContain,
openBuildAndDeployTab,
Expand All @@ -20,13 +18,12 @@ test('Create Counter Contract in Web IDE then build', async ({ page }) => {
await isCodeEditorLoaded(page);
await openBuildAndDeployTab(page);

const getLogs = () => getElementContent(page, XTERM_LOGS_LOCATOR);
await logsContain(await getLogs(), [`Project '${projectName}' is opened`]);
await logsContain(page, [`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/]);
await logsContain(page, [/Built Successfully/]);
});
9 changes: 5 additions & 4 deletions tests/project/clone-shared-code.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import {
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']);

test('Clone code from shared link to local', async ({ page, browserName }) => {
test.skip(
['firefox', 'webkit'].includes(browserName),
'clipboard not working on theese browsers',
);
// Generate share code
const shareCode = `contract ${randomUUID()} with Deployable {\n\n\n}`;
const url = `https://ide.ton.org/?code=${encodeBase64(shareCode)}&lang=tact`;
Expand Down
9 changes: 5 additions & 4 deletions tests/project/file-is-sharing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import {
ProjectType,
} from 'tests/utils';

test('Check file is sharing', async ({ page, context }) => {
// Grant clipboard permissions to browser context
await context.grantPermissions(['clipboard-read', 'clipboard-write']);

test('Check file is sharing', async ({ page, browserName }) => {
test.skip(
['firefox', 'webkit'].includes(browserName),
'clipboard not working on theese browsers',
);
// Open Web IDE
await page.goto('https://ide.ton.org/');
const projectName = randomUUID();
Expand Down
9 changes: 3 additions & 6 deletions tests/project/run-unit-tests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { expect, test } from '@playwright/test';
import { randomUUID } from 'crypto';
import { XTERM_LOGS_LOCATOR } from 'tests/locators';
import {
createProject,
getElementContent,
isCodeEditorLoaded,
logsContain,
openBuildAndDeployTab,
Expand All @@ -21,15 +19,14 @@ test('Create Counter contract and run Unit test', async ({ page }) => {
await isCodeEditorLoaded(page);
await openBuildAndDeployTab(page);

const getLogs = () => getElementContent(page, XTERM_LOGS_LOCATOR);
await logsContain(await getLogs(), [`Project '${projectName}' is opened`]);
await logsContain(page, [`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/]);
await logsContain(page, [/Built Successfully/]);

await openUnitTests(page);
await page.waitForTimeout(1500); // TODO: Remove this timeout after fix #249
Expand All @@ -38,7 +35,7 @@ test('Create Counter contract and run Unit test', async ({ page }) => {
await page.getByRole('button', { name: 'Run' }).click();

await page.waitForTimeout(1500);
await logsContain(await getLogs(), [
await logsContain(page, [
`Test Suites: 1 passed, 1 total`,
`Tests: 2 passed, 2 total`,
`Snapshots: 0 total`,
Expand Down
16 changes: 6 additions & 10 deletions tests/templates/e2e-web-build-and-deploy-template.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test';
import { MONACO_LINES_LOCATOR, XTERM_LOGS_LOCATOR } from '../locators';
import { MONACO_LINES_LOCATOR } from '../locators';
import {
getElementContent,
isCodeEditorLoaded,
Expand Down Expand Up @@ -35,11 +35,7 @@ test('Web IDE build and deploy template', async ({ page }) => {
normalizeString(templateContentValue || ''),
);

const getLogs = () => getElementContent(page, XTERM_LOGS_LOCATOR);

await expect(await getLogs()).toContain(
`Project '${TEMPLATE_NAME}' is opened`,
);
await logsContain(page, [`Project '${TEMPLATE_NAME}' is opened`]);

// Open Build and Deploy tab
await openBuildAndDeployTab(page);
Expand All @@ -50,7 +46,7 @@ test('Web IDE build and deploy template', async ({ page }) => {
await page.waitForTimeout(2000);

// Validate build logs
await logsContain(await getLogs(), [
await logsContain(page, [
'Message sent: Deploy, from EQAB..wSnT, to EQBK..v0_-, value 0.05, not bounced',
'Message sent: DeployOk, from EQBK..v0_-, to EQAB..wSnT, value 0.0465792, not bounced',
'Transaction Executed: success, Exit Code: 0, Gas: 0.0029424',
Expand All @@ -63,7 +59,7 @@ test('Web IDE build and deploy template', async ({ page }) => {
await page.waitForTimeout(1500);

// Validate redeploy logs
await logsContain(await getLogs(), [
await logsContain(page, [
'Deploying contract ...',
'Contract deployed on SANDBOX Contract address: EQ',
]);
Expand All @@ -74,7 +70,7 @@ test('Web IDE build and deploy template', async ({ page }) => {
await page.waitForTimeout(500);

// Validate call logs
await logsContain(await getLogs(), [
await logsContain(page, [
'Message sent: "increment", from EQAB..wSnT, to EQBK..v0_-, value 0.05',
'Transaction Executed: success, Exit Code: 0, Gas: 0.0014712',
]);
Expand All @@ -85,5 +81,5 @@ test('Web IDE build and deploy template', async ({ page }) => {
await page.waitForTimeout(500);

// Validate call logs
await logsContain(await getLogs(), ['"method": "value"', '"value": "1"']);
await logsContain(page, ['"method": "value"', '"value": "1"']);
});
11 changes: 8 additions & 3 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MONACO_LINES_LOCATOR,
PROJECT_DROPDOWN_LOCATOR,
UNIT_TESTS_LOCATOR,
XTERM_LOGS_LOCATOR,
} from './locators';

export async function getElementContent(page: Page, selector: string) {
Expand All @@ -27,11 +28,14 @@ export async function getElementContent(page: Page, selector: string) {
}

export async function logsContain(
logs: string,
page: Page,
expectedValues: string[] | RegExp[],
) {
for (const expectedValue of expectedValues) {
await expect(logs).toMatch(expectedValue);
await expect(await page.locator(XTERM_LOGS_LOCATOR)).toContainText(
expectedValue,
{ useInnerText: true },
);
}
}

Expand Down Expand Up @@ -60,9 +64,10 @@ export async function isCodeEditorLoaded(page: Page) {
await expect(page.getByText('Loading...', { exact: true }), {
message: 'Editor should be loaded',
}).not.toBeVisible();

await expect(codeBlock, {
message: 'Editor should be visible',
}).toBeVisible();
}).toBeInViewport();
}

export enum ProjectType {
Expand Down

0 comments on commit 4df470a

Please sign in to comment.