diff --git a/test/sql/document.spec.ts b/test/sql/document.spec.ts index 9095f03e3..5d17c22c3 100644 --- a/test/sql/document.spec.ts +++ b/test/sql/document.spec.ts @@ -1,6 +1,7 @@ import { expect, test } from "@playwright/test"; -import { existsSync, unlinkSync, writeFileSync } from "fs"; +import { existsSync, mkdtempSync, rmdirSync, unlinkSync, writeFileSync } from "fs"; +import { tmpdir } from "os"; import path from "path"; import { CommandBarButton, DataExplorer, DocumentsTab, ONE_MINUTE_MS, TestAccount } from "../fx"; import { @@ -108,9 +109,13 @@ for (const { name, databaseId, containerId, documents } of documentTestCases) { test.describe.serial("Upload Item", () => { let context: TestContainerContext = null!; - const uploadDocumentFilePath: string = path.join(__dirname, "uploadDocument.json"); + let uploadDocumentDirPath: string = null!; + let uploadDocumentFilePath: string = null!; test.beforeAll("Create Test database and open documents tab", async ({ browser }) => { + uploadDocumentDirPath = mkdtempSync(path.join(tmpdir(), "upload-document-")); + uploadDocumentFilePath = path.join(uploadDocumentDirPath, "uploadDocument.json"); + const page = await browser.newPage(); context = await createTestSQLContainer(); explorer = await DataExplorer.open(page, TestAccount.SQL); @@ -124,10 +129,13 @@ test.describe.serial("Upload Item", () => { await containerMenuNode.element.click(); }); - test.afterAll("Delete Test Database and uploadDocument.json", async () => { + test.afterAll("Delete Test Database and uploadDocument temp folder", async () => { if (existsSync(uploadDocumentFilePath)) { unlinkSync(uploadDocumentFilePath); } + if (existsSync(uploadDocumentDirPath)) { + rmdirSync(uploadDocumentDirPath); + } if (!process.env.CI) { await context?.dispose(); } @@ -193,9 +201,9 @@ test.describe.serial("Upload Item", () => { await uploadButton.click(); // Verify upload failure message - const fileUploadStatusExpected: string = "Unexpected non-whitespace character after JSON"; const fileUploadErrorList = explorer.frame.getByLabel("error list"); - await expect(fileUploadErrorList).toContainText(fileUploadStatusExpected, { + // The parsing error will show up differently in different browsers so just check for the word "JSON" + await expect(fileUploadErrorList).toContainText("JSON", { timeout: ONE_MINUTE_MS, }); }); diff --git a/test/sql/scaleAndSettings/computedProperties.spec.ts b/test/sql/scaleAndSettings/computedProperties.spec.ts index c3723fdae..d1f95e53e 100644 --- a/test/sql/scaleAndSettings/computedProperties.spec.ts +++ b/test/sql/scaleAndSettings/computedProperties.spec.ts @@ -96,14 +96,13 @@ test.describe("Computed Properties", () => { const clearComputedPropertiesTextBoxContent = async ({ page }: { page: Page }): Promise => { // Get computed properties text box - const computedPropertiesTextBox = explorer.frame.getByRole("textbox", { name: "Computed properties" }); - await computedPropertiesTextBox.waitFor(); + await explorer.frame.waitForSelector(".monaco-scrollable-element", { state: "visible" }); const computedPropertiesEditor = explorer.frame.getByTestId("computed-properties-editor"); await computedPropertiesEditor.click(); - // Clear existing content - const isMac: boolean = process.platform === "darwin"; - await page.keyboard.press(isMac ? "Meta+A" : "Control+A"); - await page.keyboard.press("Backspace"); + // Clear existing content (Ctrl+A + Backspace does not work with webkit) + for (let i = 0; i < 100; i++) { + await page.keyboard.press("Backspace"); + } }; }); diff --git a/test/sql/scripts/storedProcedure.spec.ts b/test/sql/scripts/storedProcedure.spec.ts index 3a784f90b..94a0cd3f3 100644 --- a/test/sql/scripts/storedProcedure.spec.ts +++ b/test/sql/scripts/storedProcedure.spec.ts @@ -18,7 +18,7 @@ test.describe("Stored Procedures", () => { await context?.dispose(); }); - test("Add, execute, and delete stored procedure", async () => { + test("Add, execute, and delete stored procedure", async ({}, testInfo) => { // Open container context menu and click New Stored Procedure const containerNode = await explorer.waitForContainerNode(context.database.id, context.container.id); await containerNode.openContextMenu(); @@ -27,7 +27,7 @@ test.describe("Stored Procedures", () => { // Type stored procedure id and use stock procedure const storedProcedureIdTextBox = explorer.frame.getByLabel("Stored procedure id"); await storedProcedureIdTextBox.isVisible(); - const storedProcedureName = "stored-procedure-1"; + const storedProcedureName = `stored-procedure-${testInfo.testId}`; await storedProcedureIdTextBox.fill(storedProcedureName); const saveButton = explorer.commandBarButton(CommandBarButton.Save); @@ -48,7 +48,9 @@ test.describe("Stored Procedures", () => { await executeSidePanelButton.click(); const executeStoredProcedureResult = explorer.frame.getByLabel("Execute stored procedure result"); - await expect(executeStoredProcedureResult).toBeVisible(); + await expect(executeStoredProcedureResult).toBeAttached({ + timeout: ONE_MINUTE_MS, + }); // Delete stored procedure await containerNode.expand(); diff --git a/test/sql/scripts/trigger.spec.ts b/test/sql/scripts/trigger.spec.ts index 21100b18a..6874c2aac 100644 --- a/test/sql/scripts/trigger.spec.ts +++ b/test/sql/scripts/trigger.spec.ts @@ -32,7 +32,7 @@ test.describe("Triggers", () => { }); } - test("Add and delete trigger", async ({ page }) => { + test("Add and delete trigger", async ({ page }, testInfo) => { // Open container context menu and click New Trigger const containerNode = await explorer.waitForContainerNode(context.database.id, context.container.id); await containerNode.openContextMenu(); @@ -40,7 +40,7 @@ test.describe("Triggers", () => { // Assign Trigger id const triggerIdTextBox = explorer.frame.getByLabel("Trigger Id"); - const triggerId: string = "validateItemTimestamp"; + const triggerId: string = `validateItemTimestamp-${testInfo.testId}`; await triggerIdTextBox.fill(triggerId); // Create Trigger body that validates item timestamp diff --git a/test/sql/scripts/userDefinedFunction.spec.ts b/test/sql/scripts/userDefinedFunction.spec.ts index 8f6a80dd0..911b1f4ce 100644 --- a/test/sql/scripts/userDefinedFunction.spec.ts +++ b/test/sql/scripts/userDefinedFunction.spec.ts @@ -25,7 +25,7 @@ test.describe("User Defined Functions", () => { }); } - test("Add, execute, and delete user defined function", async ({ page }) => { + test("Add, execute, and delete user defined function", async ({ page }, testInfo) => { // Open container context menu and click New UDF const containerNode = await explorer.waitForContainerNode(context.database.id, context.container.id); await containerNode.openContextMenu(); @@ -33,7 +33,7 @@ test.describe("User Defined Functions", () => { // Assign UDF id const udfIdTextBox = explorer.frame.getByLabel("User Defined Function Id"); - const udfId: string = "extractDocumentId"; + const udfId: string = `extractDocumentId-${testInfo.testId}`; await udfIdTextBox.fill(udfId); // Create UDF body that extracts the document id from a document