diff --git a/e2e/tests/actionValues.test.ts b/e2e/tests/actionValues.test.ts deleted file mode 100644 index f072f157..00000000 --- a/e2e/tests/actionValues.test.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* -MIT License - -Copyright (c) 2021-present, Elastic NV - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -import { Page } from 'playwright-core'; -import { ElectronServiceFactory, env } from '../services'; - -const electronService = new ElectronServiceFactory(); - -afterEach(async () => { - await electronService.terminate(); -}); - -const ACTION_URL = 'https://e2e-test-action-edit.org'; -const ACTION_OPTION = 'innerText'; -const ASSERTION_SELECTOR = 'test-assertion-selector'; -const ASSERTION_VALUE = 'test-assertion-value'; - -async function addAssertion() { - await electronService.enterTestUrl(env.DEMO_APP_URL); - await electronService.clickStartRecording(); - await electronService.waitForPageToBeIdle(); - await electronService.clickStopRecording(); - await electronService.clickActionElementSettingsButton( - 'id=action-element-0-0', - 'text=Add assertion' - ); -} - -async function editAssertion(electronWindow: Page) { - await electronWindow.click('id=action-element-0-1'); - await electronWindow.hover('id=action-element-0-1'); - await electronWindow.selectOption(`[aria-label="Assertion type select"]`, ACTION_OPTION); - await electronWindow.fill(`[aria-label="Assertion selector"]`, ASSERTION_SELECTOR); - await electronWindow.fill(`[aria-label="Assertion value"]`, ASSERTION_VALUE); - await electronWindow.click(`[data-test-subj="save-0-1"]`); - // make sure state has been updated by checking the action header's content - await electronWindow.waitForSelector(`#action-element-0-1 >> div:has-text("Inner Text")`, { - timeout: 2000, - }); -} - -async function editAction(electronWindow: Page) { - await electronService.clickActionElementSettingsButton( - 'id=action-element-0-0', - `[data-test-subj="edit-action"]` - ); - await electronWindow.fill(`[data-test-subj="edit-url-0-0"]`, ACTION_URL); - await electronWindow.click(`[data-test-subj="save-action-0-0"]`); - // make sure state has been updated by checking the ation header's content - await electronWindow.waitForSelector(`id=action-element-0-0 >> div:has-text("${ACTION_URL}")`, { - timeout: 2000, - }); -} - -describe('Assertion and Action values', () => { - it('includes updated action/assertion values in code output', async () => { - const electronWindow = await electronService.getWindow(); - await addAssertion(); - await editAssertion(electronWindow); - await editAction(electronWindow); - - // open export flyout - await electronWindow.click('text=Export'); - // get inner text of code to export - const innerText = await (await electronWindow.$('id=export-code-block')).innerText(); - - /** - * The outputted code should contain the updated values we have supplied in the edit steps above. - */ - expect(innerText).toContain( - `expect(await page.${ACTION_OPTION}('${ASSERTION_SELECTOR}')).toMatch('${ASSERTION_VALUE}');` - ); - expect(innerText).toContain(`await page.goto('${ACTION_URL}');`); - }); -}); diff --git a/e2e/tests/assertion.test.ts b/e2e/tests/assertion.test.ts deleted file mode 100644 index 9a098c74..00000000 --- a/e2e/tests/assertion.test.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -MIT License - -Copyright (c) 2021-present, Elastic NV - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -import { ElectronServiceFactory, env } from '../services'; - -const electronService = new ElectronServiceFactory(); - -afterEach(async () => { - await electronService.terminate(); -}); - -describe('Assertion', () => { - describe('Assertion Info Popover', () => { - it('creates a link to playwright docs on assertion info popover', async () => { - const electronWindow = await electronService.getWindow(); - await electronService.enterTestUrl(env.DEMO_APP_URL); - await electronService.clickStartRecording(); - await electronService.waitForPageToBeIdle(); - await electronService.clickStopRecording(); - await electronService.clickActionElementSettingsButton( - 'id=action-element-0-0', - 'text=Add assertion' - ); - await electronWindow.click( - `[aria-label="Shows a popover with more information about Playwright assertions."]` - ); - - expect( - await electronWindow.$( - "text=You can add assertions to validate your page's content matches your expectations." - ) - ).toBeTruthy(); - expect(await electronWindow.$('text=Read more')).toBeTruthy(); - }); - }); -}); diff --git a/e2e/tests/export.test.ts b/e2e/tests/export.test.ts deleted file mode 100644 index cc967e3c..00000000 --- a/e2e/tests/export.test.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* -MIT License - -Copyright (c) 2021-present, Elastic NV - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ -import os from 'os'; -import path from 'path'; -import * as fs from 'fs/promises'; -import { ElectronServiceFactory, env } from '../services'; - -const electronService = new ElectronServiceFactory(); -afterAll(async () => { - await electronService.terminate(); -}); - -describe('Export', () => { - it('shows disabled export button when script is not recorded', async () => { - const electronWindow = await electronService.getWindow(); - const exportButton = await electronWindow.$(`[aria-label="export"]`); - expect(exportButton).toBeTruthy(); - expect(await exportButton!.isEnabled()).toBeFalsy(); - }); - - it('saves a script in filesystem', async () => { - const app = await electronService.getInstance(); - const filePath = path.join(os.tmpdir(), 'some.journey.test'); - // when clicking `Save` button, saves given file immediately instead of opening save dialog - // it bypasses native dialog interaction for testing - const saveDialogMock = async ({ dialog }, filePath) => { - dialog.showSaveDialog = () => Promise.resolve({ canceled: false, filePath }); - }; - // apply mocking dialog.showSaveDialog to electron app - await app.evaluate(saveDialogMock, filePath); - - const electronWindow = await electronService.getWindow(); - await electronService.enterTestUrl(env.DEMO_APP_URL); - await electronService.clickStartRecording(); - await electronService.waitForPageToBeIdle(); - await electronService.clickStopRecording(); - - const exportButton = await electronWindow.$(`[aria-label="export"]`); - expect(exportButton).toBeTruthy(); - await exportButton?.click(); - const saveButton = await electronWindow.$('[aria-label="save-code"]'); - await saveButton?.click(); - // file exists, otherwise throws - expect(await fs.stat(filePath)).toBeTruthy(); - // cleanup - await fs.rm(filePath); - }); -}); diff --git a/e2e/tests/navigation.test.ts b/e2e/tests/navigation.test.ts deleted file mode 100644 index 526780de..00000000 --- a/e2e/tests/navigation.test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* -MIT License - -Copyright (c) 2021-present, Elastic NV - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -import type { Server } from 'http'; -import { ElectronServiceFactory, env } from '../services'; -import { createTestHttpServer } from './testServer'; - -const electronService = new ElectronServiceFactory(); - -let server: Server; -let url: string; - -beforeAll(async () => { - const { server: s, port } = await createTestHttpServer(); - server = s; - url = `http://localhost:${port}`; -}); - -afterAll(async () => { - await electronService.terminate(); - await new Promise(resolve => server.close(resolve)); -}); - -describe('Navigation', () => { - it("records chromium's opened pages", async () => { - const electronWindow = await electronService.getWindow(); - - await electronService.enterTestUrl(env.DEMO_APP_URL); - - await electronService.clickStartRecording(); - await electronService.waitForPageToBeIdle(); - await electronService.navigateRecordingBrowser(url); - - expect(await electronWindow.$('text=Step 1')).toBeTruthy(); - expect(await electronWindow.$(`text=navigate ${env.DEMO_APP_URL}`)).toBeTruthy(); - expect(await electronWindow.$(`text=navigate ${url}`)).toBeTruthy(); - await electronService.clickStopRecording(); - }); -}); diff --git a/e2e/tests/pauseAndResume.test.ts b/e2e/tests/pauseAndResume.test.ts deleted file mode 100644 index 3b37dbab..00000000 --- a/e2e/tests/pauseAndResume.test.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* -MIT License - -Copyright (c) 2021-present, Elastic NV - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -import { ElectronServiceFactory, env } from '../services'; - -const electronService = new ElectronServiceFactory(); - -afterEach(async () => { - await electronService.terminate(); -}); - -describe('Pause and Resume', () => { - it('pauses and resumes', async () => { - const electronWindow = await electronService.getWindow(); - - await electronService.enterTestUrl(env.DEMO_APP_URL); - await electronService.clickStartRecording(); - await electronService.waitForPageToBeIdle(); - await electronWindow.click('text=Pause'); - - expect(await electronWindow.getByText('Recording paused')).toBeTruthy(); - - expect(await electronWindow.getByText('Resume')).toBeTruthy(); - expect(await electronWindow.getByText('Stop').isDisabled()).toBeTruthy(); - expect(await electronWindow.getByText('Test').isDisabled()).toBeTruthy(); - - await electronWindow.click('text=Resume'); - expect(await electronWindow.getByText('Recording', { exact: true })).toBeTruthy(); - await electronService.recordClick('text=BuyUSD 12.49 >> button'); - await electronService.recordClick('text=Add to Cart'); - await electronService.clickStopRecording(); - - expect(await electronWindow.getByText('Start over').isEnabled()).toBeTruthy(); - expect(await electronWindow.getByText('Test').isEnabled()).toBeTruthy(); - }); -}); diff --git a/e2e/tests/runTest.test.ts b/e2e/tests/runTest.test.ts deleted file mode 100644 index 8dc3b4c3..00000000 --- a/e2e/tests/runTest.test.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* -MIT License - -Copyright (c) 2021-present, Elastic NV - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -import { ElementHandle, Page } from 'playwright-core'; -import { ElectronServiceFactory, env } from '../services'; - -let electronService: ElectronServiceFactory; - -beforeEach(() => { - electronService = new ElectronServiceFactory(); -}); - -afterEach(async () => { - await electronService.terminate(); -}); - -describe('Run test', () => { - describe('Test Button', () => { - it('is disabled when scripts are not recorded', async () => { - const electronWindow: Page = await electronService.getWindow(); - - const testButton = await electronWindow.getByLabel('Test'); - expect(await testButton.count()).toBe(1); - expect(await testButton.isEnabled()).toBeFalsy(); - }); - - it('is disabled during a recording session', async () => { - const electronWindow = await electronService.getWindow(); - - await electronService.enterTestUrl(env.DEMO_APP_URL); - await electronService.clickStartRecording(); - await electronService.waitForPageToBeIdle(); - - const testButton = (await electronWindow.$(`[aria-label="Test"]`)) as ElementHandle; - expect(testButton).toBeTruthy(); - expect(await testButton.isEnabled()).toBeFalsy(); - await electronService.clickStopRecording(); - }); - }); - - describe('Record forms and run tests', () => { - it('records filling up the form, run tests and shows the result', async () => { - const electronWindow = await electronService.getWindow(); - await electronService.enterTestUrl(env.DEMO_APP_URL); - await electronService.clickStartRecording(); - await electronService.waitForPageToBeIdle(); - - await electronService.recordClick('text=BuyUSD 12.49 >> button'); - await electronService.recordClick('text=Add to Cart'); - await electronService - .getRecordingPage() - .locator('input[name="email"]') - .fill('hello@example.com'); - await electronService - .getRecordingPage() - .locator('input[name="street_address"]') - .fill('1 High st'); - await electronService.recordClick('text=Place your order'); - - await electronService.clickStopRecording(); - await electronService.clickRunTest(); - - expect(await electronWindow.$('text=1 success')); - }); - }); -}); diff --git a/e2e/tests/stepDividers.test.ts b/e2e/tests/stepDividers.test.ts deleted file mode 100644 index 885ce8a9..00000000 --- a/e2e/tests/stepDividers.test.ts +++ /dev/null @@ -1,123 +0,0 @@ -/* -MIT License - -Copyright (c) 2021-present, Elastic NV - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ -import type { Server } from 'http'; -import { ElectronServiceFactory, env } from '../services'; -import { createTestHttpServer } from './testServer'; - -let electronService: ElectronServiceFactory; -let server: Server; -let url: string; - -beforeAll(async () => { - const { server: s, port } = await createTestHttpServer(); - server = s; - url = `http://localhost:${port}`; - console.log('url port', url); -}); - -afterAll(async () => { - await new Promise(resolve => server.close(resolve)); -}); - -function getCoordinates({ - x, - y, - width, - height, -}: { - x: number; - y: number; - width: number; - height: number; -}) { - return [x + width / 2, y + height / 2]; -} - -describe('Step Divider', () => { - beforeEach(async () => { - electronService = new ElectronServiceFactory(); - }); - afterEach(async () => { - await electronService.terminate(); - }); - - it('creates a step and drags to a new position', async () => { - const electronWindow = await electronService.getWindow(); - await electronService.enterTestUrl(env.DEMO_APP_URL); - await electronService.clickStartRecording(); - await electronService.waitForPageToBeIdle(); - await electronService.navigateRecordingBrowser(url); - const page = await electronService.getRecordingPage(); - await page.getByRole('button', { name: 'Hello Elastic Synthetics Recorder' }).click(); - - await electronWindow.getByText('Hello Elastic Synthetics').waitFor(); - await electronService.clickStopRecording(); - - const divider = await electronWindow.locator('id=insert-divider-0-1'); - await divider.click(); - const step = await electronWindow.locator('id=step-1'); - await step.hover(); - await electronWindow.mouse.down(); - await electronWindow.mouse.move(100, 100, { steps: 5 }); - const dropZone = await (await electronWindow.locator('id=action-element-1-0')).boundingBox(); - if (!dropZone) expect(dropZone).not.toBeNull(); - else { - const [dzx, dzy] = getCoordinates(dropZone); - await electronWindow.mouse.move(dzx, dzy, { steps: 5 }); - await electronWindow.mouse.up(); - /** - * There was originally only one action in this step, so the targeted insert button would only be - * rendered if Playwright successfully dragged the step separator over drop zone and released it. - */ - expect(await electronWindow.$('id=insert-divider-0-1')).toBeTruthy(); - } - }); - - it('deletes a step', async () => { - const electronWindow = await electronService.getWindow(); - await electronService.enterTestUrl(env.DEMO_APP_URL); - await electronService.clickStartRecording(); - await electronService.waitForPageToBeIdle(); - await electronService.navigateRecordingBrowser(url); - await electronService.waitForPageToBeIdle(); - const page = await electronService.getRecordingPage(); - await page.getByRole('button', { name: 'Hello Elastic Synthetics Recorder' }).click(); - - await electronWindow.getByText('Hello Elastic Synthetics').waitFor(); - await electronService.clickStopRecording(); - - const divider = await electronWindow.locator('id=insert-divider-0-1'); - await divider.click(); - const step = await electronWindow.locator('id=step-1'); - await step.hover(); - const elems = await electronWindow.$$('[data-test-subj="step-div"]'); - expect(elems.length).toEqual(2); - const isVisible = await electronWindow.locator('text=Step 2').isVisible(); - expect(isVisible).toBeTruthy(); - - await electronWindow.locator('[aria-label="Delete step"]').nth(0).click(); - const stepCounts = await electronWindow.locator('[data-test-subj="step-div"]').count(); - expect(stepCounts).toEqual(1); - }); -});