From 1ec4835dcac769d0711bbfeaa63b4e1743fde265 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Feb 2023 16:25:52 +0100 Subject: [PATCH] Create screenshots directory when needed --- .../e2e/src/suites-local/signup.e2e-spec.ts | 23 +++++++++++++------ client/e2e/src/utils/files.ts | 17 ++++++++++++++ client/e2e/src/utils/hooks.ts | 5 +++- client/e2e/src/utils/index.ts | 1 + 4 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 client/e2e/src/utils/files.ts diff --git a/client/e2e/src/suites-local/signup.e2e-spec.ts b/client/e2e/src/suites-local/signup.e2e-spec.ts index b6f7ad1a7..7c822a6e6 100644 --- a/client/e2e/src/suites-local/signup.e2e-spec.ts +++ b/client/e2e/src/suites-local/signup.e2e-spec.ts @@ -2,7 +2,16 @@ import { AdminConfigPage } from '../po/admin-config.po' import { AdminRegistrationPage } from '../po/admin-registration.po' import { LoginPage } from '../po/login.po' import { SignupPage } from '../po/signup.po' -import { browserSleep, getVerificationLink, go, findEmailTo, isMobileDevice, MockSMTPServer, waitServerUp } from '../utils' +import { + browserSleep, + findEmailTo, + getScreenshotPath, + getVerificationLink, + go, + isMobileDevice, + MockSMTPServer, + waitServerUp +} from '../utils' function checkEndMessage (options: { message: string @@ -155,7 +164,7 @@ describe('Signup', () => { afterEmailVerification: false }) - await browser.saveScreenshot('./screenshots/direct-without-email.png') + await browser.saveScreenshot(getScreenshotPath('direct-without-email.png')) await loginPage.logout() }) @@ -203,7 +212,7 @@ describe('Signup', () => { afterEmailVerification: false }) - await browser.saveScreenshot('./screenshots/request-without-email.png') + await browser.saveScreenshot(getScreenshotPath('request-without-email.png')) }) it('Should display a message when trying to login with this account', async function () { @@ -283,7 +292,7 @@ describe('Signup', () => { afterEmailVerification: false }) - await browser.saveScreenshot('./screenshots/direct-with-email.png') + await browser.saveScreenshot(getScreenshotPath('direct-with-email.png')) }) it('Should validate the email', async function () { @@ -304,7 +313,7 @@ describe('Signup', () => { afterEmailVerification: true }) - await browser.saveScreenshot('./screenshots/direct-after-email.png') + await browser.saveScreenshot(getScreenshotPath('direct-after-email.png')) }) }) @@ -355,7 +364,7 @@ describe('Signup', () => { afterEmailVerification: false }) - await browser.saveScreenshot('./screenshots/request-with-email.png') + await browser.saveScreenshot(getScreenshotPath('request-with-email.png')) }) it('Should display a message when trying to login with this account', async function () { @@ -391,7 +400,7 @@ describe('Signup', () => { afterEmailVerification: true }) - await browser.saveScreenshot('./screenshots/request-after-email.png') + await browser.saveScreenshot(getScreenshotPath('request-after-email.png')) }) }) diff --git a/client/e2e/src/utils/files.ts b/client/e2e/src/utils/files.ts new file mode 100644 index 000000000..c532c987e --- /dev/null +++ b/client/e2e/src/utils/files.ts @@ -0,0 +1,17 @@ +import { mkdirSync } from 'fs' +import { join } from 'path' + +const SCREENSHOTS_DIRECTORY = 'screenshots' + +function createScreenshotsDirectory () { + mkdirSync(SCREENSHOTS_DIRECTORY, { recursive: true }) +} + +function getScreenshotPath (filename: string) { + return join(SCREENSHOTS_DIRECTORY, filename) +} + +export { + createScreenshotsDirectory, + getScreenshotPath +} diff --git a/client/e2e/src/utils/hooks.ts b/client/e2e/src/utils/hooks.ts index 7fe247681..8baf9fb44 100644 --- a/client/e2e/src/utils/hooks.ts +++ b/client/e2e/src/utils/hooks.ts @@ -1,7 +1,8 @@ import { ChildProcessWithoutNullStreams } from 'child_process' import { basename } from 'path' -import { runCommand, runServer } from './server' import { setValue } from '@wdio/shared-store-service' +import { createScreenshotsDirectory } from './files' +import { runCommand, runServer } from './server' let appInstance: number let app: ChildProcessWithoutNullStreams @@ -21,6 +22,8 @@ function afterLocalSuite () { } async function beforeLocalSession (config: { baseUrl: string }, capabilities: { browserName: string }) { + await createScreenshotsDirectory() + appInstance = capabilities['browserName'] === 'chrome' ? 1 : 2 diff --git a/client/e2e/src/utils/index.ts b/client/e2e/src/utils/index.ts index 420fd239e..0770cb0f4 100644 --- a/client/e2e/src/utils/index.ts +++ b/client/e2e/src/utils/index.ts @@ -1,6 +1,7 @@ export * from './common' export * from './elements' export * from './email' +export * from './files' export * from './hooks' export * from './mock-smtp' export * from './server'