From de2909daaf0add75c12bc39dc8835700cdc7c5f0 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Wed, 29 Jan 2025 16:52:05 +0200 Subject: [PATCH 1/7] Add Screenshot on fail plugin --- .../src/plugins/ScreenshotOnFailPlugin.ts | 54 +++++++++++++++++++ @bellatrix/extras/src/plugins/index.ts | 1 + .../core/BrowserController.ts | 2 + .../playwright/PlaywrightBrowserController.ts | 5 ++ .../selenium/SeleniumBrowserController.ts | 6 +++ @bellatrix/web/src/services/BrowserService.ts | 6 +++ example/tests/ProductPurchaseTests.test.ts | 3 +- 7 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 @bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts diff --git a/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts b/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts new file mode 100644 index 0000000..6da33c3 --- /dev/null +++ b/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts @@ -0,0 +1,54 @@ +import { Plugin } from '@bellatrix/core/infrastructure'; +import { TestMetadata } from '@bellatrix/core/test/props'; +import { ServiceLocator } from '@bellatrix/core/utilities'; +import { App } from '@bellatrix/web/infrastructure'; +import * as fs from 'fs'; +import * as path from 'path'; + +export class ScreenshotOnFailPlugin extends Plugin { + override async preAfterTest(metadata: TestMetadata): Promise { + if(metadata.error !== undefined) { + const app = ServiceLocator.resolve(App); + const screenshotImage = await app.browser.getScreenshot(); + // Save the screenshot as an image file + try { + const savePath = this.saveImageFromBase64(screenshotImage.base64, '../reports/screenshots/' + metadata.testName); // TODO: take from config + console.info('\n Screenshot for failed test ' + metadata.testName + ': ' + savePath + '\n'); + } catch (error) { + console.error('Error saving screenshot:', (error as Error).message); + } + } + } + + /** + * Save a Base64 string as an image file + * @param base64String - The Base64 string of the image + * @param outputPath - The path to save the image file + */ + private saveImageFromBase64(base64String: string, outputPath: string): string { + // Check if the Base64 string contains the data prefix (e.g., "data:image/png;base64,") + let matches = base64String.match(/^data:image\/([a-zA-Z]+);base64,(.+)$/); + if (!matches || matches.length !== 3) { + base64String = 'data:image/png;base64,' + base64String; + matches = base64String.match(/^data:image\/([a-zA-Z]+);base64,(.+)$/); + } + // Extract the file extension and the Base64-encoded data + const fileExtension = matches[1]; // e.g., 'png', 'jpeg', etc. + const base64Data = matches[2]; + // Decode the Base64 string into binary data + const binaryData = Buffer.from(base64Data, 'base64'); + const arrayBufferView: Uint8Array = new Uint8Array(binaryData.buffer, binaryData.byteOffset, binaryData.length); + // Ensure the output directory exists + const outputDir = path.dirname(outputPath); + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, { recursive: true }); + } + // Determine the output file path (with the correct file extension) + const outputFilePath = path.extname(outputPath) + ? outputPath + : `${outputPath}.${fileExtension}`; + // Write the binary data to a file + fs.writeFileSync(outputFilePath, arrayBufferView); + return outputFilePath; + } +} diff --git a/@bellatrix/extras/src/plugins/index.ts b/@bellatrix/extras/src/plugins/index.ts index 5ad46e3..ffdd303 100644 --- a/@bellatrix/extras/src/plugins/index.ts +++ b/@bellatrix/extras/src/plugins/index.ts @@ -1 +1,2 @@ export * from './LogLifecyclePlugin'; +export * from './ScreenshotOnFailPlugin'; diff --git a/@bellatrix/web/src/infrastructure/browsercontroller/core/BrowserController.ts b/@bellatrix/web/src/infrastructure/browsercontroller/core/BrowserController.ts index ca32f4a..fe733d9 100644 --- a/@bellatrix/web/src/infrastructure/browsercontroller/core/BrowserController.ts +++ b/@bellatrix/web/src/infrastructure/browsercontroller/core/BrowserController.ts @@ -1,4 +1,5 @@ import { Locator, SearchContext, WebElement } from '.'; +import { Image } from '@bellatrix/core/image'; export type Cookie = { name: string; @@ -30,6 +31,7 @@ export abstract class BrowserController implements SearchContext { abstract getCookie(name: string): Promise; abstract getAllCookies(): Promise; abstract clearCookies(): Promise; + abstract getScreenshot(): Promise; abstract executeJavascript(script: string | ((...args: VarArgs) => T), ...args: VarArgs): Promise; abstract waitUntil(condition: (browserController: Omit) => boolean | Promise, timeout: number, pollingInterval: number): Promise diff --git a/@bellatrix/web/src/infrastructure/browsercontroller/playwright/PlaywrightBrowserController.ts b/@bellatrix/web/src/infrastructure/browsercontroller/playwright/PlaywrightBrowserController.ts index a827857..fb1dab4 100644 --- a/@bellatrix/web/src/infrastructure/browsercontroller/playwright/PlaywrightBrowserController.ts +++ b/@bellatrix/web/src/infrastructure/browsercontroller/playwright/PlaywrightBrowserController.ts @@ -4,6 +4,7 @@ import { Cookie, BrowserController, WebElement, Locator } from '@bellatrix/web/i import { PlaywrightWebElement } from '@bellatrix/web/infrastructure/browsercontroller/playwright'; import { BellatrixSettings } from '@bellatrix/core/settings'; import { HttpClient } from '@bellatrix/core/http'; +import { Image } from '@bellatrix/core/image'; export class PlaywrightBrowserController extends BrowserController { private _browser: Browser; @@ -48,6 +49,10 @@ export class PlaywrightBrowserController extends BrowserController { return await this._page.content(); } + override async getScreenshot(): Promise { + return await Image.fromBase64((await this._page.screenshot()).toString('base64')); + } + override async back(): Promise { await this._page.goBack(); } diff --git a/@bellatrix/web/src/infrastructure/browsercontroller/selenium/SeleniumBrowserController.ts b/@bellatrix/web/src/infrastructure/browsercontroller/selenium/SeleniumBrowserController.ts index c59c263..1c808fe 100644 --- a/@bellatrix/web/src/infrastructure/browsercontroller/selenium/SeleniumBrowserController.ts +++ b/@bellatrix/web/src/infrastructure/browsercontroller/selenium/SeleniumBrowserController.ts @@ -3,6 +3,7 @@ import { By, WebDriver as NativeWebDriver, until } from 'selenium-webdriver'; import { Cookie, BrowserController, WebElement, Locator } from '@bellatrix/web/infrastructure/browsercontroller/core'; import { SeleniumShadowRootWebElement, SeleniumWebElement } from '@bellatrix/web/infrastructure/browsercontroller/selenium'; import { BellatrixSettings } from '@bellatrix/core/settings'; +import { Image } from '@bellatrix/core/image'; export class SeleniumBrowserController extends BrowserController { private _driver: NativeWebDriver; @@ -32,6 +33,11 @@ export class SeleniumBrowserController extends BrowserController { return await this.wrappedDriver.getPageSource(); } + override async getScreenshot(): Promise { + const base64image = (await this.wrappedDriver.takeScreenshot()); + return Image.fromBase64(base64image); + } + override async back(): Promise { await this.wrappedDriver.navigate().back(); } diff --git a/@bellatrix/web/src/services/BrowserService.ts b/@bellatrix/web/src/services/BrowserService.ts index 4fd1623..98df51c 100644 --- a/@bellatrix/web/src/services/BrowserService.ts +++ b/@bellatrix/web/src/services/BrowserService.ts @@ -1,6 +1,7 @@ import { BrowserController } from '@bellatrix/web/infrastructure/browsercontroller/core'; import { BellatrixSettings } from '@bellatrix/core/settings'; import { BellatrixWebService } from '@bellatrix/web/services/decorators'; +import { Image } from '@bellatrix/core/image'; import { WebService } from '.'; @BellatrixWebService @@ -21,6 +22,11 @@ export class BrowserService extends WebService { return await this.driver.getPageSource(); } + async getScreenshot(): Promise { + const base64image = (await this.driver.getScreenshot()).base64; + return Image.fromBase64(base64image); + } + async back(): Promise { return await this.driver.back(); } diff --git a/example/tests/ProductPurchaseTests.test.ts b/example/tests/ProductPurchaseTests.test.ts index 5112ed1..5334735 100644 --- a/example/tests/ProductPurchaseTests.test.ts +++ b/example/tests/ProductPurchaseTests.test.ts @@ -2,7 +2,7 @@ import { Test, TestClass } from '@bellatrix/web/test'; import { WebTest } from '@bellatrix/web/infrastructure'; import { Button } from '@bellatrix/web/components'; import { ExtraWebHooks } from '@bellatrix/extras/hooks'; -import { LogLifecyclePlugin } from '@bellatrix/extras/plugins'; +import { LogLifecyclePlugin, ScreenshotOnFailPlugin } from '@bellatrix/extras/plugins'; import { MainPage, CartPage, CheckoutPage, PurchaseInfo } from '../src/pages'; import { PluginExecutionEngine } from '@bellatrix/core/infrastructure'; import { WebServiceHooks } from '@bellatrix/web/services/utilities'; @@ -14,6 +14,7 @@ export class ProductPurchaseTests extends WebTest { await super.configure(); ExtraWebHooks.addComponentBDDLogging(); PluginExecutionEngine.addPlugin(LogLifecyclePlugin); + PluginExecutionEngine.addPlugin(ScreenshotOnFailPlugin); WebServiceHooks.addListenerTo(NavigationService).before('navigate', (_, url) => console.log(`navigating to ${url}`)); } From 2859d36435f237e6367d580fee5a6bf657a74b03 Mon Sep 17 00:00:00 2001 From: Teodor Nikolov Date: Wed, 29 Jan 2025 17:18:22 +0200 Subject: [PATCH 2/7] reduced nesting --- .../src/plugins/ScreenshotOnFailPlugin.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts b/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts index 6da33c3..158ea8f 100644 --- a/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts +++ b/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts @@ -7,16 +7,18 @@ import * as path from 'path'; export class ScreenshotOnFailPlugin extends Plugin { override async preAfterTest(metadata: TestMetadata): Promise { - if(metadata.error !== undefined) { - const app = ServiceLocator.resolve(App); - const screenshotImage = await app.browser.getScreenshot(); - // Save the screenshot as an image file - try { - const savePath = this.saveImageFromBase64(screenshotImage.base64, '../reports/screenshots/' + metadata.testName); // TODO: take from config - console.info('\n Screenshot for failed test ' + metadata.testName + ': ' + savePath + '\n'); - } catch (error) { - console.error('Error saving screenshot:', (error as Error).message); - } + if (!metadata.error) { + return; + } + + const app = ServiceLocator.resolve(App); + const screenshotImage = await app.browser.getScreenshot(); + // Save the screenshot as an image file + try { + const savePath = this.saveImageFromBase64(screenshotImage.base64, '../reports/screenshots/' + metadata.testName); // TODO: take from config + console.info('\n Screenshot for failed test ' + metadata.testName + ': ' + savePath + '\n'); + } catch (error) { + console.error('Error saving screenshot:', (error as Error).message); } } From c7fa8dbf18609eaa3c2b63d9be04d893e165685b Mon Sep 17 00:00:00 2001 From: Teodor Nikolov Date: Wed, 29 Jan 2025 17:37:40 +0200 Subject: [PATCH 3/7] Refactor ScreenshotOnFailPlugin to use Image class for saving screenshots --- @bellatrix/core/src/image/Image.ts | 8 ++--- .../src/plugins/ScreenshotOnFailPlugin.ts | 32 ++++++------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/@bellatrix/core/src/image/Image.ts b/@bellatrix/core/src/image/Image.ts index c1a2558..b842f3d 100644 --- a/@bellatrix/core/src/image/Image.ts +++ b/@bellatrix/core/src/image/Image.ts @@ -54,6 +54,10 @@ export class Image { return `data:image/${this.type};base64,${this.base64}`; } + get buffer() { + return this._buffer; + } + get width(): number { switch (this._type) { case 'png': @@ -172,10 +176,6 @@ export class Image { } } - protected get buffer() { - return this._buffer; - } - protected determineType(buffer: Buffer): keyof typeof this.SIGNATURES { for (const [format, signature] of Object.entries(this.SIGNATURES)) { if (buffer.subarray(0, signature.length).equals(signature)) { diff --git a/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts b/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts index 158ea8f..26b655b 100644 --- a/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts +++ b/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts @@ -1,6 +1,7 @@ import { Plugin } from '@bellatrix/core/infrastructure'; import { TestMetadata } from '@bellatrix/core/test/props'; import { ServiceLocator } from '@bellatrix/core/utilities'; +import { Image } from '@bellatrix/core/image'; import { App } from '@bellatrix/web/infrastructure'; import * as fs from 'fs'; import * as path from 'path'; @@ -15,7 +16,7 @@ export class ScreenshotOnFailPlugin extends Plugin { const screenshotImage = await app.browser.getScreenshot(); // Save the screenshot as an image file try { - const savePath = this.saveImageFromBase64(screenshotImage.base64, '../reports/screenshots/' + metadata.testName); // TODO: take from config + const savePath = this.saveImageToFile(screenshotImage, '../reports/screenshots/' + metadata.testName); // TODO: take from config console.info('\n Screenshot for failed test ' + metadata.testName + ': ' + savePath + '\n'); } catch (error) { console.error('Error saving screenshot:', (error as Error).message); @@ -23,33 +24,20 @@ export class ScreenshotOnFailPlugin extends Plugin { } /** - * Save a Base64 string as an image file - * @param base64String - The Base64 string of the image + * Save an Image class instance as a file + * @param image - The Image instance to be saved * @param outputPath - The path to save the image file */ - private saveImageFromBase64(base64String: string, outputPath: string): string { - // Check if the Base64 string contains the data prefix (e.g., "data:image/png;base64,") - let matches = base64String.match(/^data:image\/([a-zA-Z]+);base64,(.+)$/); - if (!matches || matches.length !== 3) { - base64String = 'data:image/png;base64,' + base64String; - matches = base64String.match(/^data:image\/([a-zA-Z]+);base64,(.+)$/); - } - // Extract the file extension and the Base64-encoded data - const fileExtension = matches[1]; // e.g., 'png', 'jpeg', etc. - const base64Data = matches[2]; - // Decode the Base64 string into binary data - const binaryData = Buffer.from(base64Data, 'base64'); - const arrayBufferView: Uint8Array = new Uint8Array(binaryData.buffer, binaryData.byteOffset, binaryData.length); - // Ensure the output directory exists + private saveImageToFile(image: Image, outputPath: string): string { const outputDir = path.dirname(outputPath); if (!fs.existsSync(outputDir)) { fs.mkdirSync(outputDir, { recursive: true }); } - // Determine the output file path (with the correct file extension) - const outputFilePath = path.extname(outputPath) - ? outputPath - : `${outputPath}.${fileExtension}`; - // Write the binary data to a file + + const outputFilePath = path.extname(outputPath) ? outputPath : `${outputPath}.${image.type}`; + + const binaryData = image.buffer; + const arrayBufferView: Uint8Array = new Uint8Array(binaryData.buffer, binaryData.byteOffset, binaryData.length); fs.writeFileSync(outputFilePath, arrayBufferView); return outputFilePath; } From ef3e1bd9bdd61e08f9daa6bc9a384c277c7e553b Mon Sep 17 00:00:00 2001 From: Teodor Nikolov Date: Wed, 29 Jan 2025 18:38:45 +0200 Subject: [PATCH 4/7] added BELLATRIX_CONFIGURATION_ROOT environment variable --- @bellatrix/runner/bellatrix.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/@bellatrix/runner/bellatrix.js b/@bellatrix/runner/bellatrix.js index 9addb1c..600a0b0 100755 --- a/@bellatrix/runner/bellatrix.js +++ b/@bellatrix/runner/bellatrix.js @@ -81,7 +81,9 @@ const configs = [ '.bellatrix.json', ]; -const configFileURL = pathToFileURL(findFilePath(configs)); +const configFilePath = findFilePath(configs); +const configFileURL = pathToFileURL(configFilePath); +process.env.BELLATRIX_CONFIGURAITON_ROOT = dirname(configFilePath); let config; if (configFileURL.href.endsWith('.ts') || configFileURL.href.endsWith('.mts')) { From 66737b95a3f8b467f586b6fe6d9d09cf1bbae1e8 Mon Sep 17 00:00:00 2001 From: Teodor Nikolov Date: Wed, 29 Jan 2025 18:39:00 +0200 Subject: [PATCH 5/7] updated screenshot on fail update --- .../src/plugins/ScreenshotOnFailPlugin.ts | 58 +++++++++++++++---- example/bellatrix.config.ts | 5 ++ 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts b/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts index 26b655b..e199ae2 100644 --- a/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts +++ b/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts @@ -3,23 +3,47 @@ import { TestMetadata } from '@bellatrix/core/test/props'; import { ServiceLocator } from '@bellatrix/core/utilities'; import { Image } from '@bellatrix/core/image'; import { App } from '@bellatrix/web/infrastructure'; -import * as fs from 'fs'; -import * as path from 'path'; +import { existsSync, mkdirSync, writeFileSync } from 'fs'; +import { dirname, extname, join } from 'path'; +import { BellatrixSettings } from '@bellatrix/core/settings'; export class ScreenshotOnFailPlugin extends Plugin { override async preAfterTest(metadata: TestMetadata): Promise { + const pluginSettings = BellatrixSettings.get().screenshotOnFailPluginSettings; + + if (!pluginSettings?.isPluginEnabled) { + return; + } + if (!metadata.error) { return; } const app = ServiceLocator.resolve(App); const screenshotImage = await app.browser.getScreenshot(); - // Save the screenshot as an image file + + const outputPath = pluginSettings?.outputPath; + + if (!outputPath) { + console.error('Output path for screenshots is not defined in the configuration.'); + return; + } + try { - const savePath = this.saveImageToFile(screenshotImage, '../reports/screenshots/' + metadata.testName); // TODO: take from config + const projectRoot = process.env['BELLATRIX_CONFIGURAITON_ROOT']!; // TODO: find a better way to get the project root + const pathArray = [projectRoot, outputPath]; + if (pluginSettings?.shouldCreateFolderPerSuite) { + pathArray.push(metadata.suiteName); + } + pathArray.push(metadata.testName); + const savePath = this.saveImageToFile(screenshotImage, join(...pathArray)); console.info('\n Screenshot for failed test ' + metadata.testName + ': ' + savePath + '\n'); } catch (error) { - console.error('Error saving screenshot:', (error as Error).message); + if (error instanceof Error) { + console.error('Error saving screenshot:', error.message); + } else { + console.error('Error saving screenshot'); + } } } @@ -29,16 +53,28 @@ export class ScreenshotOnFailPlugin extends Plugin { * @param outputPath - The path to save the image file */ private saveImageToFile(image: Image, outputPath: string): string { - const outputDir = path.dirname(outputPath); - if (!fs.existsSync(outputDir)) { - fs.mkdirSync(outputDir, { recursive: true }); + const outputDir = dirname(outputPath); + if (!existsSync(outputDir)) { + mkdirSync(outputDir, { recursive: true }); } - const outputFilePath = path.extname(outputPath) ? outputPath : `${outputPath}.${image.type}`; + const outputFilePath = extname(outputPath) ? outputPath : `${outputPath}.${image.type}`; const binaryData = image.buffer; - const arrayBufferView: Uint8Array = new Uint8Array(binaryData.buffer, binaryData.byteOffset, binaryData.length); - fs.writeFileSync(outputFilePath, arrayBufferView); + const arrayBufferView = new Uint8Array(binaryData.buffer, binaryData.byteOffset, binaryData.length); + writeFileSync(outputFilePath, arrayBufferView); return outputFilePath; } } + +declare module '@bellatrix/core/types' { + interface BellatrixConfiguration { + screenshotOnFailPluginSettings?: ScreenshotOnFailPluginSettings; + } +} + +interface ScreenshotOnFailPluginSettings { + isPluginEnabled: boolean; + outputPath: string, + shouldCreateFolderPerSuite?: boolean, +} diff --git a/example/bellatrix.config.ts b/example/bellatrix.config.ts index 9f0d7bb..76c7beb 100644 --- a/example/bellatrix.config.ts +++ b/example/bellatrix.config.ts @@ -43,6 +43,11 @@ const config: BellatrixConfigurationOverride = { browserName: 'chrome' } } + }, + screenshotOnFailPluginSettings: { + isPluginEnabled: true, + outputPath: `./reports/screenshots${Date.now()}`, + shouldCreateFolderPerSuite: true, } }; From c29c49ae29fa896cdb9b9e49417d5f9d0809c1c1 Mon Sep 17 00:00:00 2001 From: Teodor Nikolov Date: Wed, 29 Jan 2025 18:40:41 +0200 Subject: [PATCH 6/7] disabled screenshot on fail's shouldCreateFolderPerSuite in example project --- example/bellatrix.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/bellatrix.config.ts b/example/bellatrix.config.ts index 76c7beb..ca7dfaf 100644 --- a/example/bellatrix.config.ts +++ b/example/bellatrix.config.ts @@ -47,7 +47,7 @@ const config: BellatrixConfigurationOverride = { screenshotOnFailPluginSettings: { isPluginEnabled: true, outputPath: `./reports/screenshots${Date.now()}`, - shouldCreateFolderPerSuite: true, + shouldCreateFolderPerSuite: false, } }; From f201943ce653873ada9f5df27643be229c9c1f65 Mon Sep 17 00:00:00 2001 From: NikolayAvramov Date: Thu, 30 Jan 2025 13:17:21 +0200 Subject: [PATCH 7/7] rename screenshot method --- @bellatrix/appium/src/android/AndroidDriver.ts | 2 +- @bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts | 3 ++- .../browsercontroller/core/BrowserController.ts | 2 +- .../playwright/PlaywrightBrowserController.ts | 2 +- .../browsercontroller/selenium/SeleniumBrowserController.ts | 2 +- @bellatrix/web/src/services/BrowserService.ts | 4 ++-- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/@bellatrix/appium/src/android/AndroidDriver.ts b/@bellatrix/appium/src/android/AndroidDriver.ts index e37ed8b..2391558 100644 --- a/@bellatrix/appium/src/android/AndroidDriver.ts +++ b/@bellatrix/appium/src/android/AndroidDriver.ts @@ -135,7 +135,7 @@ export class AndroidDriver extends AppiumDriver { }); } - async getScreenshot(): Promise { + async takeScreenshot(): Promise { const base64image = await this.commandExecutor.execute>(MobileCommands.SCREENSHOT); return Image.fromBase64(base64image); } diff --git a/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts b/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts index e199ae2..811780f 100644 --- a/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts +++ b/@bellatrix/extras/src/plugins/ScreenshotOnFailPlugin.ts @@ -20,7 +20,7 @@ export class ScreenshotOnFailPlugin extends Plugin { } const app = ServiceLocator.resolve(App); - const screenshotImage = await app.browser.getScreenshot(); + const screenshotImage = await app.browser.takeScreenshot(); const outputPath = pluginSettings?.outputPath; @@ -77,4 +77,5 @@ interface ScreenshotOnFailPluginSettings { isPluginEnabled: boolean; outputPath: string, shouldCreateFolderPerSuite?: boolean, + shouldCaptureFullPage?: boolean, } diff --git a/@bellatrix/web/src/infrastructure/browsercontroller/core/BrowserController.ts b/@bellatrix/web/src/infrastructure/browsercontroller/core/BrowserController.ts index fe733d9..fb861db 100644 --- a/@bellatrix/web/src/infrastructure/browsercontroller/core/BrowserController.ts +++ b/@bellatrix/web/src/infrastructure/browsercontroller/core/BrowserController.ts @@ -31,7 +31,7 @@ export abstract class BrowserController implements SearchContext { abstract getCookie(name: string): Promise; abstract getAllCookies(): Promise; abstract clearCookies(): Promise; - abstract getScreenshot(): Promise; + abstract takeScreenshot(): Promise; abstract executeJavascript(script: string | ((...args: VarArgs) => T), ...args: VarArgs): Promise; abstract waitUntil(condition: (browserController: Omit) => boolean | Promise, timeout: number, pollingInterval: number): Promise diff --git a/@bellatrix/web/src/infrastructure/browsercontroller/playwright/PlaywrightBrowserController.ts b/@bellatrix/web/src/infrastructure/browsercontroller/playwright/PlaywrightBrowserController.ts index fb1dab4..60b257b 100644 --- a/@bellatrix/web/src/infrastructure/browsercontroller/playwright/PlaywrightBrowserController.ts +++ b/@bellatrix/web/src/infrastructure/browsercontroller/playwright/PlaywrightBrowserController.ts @@ -49,7 +49,7 @@ export class PlaywrightBrowserController extends BrowserController { return await this._page.content(); } - override async getScreenshot(): Promise { + override async takeScreenshot(): Promise { return await Image.fromBase64((await this._page.screenshot()).toString('base64')); } diff --git a/@bellatrix/web/src/infrastructure/browsercontroller/selenium/SeleniumBrowserController.ts b/@bellatrix/web/src/infrastructure/browsercontroller/selenium/SeleniumBrowserController.ts index 1c808fe..bf5e55a 100644 --- a/@bellatrix/web/src/infrastructure/browsercontroller/selenium/SeleniumBrowserController.ts +++ b/@bellatrix/web/src/infrastructure/browsercontroller/selenium/SeleniumBrowserController.ts @@ -33,7 +33,7 @@ export class SeleniumBrowserController extends BrowserController { return await this.wrappedDriver.getPageSource(); } - override async getScreenshot(): Promise { + override async takeScreenshot(): Promise { const base64image = (await this.wrappedDriver.takeScreenshot()); return Image.fromBase64(base64image); } diff --git a/@bellatrix/web/src/services/BrowserService.ts b/@bellatrix/web/src/services/BrowserService.ts index 98df51c..e26a4e2 100644 --- a/@bellatrix/web/src/services/BrowserService.ts +++ b/@bellatrix/web/src/services/BrowserService.ts @@ -22,8 +22,8 @@ export class BrowserService extends WebService { return await this.driver.getPageSource(); } - async getScreenshot(): Promise { - const base64image = (await this.driver.getScreenshot()).base64; + async takeScreenshot(): Promise { + const base64image = (await this.driver.takeScreenshot()).base64; return Image.fromBase64(base64image); }