From ae33fbf9a751cf8e6ac90b111dec79beaa52d4b8 Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Mon, 25 Nov 2024 17:58:00 +0200 Subject: [PATCH 01/13] Pages and Sections now implement the interface PageObjectModel Used to group POMs together --- .../solutions/bellatrix/core/utilities/PageObjectModel.java | 4 ++++ .../java/solutions/bellatrix/desktop/pages/AppSection.java | 3 ++- .../java/solutions/bellatrix/desktop/pages/DesktopPage.java | 3 ++- .../main/java/solutions/bellatrix/ios/pages/AppSection.java | 3 ++- .../src/main/java/solutions/bellatrix/ios/pages/IOSPage.java | 3 ++- .../java/solutions/bellatrix/playwright/pages/WebPage.java | 3 ++- .../java/solutions/bellatrix/playwright/pages/WebSection.java | 3 ++- .../src/main/java/solutions/bellatrix/web/pages/WebPage.java | 3 ++- .../main/java/solutions/bellatrix/web/pages/WebSection.java | 3 ++- 9 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java diff --git a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java new file mode 100644 index 00000000..577f6429 --- /dev/null +++ b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java @@ -0,0 +1,4 @@ +package solutions.bellatrix.core.utilities; + +public interface PageObjectModel { +} diff --git a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java index 2a3583c6..0ed223e3 100644 --- a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java +++ b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java @@ -13,12 +13,13 @@ package solutions.bellatrix.desktop.pages; +import solutions.bellatrix.core.utilities.PageObjectModel; import solutions.bellatrix.desktop.services.AppService; import solutions.bellatrix.desktop.services.ComponentCreateService; import java.lang.reflect.ParameterizedType; -public abstract class AppSection> { +public abstract class AppSection> implements PageObjectModel { public AppService browser() { return new AppService(); } diff --git a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java index bd027db9..aa82bc8e 100644 --- a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java +++ b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java @@ -13,12 +13,13 @@ package solutions.bellatrix.desktop.pages; +import solutions.bellatrix.core.utilities.PageObjectModel; import solutions.bellatrix.desktop.services.AppService; import solutions.bellatrix.desktop.services.ComponentCreateService; import java.lang.reflect.ParameterizedType; -public abstract class DesktopPage> { +public abstract class DesktopPage> implements PageObjectModel { public AppService appService() { return new AppService(); } diff --git a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java index 7d73b032..1d643c7a 100644 --- a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java +++ b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java @@ -13,12 +13,13 @@ package solutions.bellatrix.ios.pages; +import solutions.bellatrix.core.utilities.PageObjectModel; import solutions.bellatrix.ios.services.AppService; import solutions.bellatrix.ios.services.ComponentCreateService; import java.lang.reflect.ParameterizedType; -public abstract class AppSection> { +public abstract class AppSection> implements PageObjectModel { public AppService browser() { return new AppService(); } diff --git a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java index 7f7e18d8..b2d22bcd 100644 --- a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java +++ b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java @@ -13,12 +13,13 @@ package solutions.bellatrix.ios.pages; +import solutions.bellatrix.core.utilities.PageObjectModel; import solutions.bellatrix.ios.services.AppService; import solutions.bellatrix.ios.services.ComponentCreateService; import java.lang.reflect.ParameterizedType; -public abstract class IOSPage> { +public abstract class IOSPage> implements PageObjectModel { public AppService appService() { return new AppService(); } diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java index b7102df3..66c3d64a 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java @@ -14,13 +14,14 @@ package solutions.bellatrix.playwright.pages; import solutions.bellatrix.core.utilities.InstanceFactory; +import solutions.bellatrix.core.utilities.PageObjectModel; import solutions.bellatrix.core.utilities.SingletonFactory; import solutions.bellatrix.playwright.services.App; import solutions.bellatrix.playwright.services.BrowserService; import solutions.bellatrix.playwright.services.ComponentCreateService; import solutions.bellatrix.playwright.services.NavigationService; -public abstract class WebPage> { +public abstract class WebPage> implements PageObjectModel { public ComponentCreateService create() { return SingletonFactory.getInstance(ComponentCreateService.class); } diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java index 8bd5864c..954fa387 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java @@ -14,10 +14,11 @@ package solutions.bellatrix.playwright.pages; import solutions.bellatrix.core.utilities.InstanceFactory; +import solutions.bellatrix.core.utilities.PageObjectModel; import solutions.bellatrix.core.utilities.SingletonFactory; import solutions.bellatrix.playwright.services.BrowserService; import solutions.bellatrix.playwright.services.ComponentCreateService; -public abstract class WebSection> { +public abstract class WebSection> implements PageObjectModel { public BrowserService browser() { return SingletonFactory.getInstance(BrowserService.class); } diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java index 593c94c2..c60e7b7f 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java @@ -13,6 +13,7 @@ package solutions.bellatrix.web.pages; +import solutions.bellatrix.core.utilities.PageObjectModel; import solutions.bellatrix.web.infrastructure.Browser; import solutions.bellatrix.web.services.App; import solutions.bellatrix.web.services.BrowserService; @@ -22,7 +23,7 @@ import java.lang.reflect.ParameterizedType; -public abstract class WebPage> { +public abstract class WebPage> implements PageObjectModel { public BrowserService browser() { return new BrowserService(); } diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java index 370eda65..d0421c71 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java @@ -13,12 +13,13 @@ package solutions.bellatrix.web.pages; +import solutions.bellatrix.core.utilities.PageObjectModel; import solutions.bellatrix.web.services.BrowserService; import solutions.bellatrix.web.services.ComponentCreateService; import java.lang.reflect.ParameterizedType; -public abstract class WebSection> { +public abstract class WebSection> implements PageObjectModel { public BrowserService browser() { return new BrowserService(); } From 65df92053d3c9ce0fb8ea4e559923d0e783b1598 Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Mon, 25 Nov 2024 18:00:43 +0200 Subject: [PATCH 02/13] Added addPluginWithKey method to UsesPlugins abstract class addPluginWithKey(Class key, Class plugin, Object... args) allows for a plugin to be registered under a second key; Useful for ScreenshotPlugin, which is extended by multiple classes, yet VRT plugin tries to find the screenshot plugin through the super class. --- .../java/solutions/bellatrix/core/plugins/UsesPlugins.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/UsesPlugins.java b/bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/UsesPlugins.java index a1d46a24..1a144a85 100644 --- a/bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/UsesPlugins.java +++ b/bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/UsesPlugins.java @@ -9,6 +9,12 @@ public void addPlugin(Class plugin, Object... args) { PluginExecutionEngine.addPlugin(SingletonFactory.getInstance(plugin, args)); } + public void addPluginWithKey(Class key, Class plugin, Object... args) { + var instance = SingletonFactory.getInstance(plugin, args); + SingletonFactory.register(key, instance); + PluginExecutionEngine.addPlugin(instance); + } + public void addListener(Class listener, Object... args) { Objects.requireNonNull(SingletonFactory.getInstance(listener, args)).addListener(); } From f9d4d65c084e17b0a9ef71b87a329918034c8cc5 Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Mon, 25 Nov 2024 18:02:40 +0200 Subject: [PATCH 03/13] Registering with 2 keys screenshot plugin in WebTest It is once registered as its proper class and once as its super class --- .../bellatrix/android/infrastructure/junit/AndroidTest.java | 3 ++- .../bellatrix/android/infrastructure/testng/AndroidTest.java | 3 ++- .../bellatrix/desktop/infrastructure/junit/DesktopTest.java | 3 ++- .../bellatrix/desktop/infrastructure/testng/DesktopTest.java | 3 ++- .../solutions/bellatrix/ios/infrastructure/junit/IOSTest.java | 3 ++- .../solutions/bellatrix/ios/infrastructure/testng/IOSTest.java | 3 ++- .../bellatrix/playwright/infrastructure/junit/WebTest.java | 3 ++- .../bellatrix/playwright/infrastructure/testng/WebTest.java | 3 ++- .../solutions/bellatrix/web/infrastructure/junit/WebTest.java | 3 ++- .../solutions/bellatrix/web/infrastructure/testng/WebTest.java | 3 ++- 10 files changed, 20 insertions(+), 10 deletions(-) diff --git a/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/junit/AndroidTest.java b/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/junit/AndroidTest.java index 92e78359..150c15e1 100644 --- a/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/junit/AndroidTest.java +++ b/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/junit/AndroidTest.java @@ -14,6 +14,7 @@ package solutions.bellatrix.android.infrastructure.junit; import org.junit.jupiter.api.extension.ExtendWith; +import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.android.components.listeners.BddLogging; import solutions.bellatrix.android.infrastructure.AppLifecyclePlugin; import solutions.bellatrix.android.infrastructure.DownloadDemoAppsPlugin; @@ -33,7 +34,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPlugin(MobileScreenshotPlugin.class); + addPluginWithKey(ScreenshotPlugin.class, MobileScreenshotPlugin.class); addPlugin(MobileVideoPlugin.class); //addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/testng/AndroidTest.java b/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/testng/AndroidTest.java index 1f49e1db..db2550b3 100644 --- a/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/testng/AndroidTest.java +++ b/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/testng/AndroidTest.java @@ -13,6 +13,7 @@ package solutions.bellatrix.android.infrastructure.testng; +import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.android.components.listeners.BddLogging; import solutions.bellatrix.android.infrastructure.AppLifecyclePlugin; import solutions.bellatrix.android.infrastructure.DownloadDemoAppsPlugin; @@ -30,7 +31,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPlugin(MobileScreenshotPlugin.class); + addPluginWithKey(ScreenshotPlugin.class, MobileScreenshotPlugin.class); addPlugin(MobileVideoPlugin.class); addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/junit/DesktopTest.java b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/junit/DesktopTest.java index 62e4579d..a98f777b 100644 --- a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/junit/DesktopTest.java +++ b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/junit/DesktopTest.java @@ -13,6 +13,7 @@ package solutions.bellatrix.desktop.infrastructure.junit; +import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.core.plugins.junit.BaseTest; import solutions.bellatrix.desktop.components.listeners.BddLogging; import solutions.bellatrix.desktop.infrastructure.AppLifecyclePlugin; @@ -30,7 +31,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPlugin(DesktopScreenshotPlugin.class); + addPluginWithKey(ScreenshotPlugin.class, DesktopScreenshotPlugin.class); addPlugin(DesktopVideoPlugin.class); addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/testng/DesktopTest.java b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/testng/DesktopTest.java index 3f271fb0..0e516046 100644 --- a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/testng/DesktopTest.java +++ b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/testng/DesktopTest.java @@ -13,6 +13,7 @@ package solutions.bellatrix.desktop.infrastructure.testng; +import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.core.plugins.testng.BaseTest; import solutions.bellatrix.desktop.components.listeners.BddLogging; import solutions.bellatrix.desktop.infrastructure.AppLifecyclePlugin; @@ -30,7 +31,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPlugin(DesktopScreenshotPlugin.class); + addPluginWithKey(ScreenshotPlugin.class, DesktopScreenshotPlugin.class); addPlugin(DesktopVideoPlugin.class); addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/junit/IOSTest.java b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/junit/IOSTest.java index 49d979da..eede942e 100644 --- a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/junit/IOSTest.java +++ b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/junit/IOSTest.java @@ -13,6 +13,7 @@ package solutions.bellatrix.ios.infrastructure.junit; +import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.core.plugins.junit.BaseTest; import solutions.bellatrix.ios.components.listeners.BddLogging; import solutions.bellatrix.ios.infrastructure.AppLifecyclePlugin; @@ -29,7 +30,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPlugin(MobileScreenshotPlugin.class); + addPluginWithKey(ScreenshotPlugin.class, MobileScreenshotPlugin.class); addPlugin(MobileVideoPlugin.class); addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/testng/IOSTest.java b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/testng/IOSTest.java index b96590df..6fa84034 100644 --- a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/testng/IOSTest.java +++ b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/testng/IOSTest.java @@ -13,6 +13,7 @@ package solutions.bellatrix.ios.infrastructure.testng; +import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.core.plugins.testng.BaseTest; import solutions.bellatrix.ios.components.listeners.BddLogging; import solutions.bellatrix.ios.infrastructure.AppLifecyclePlugin; @@ -29,7 +30,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPlugin(MobileScreenshotPlugin.class); + addPluginWithKey(ScreenshotPlugin.class, MobileScreenshotPlugin.class); addPlugin(MobileVideoPlugin.class); addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/junit/WebTest.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/junit/WebTest.java index 486d5396..b9a21984 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/junit/WebTest.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/junit/WebTest.java @@ -14,6 +14,7 @@ package solutions.bellatrix.playwright.infrastructure.junit; import org.junit.jupiter.api.extension.ExtendWith; +import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.core.plugins.junit.BaseTest; import solutions.bellatrix.core.plugins.junit.TestResultWatcher; import solutions.bellatrix.core.utilities.SingletonFactory; @@ -35,7 +36,7 @@ public App app() { @Override protected void configure() { addPlugin(BrowserLifecyclePlugin.class); - addPlugin(WebScreenshotPlugin.class); + addPluginWithKey(ScreenshotPlugin.class, WebScreenshotPlugin.class); addPlugin(WebVideoPlugin.class); addPlugin(LogLifecyclePlugin.class); addListener(BddConsoleLogging.class); diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/testng/WebTest.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/testng/WebTest.java index d4571fb1..0591ec94 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/testng/WebTest.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/testng/WebTest.java @@ -13,6 +13,7 @@ package solutions.bellatrix.playwright.infrastructure.testng; +import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.core.plugins.testng.BaseTest; import solutions.bellatrix.core.utilities.SingletonFactory; import solutions.bellatrix.playwright.components.listeners.BddConsoleLogging; @@ -31,7 +32,7 @@ public App app() { @Override protected void configure() { addPlugin(BrowserLifecyclePlugin.class); - addPlugin(WebScreenshotPlugin.class); + addPluginWithKey(ScreenshotPlugin.class, WebScreenshotPlugin.class); addPlugin(WebVideoPlugin.class); addPlugin(LogLifecyclePlugin.class); addListener(BddConsoleLogging.class); diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/junit/WebTest.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/junit/WebTest.java index efbaa2b8..cc98ec8d 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/junit/WebTest.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/junit/WebTest.java @@ -14,6 +14,7 @@ package solutions.bellatrix.web.infrastructure.junit; import org.junit.jupiter.api.extension.ExtendWith; +import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.core.plugins.junit.BaseTest; import solutions.bellatrix.core.plugins.junit.TestResultWatcher; import solutions.bellatrix.core.utilities.SingletonFactory; @@ -36,7 +37,7 @@ public App app() { @Override protected void configure() { addPlugin(BrowserLifecyclePlugin.class); - addPlugin(WebScreenshotPlugin.class); + addPluginWithKey(ScreenshotPlugin.class, WebScreenshotPlugin.class); addPlugin(WebVideoPlugin.class); addPlugin(LogLifecyclePlugin.class); addListener(BddConsoleLogging.class); diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/testng/WebTest.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/testng/WebTest.java index 4655c95b..d7d41790 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/testng/WebTest.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/testng/WebTest.java @@ -13,6 +13,7 @@ package solutions.bellatrix.web.infrastructure.testng; +import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.core.plugins.testng.BaseTest; import solutions.bellatrix.core.utilities.SingletonFactory; import solutions.bellatrix.web.components.listeners.BddConsoleLogging; @@ -32,7 +33,7 @@ public App app() { @Override protected void configure() { addPlugin(BrowserLifecyclePlugin.class); - addPlugin(WebScreenshotPlugin.class); + addPluginWithKey(ScreenshotPlugin.class, WebScreenshotPlugin.class); addPlugin(WebVideoPlugin.class); addPlugin(LogLifecyclePlugin.class); addListener(BddConsoleLogging.class); From 93bf25234e09818c6011464a009941b0f9aba844 Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Mon, 25 Nov 2024 18:03:54 +0200 Subject: [PATCH 04/13] Update VRT plugin --- .../bellatrix/plugins/vrt/ViewportSize.java | 51 +++++++++ .../plugins/vrt/VisualRegression.java | 26 +++++ .../vrt/VisualRegressionAssertions.java | 49 ++++++++ .../plugins/vrt/VisualRegressionPlugin.java | 47 ++++++++ .../plugins/vrt/VisualRegressionService.java | 106 ++++++++++++++++++ ...ngs.java => VisualRegressionSettings.java} | 4 +- .../plugins/vrt/VisualRegressionTracker.java | 55 --------- 7 files changed, 281 insertions(+), 57 deletions(-) create mode 100644 bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/ViewportSize.java create mode 100644 bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegression.java create mode 100644 bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java create mode 100644 bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionPlugin.java create mode 100644 bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java rename bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/{VisualRegressionTrackerSettings.java => VisualRegressionSettings.java} (95%) delete mode 100644 bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionTracker.java diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/ViewportSize.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/ViewportSize.java new file mode 100644 index 00000000..0e0f4f84 --- /dev/null +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/ViewportSize.java @@ -0,0 +1,51 @@ +/* + * Copyright 2024 Automate The Planet Ltd. + * Author: Miriam Kyoseva + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package solutions.bellatrix.plugins.vrt; + +import lombok.Getter; + +@Getter +public enum ViewportSize { + + MOBILE_S(300, 873), + MOBILE_M(320, 873), + MOBILE_L(393, 873), + TABLET(768, 873), + DESKTOP_M(1280, 873), + DESKTOP(1440, 873), + DESKTOP_TALL(1440, 1500), + IPHONE_X(375, 667), + NEXUS_7_TABLET(600, 960), + IPAD(768, 1024), + IPHONE_SE(375, 667), + IPHONE_13_PRO(375, 667), + IPHONE_12_PRO(390, 844); + + private final int width; + private final int height; + + ViewportSize(int width, int height) { + this.width = width; + this.height = height; + } + + public String getName(){ + return this.name(); + } + + @Override + public String toString() { + return String.format("%sx%s", getWidth(), getHeight()); + } +} diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegression.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegression.java new file mode 100644 index 00000000..2d5932e6 --- /dev/null +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegression.java @@ -0,0 +1,26 @@ +/* + * Copyright 2024 Automate The Planet Ltd. + * Author: Miriam Kyoseva + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package solutions.bellatrix.plugins.vrt; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface VisualRegression { + String projectName() default ""; + ViewportSize viewportSize() default ViewportSize.DESKTOP; +} diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java new file mode 100644 index 00000000..caedd48e --- /dev/null +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java @@ -0,0 +1,49 @@ +/* + * Copyright 2024 Automate The Planet Ltd. + * Author: Miriam Kyoseva + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package solutions.bellatrix.plugins.vrt; + +import io.visual_regression_tracker.sdk_java.TestRunResult; +import io.visual_regression_tracker.sdk_java.TestRunStatus; +import lombok.experimental.UtilityClass; +import org.junit.jupiter.api.Assertions; +import solutions.bellatrix.core.utilities.PageObjectModel; + +@UtilityClass +public class VisualRegressionAssertions { + public static void assertSameAsBaseline(String name, String... testCasesName) { + TestRunResult result = VisualRegressionService.track(name + String.join(" ", testCasesName), 0.01f); + Assertions.assertSame(result.getTestRunResponse().getStatus(), TestRunStatus.OK, + String.format("Visual comparison has detected a difference at: %s", result.getTestRunResponse().getUrl())); + } + + public static void assertSameAsBaseline(String name, String screenshot, String... testCasesName) { + TestRunResult result = VisualRegressionService.track(name + String.join(" ", testCasesName), 0.01f, screenshot); + Assertions.assertSame(result.getTestRunResponse().getStatus(), TestRunStatus.OK, + String.format("Visual comparison has detected a difference at: %s", result.getTestRunResponse().getUrl())); + } + + public static void assertSameAsBaseline(PageObjectModel pageObjectModel, String... testCasesName) { + String name = pageObjectModel.getClass().getSimpleName(); + assertSameAsBaseline(name, testCasesName); + } + + public static void assertSameAsBaseline(PageObjectModel pageObjectModel) { + assertSameAsBaseline(pageObjectModel, ""); + } + + public static void assertSameAsBaseline(TestRunResult result) { + Assertions.assertSame(result.getTestRunResponse().getStatus(), TestRunStatus.OK, + String.format("Visual comparison has detected a difference at: %s", result.getTestRunResponse().getUrl())); + } +} diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionPlugin.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionPlugin.java new file mode 100644 index 00000000..84463a58 --- /dev/null +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionPlugin.java @@ -0,0 +1,47 @@ +/* + * Copyright 2024 Automate The Planet Ltd. + * Author: Miriam Kyoseva + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package solutions.bellatrix.plugins.vrt; + +import solutions.bellatrix.core.configuration.ConfigurationService; +import solutions.bellatrix.core.plugins.Plugin; +import solutions.bellatrix.core.plugins.TestResult; + +import java.lang.reflect.Method; + +public class VisualRegressionPlugin extends Plugin { + @Override + public void postAfterTest(TestResult testResult, Method memberInfo, Throwable failedTestException) { + VisualRegressionService.stop(); + } + + @Override + public void preBeforeTest(TestResult testResult, Method memberInfo) { + VisualRegression attribute = getVisualRegressionConfiguration(memberInfo); + + if (attribute != null) { + VisualRegressionService.initService(attribute, ConfigurationService.get(VisualRegressionSettings.class)); + VisualRegressionService.start(); + } + } + + private VisualRegression getVisualRegressionConfiguration(Method memberInfo) { + var classAttribute = (VisualRegression)memberInfo.getDeclaringClass().getDeclaredAnnotation(VisualRegression.class); + var methodAttribute = (VisualRegression)memberInfo.getDeclaredAnnotation(VisualRegression.class); + if (methodAttribute != null) { + return methodAttribute; + } + + return classAttribute; + } +} diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java new file mode 100644 index 00000000..69f03649 --- /dev/null +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java @@ -0,0 +1,106 @@ +/* + * Copyright 2024 Automate The Planet Ltd. + * Author: Miriam Kyoseva + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package solutions.bellatrix.plugins.vrt; + +import io.visual_regression_tracker.sdk_java.TestRunOptions; +import io.visual_regression_tracker.sdk_java.TestRunResult; +import io.visual_regression_tracker.sdk_java.VisualRegressionTracker; +import io.visual_regression_tracker.sdk_java.VisualRegressionTrackerConfig; +import lombok.experimental.UtilityClass; +import plugins.screenshots.ScreenshotPlugin; +import solutions.bellatrix.core.configuration.ConfigurationService; +import solutions.bellatrix.core.utilities.SingletonFactory; + +import java.io.IOException; +import java.util.Objects; + +public class VisualRegressionService { + private static final ThreadLocal VISUAL_REGRESSION_TRACKER_THREAD_LOCAL; + private static final ThreadLocal VISUAL_REGRESSION_ATTRIBUTE; + + static { + try { + VISUAL_REGRESSION_TRACKER_THREAD_LOCAL = new ThreadLocal<>(); + VISUAL_REGRESSION_ATTRIBUTE = new ThreadLocal<>(); + } catch (Exception e) { + throw new RuntimeException("Failed to initialize VisualRegressionService", e); + } + } + + public static VisualRegressionTracker tracker() { + return VISUAL_REGRESSION_TRACKER_THREAD_LOCAL.get(); + } + + public static void initService(VisualRegression attribute, VisualRegressionSettings settings) { + VISUAL_REGRESSION_ATTRIBUTE.set(attribute); + VISUAL_REGRESSION_TRACKER_THREAD_LOCAL.set(new VisualRegressionTracker(new VisualRegressionTrackerConfig( + settings.getApiUrl(), + settings.getApiKey(), + settings.getProject(), + settings.getBranch(), + settings.getCiBuildId(), + settings.isEnableSoftAssert(), + settings.getHttpTimeout() + ))); + } + + public static TestRunResult track(String name, Float diffTolerance, String screenshot) { + try { + return tracker().track(name, screenshot, buildRunOptions(diffTolerance)); + } catch (IOException | InterruptedException e) { + throw new RuntimeException(e); + } + } + + public static TestRunResult track(String name, Float diffTolerance) { + return track(name, diffTolerance, takeSnapshot(name)); + } + + public static TestRunResult track(String name) { + return track(name, 0.000f); + } + + public static String takeSnapshot(String name) { + var screenshotPlugin = SingletonFactory.getInstance(ScreenshotPlugin.class); + return Objects.requireNonNull(screenshotPlugin).takeScreenshot(name); + } + + public static TestRunOptions buildRunOptions(Float diffTolerance) { + var options = TestRunOptions.builder() + .device(System.getProperty("COMPUTERNAME")) + .os(System.getProperty("os.name")) + .viewport(String.format("%dx%d", VISUAL_REGRESSION_ATTRIBUTE.get().viewportSize().getWidth(), VISUAL_REGRESSION_ATTRIBUTE.get().viewportSize().getHeight())) + .customTags(String.format("%s", VISUAL_REGRESSION_ATTRIBUTE.get().viewportSize().name())) + .diffTollerancePercent(diffTolerance) + .build(); + + return options; + } + + public static void start() { + try { + VISUAL_REGRESSION_TRACKER_THREAD_LOCAL.get().start(); + } catch (IOException | InterruptedException e) { + throw new RuntimeException(e); + } + } + + public static void stop() { + try { + VISUAL_REGRESSION_TRACKER_THREAD_LOCAL.get().stop(); + } catch (IOException | InterruptedException e) { + throw new RuntimeException(e); + } + } +} diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionTrackerSettings.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionSettings.java similarity index 95% rename from bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionTrackerSettings.java rename to bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionSettings.java index 7369f03a..ac661b6d 100644 --- a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionTrackerSettings.java +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionSettings.java @@ -18,10 +18,10 @@ import lombok.Setter; @Getter @Setter @NoArgsConstructor -public class VisualRegressionTrackerSettings { +public class VisualRegressionSettings { private String apiUrl; - private String project; private String apiKey; + private String project; private String branch; private boolean enableSoftAssert; private String ciBuildId; diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionTracker.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionTracker.java deleted file mode 100644 index b4a9142f..00000000 --- a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionTracker.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2024 Automate The Planet Ltd. - * Author: Miriam Kyoseva - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package solutions.bellatrix.plugins.vrt; - -import io.visual_regression_tracker.sdk_java.VisualRegressionTrackerConfig; -import lombok.SneakyThrows; -import lombok.experimental.UtilityClass; -import plugins.screenshots.ScreenshotPlugin; -import solutions.bellatrix.core.configuration.ConfigurationService; -import solutions.bellatrix.core.utilities.SingletonFactory; - -import java.util.Objects; - -@UtilityClass -public class VisualRegressionTracker { - private static final VisualRegressionTrackerSettings settings = ConfigurationService.get(VisualRegressionTrackerSettings.class); - private static final VisualRegressionTrackerConfig config = new VisualRegressionTrackerConfig( - settings.getApiUrl(), - settings.getApiKey(), - settings.getProject(), - settings.getBranch(), - settings.getCiBuildId(), - settings.isEnableSoftAssert(), - settings.getHttpTimeout() - ); - private static io.visual_regression_tracker.sdk_java.VisualRegressionTracker tracker; - - static { - tracker = new io.visual_regression_tracker.sdk_java.VisualRegressionTracker(config); - } - - @SneakyThrows - public static void takeSnapshot() { - var caller = Thread.currentThread().getStackTrace()[1]; // gets the caller method of screenshot() - var name = caller.getMethodName(); - - tracker.track(name, Objects.requireNonNull(SingletonFactory.getInstance(ScreenshotPlugin.class)).takeScreenshot(name)); - } - - @SneakyThrows - public static void takeSnapshot(String name) { - tracker.track(name, Objects.requireNonNull(SingletonFactory.getInstance(ScreenshotPlugin.class)).takeScreenshot(name)); - } -} From dc070206877a219e74c3d5dd66f9b7d91afde889 Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Mon, 25 Nov 2024 18:14:00 +0200 Subject: [PATCH 05/13] Prioritize attribute's projectName over the projectName defined in the config file --- .../bellatrix/plugins/vrt/VisualRegressionService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java index 69f03649..a5bc23dd 100644 --- a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java @@ -44,15 +44,18 @@ public static VisualRegressionTracker tracker() { public static void initService(VisualRegression attribute, VisualRegressionSettings settings) { VISUAL_REGRESSION_ATTRIBUTE.set(attribute); - VISUAL_REGRESSION_TRACKER_THREAD_LOCAL.set(new VisualRegressionTracker(new VisualRegressionTrackerConfig( + + var config = new VisualRegressionTrackerConfig( settings.getApiUrl(), settings.getApiKey(), - settings.getProject(), + !attribute.projectName().isBlank() ? attribute.projectName() : settings.getProject(), settings.getBranch(), settings.getCiBuildId(), settings.isEnableSoftAssert(), settings.getHttpTimeout() - ))); + ); + + VISUAL_REGRESSION_TRACKER_THREAD_LOCAL.set(new VisualRegressionTracker(config)); } public static TestRunResult track(String name, Float diffTolerance, String screenshot) { From c34053260d4a23f55d2a8d4c58a7f79fdb33f4f9 Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Mon, 25 Nov 2024 18:46:13 +0200 Subject: [PATCH 06/13] Update to PageObjectModel interface --- .../java/solutions/bellatrix/android/pages/AndroidPage.java | 3 ++- .../java/solutions/bellatrix/android/pages/AppSection.java | 3 ++- .../solutions/bellatrix/core/utilities/PageObjectModel.java | 6 +++++- .../java/solutions/bellatrix/desktop/pages/AppSection.java | 2 +- .../java/solutions/bellatrix/desktop/pages/DesktopPage.java | 2 +- .../main/java/solutions/bellatrix/ios/pages/AppSection.java | 2 +- .../main/java/solutions/bellatrix/ios/pages/IOSPage.java | 2 +- .../java/solutions/bellatrix/playwright/pages/WebPage.java | 2 +- .../solutions/bellatrix/playwright/pages/WebSection.java | 2 +- .../main/java/solutions/bellatrix/web/pages/WebPage.java | 2 +- .../main/java/solutions/bellatrix/web/pages/WebSection.java | 2 +- 11 files changed, 17 insertions(+), 11 deletions(-) diff --git a/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AndroidPage.java b/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AndroidPage.java index 4658ab3c..6088e873 100644 --- a/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AndroidPage.java +++ b/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AndroidPage.java @@ -14,10 +14,11 @@ package solutions.bellatrix.android.pages; import solutions.bellatrix.android.services.App; +import solutions.bellatrix.core.utilities.PageObjectModel; import java.lang.reflect.ParameterizedType; -public abstract class AndroidPage> { +public abstract class AndroidPage> implements PageObjectModel { public App app() { return new App(); } diff --git a/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AppSection.java b/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AppSection.java index 7478aaa7..63301531 100644 --- a/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AppSection.java +++ b/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AppSection.java @@ -14,10 +14,11 @@ package solutions.bellatrix.android.pages; import solutions.bellatrix.android.services.App; +import solutions.bellatrix.core.utilities.PageObjectModel; import java.lang.reflect.ParameterizedType; -public abstract class AppSection> { +public abstract class AppSection> implements PageObjectModel { public App app() { return new App(); } diff --git a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java index 577f6429..5750dbbc 100644 --- a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java +++ b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java @@ -1,4 +1,8 @@ package solutions.bellatrix.core.utilities; -public interface PageObjectModel { + +public interface PageObjectModel { + MapT map(); + + AssertsT asserts(); } diff --git a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java index 0ed223e3..ca2e196d 100644 --- a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java +++ b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java @@ -19,7 +19,7 @@ import java.lang.reflect.ParameterizedType; -public abstract class AppSection> implements PageObjectModel { +public abstract class AppSection> implements PageObjectModel { public AppService browser() { return new AppService(); } diff --git a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java index aa82bc8e..805589da 100644 --- a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java +++ b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java @@ -19,7 +19,7 @@ import java.lang.reflect.ParameterizedType; -public abstract class DesktopPage> implements PageObjectModel { +public abstract class DesktopPage> implements PageObjectModel { public AppService appService() { return new AppService(); } diff --git a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java index 1d643c7a..c0227ad0 100644 --- a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java +++ b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java @@ -19,7 +19,7 @@ import java.lang.reflect.ParameterizedType; -public abstract class AppSection> implements PageObjectModel { +public abstract class AppSection> implements PageObjectModel { public AppService browser() { return new AppService(); } diff --git a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java index b2d22bcd..816b46d6 100644 --- a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java +++ b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java @@ -19,7 +19,7 @@ import java.lang.reflect.ParameterizedType; -public abstract class IOSPage> implements PageObjectModel { +public abstract class IOSPage> implements PageObjectModel { public AppService appService() { return new AppService(); } diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java index 66c3d64a..36a9934a 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java @@ -21,7 +21,7 @@ import solutions.bellatrix.playwright.services.ComponentCreateService; import solutions.bellatrix.playwright.services.NavigationService; -public abstract class WebPage> implements PageObjectModel { +public abstract class WebPage> implements PageObjectModel { public ComponentCreateService create() { return SingletonFactory.getInstance(ComponentCreateService.class); } diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java index 954fa387..cf7b021d 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java @@ -18,7 +18,7 @@ import solutions.bellatrix.core.utilities.SingletonFactory; import solutions.bellatrix.playwright.services.BrowserService; import solutions.bellatrix.playwright.services.ComponentCreateService; -public abstract class WebSection> implements PageObjectModel { +public abstract class WebSection> implements PageObjectModel { public BrowserService browser() { return SingletonFactory.getInstance(BrowserService.class); } diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java index c60e7b7f..61bdde6d 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java @@ -23,7 +23,7 @@ import java.lang.reflect.ParameterizedType; -public abstract class WebPage> implements PageObjectModel { +public abstract class WebPage> implements PageObjectModel { public BrowserService browser() { return new BrowserService(); } diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java index d0421c71..c8b4944d 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java @@ -19,7 +19,7 @@ import java.lang.reflect.ParameterizedType; -public abstract class WebSection> implements PageObjectModel { +public abstract class WebSection> implements PageObjectModel { public BrowserService browser() { return new BrowserService(); } From 782e41d208c3f416fa4b9807da05ad576efdb98a Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Tue, 26 Nov 2024 09:27:35 +0200 Subject: [PATCH 07/13] Added default difference tolerance to vrt plugin settings --- .../plugins/vrt/VisualRegressionAssertions.java | 9 +++++++-- .../bellatrix/plugins/vrt/VisualRegressionService.java | 7 +++++-- .../bellatrix/plugins/vrt/VisualRegressionSettings.java | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java index caedd48e..5fd8da61 100644 --- a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java @@ -17,18 +17,23 @@ import io.visual_regression_tracker.sdk_java.TestRunStatus; import lombok.experimental.UtilityClass; import org.junit.jupiter.api.Assertions; +import solutions.bellatrix.core.configuration.ConfigurationService; import solutions.bellatrix.core.utilities.PageObjectModel; @UtilityClass public class VisualRegressionAssertions { + private static float defaultDiffTolerance() { + return ConfigurationService.get(VisualRegressionSettings.class).getDefaultDiffTolerance(); + } + public static void assertSameAsBaseline(String name, String... testCasesName) { - TestRunResult result = VisualRegressionService.track(name + String.join(" ", testCasesName), 0.01f); + TestRunResult result = VisualRegressionService.track(name + String.join(" ", testCasesName), defaultDiffTolerance()); Assertions.assertSame(result.getTestRunResponse().getStatus(), TestRunStatus.OK, String.format("Visual comparison has detected a difference at: %s", result.getTestRunResponse().getUrl())); } public static void assertSameAsBaseline(String name, String screenshot, String... testCasesName) { - TestRunResult result = VisualRegressionService.track(name + String.join(" ", testCasesName), 0.01f, screenshot); + TestRunResult result = VisualRegressionService.track(name + String.join(" ", testCasesName), defaultDiffTolerance(), screenshot); Assertions.assertSame(result.getTestRunResponse().getStatus(), TestRunStatus.OK, String.format("Visual comparison has detected a difference at: %s", result.getTestRunResponse().getUrl())); } diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java index a5bc23dd..42862ed7 100644 --- a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java @@ -17,7 +17,6 @@ import io.visual_regression_tracker.sdk_java.TestRunResult; import io.visual_regression_tracker.sdk_java.VisualRegressionTracker; import io.visual_regression_tracker.sdk_java.VisualRegressionTrackerConfig; -import lombok.experimental.UtilityClass; import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.core.configuration.ConfigurationService; import solutions.bellatrix.core.utilities.SingletonFactory; @@ -26,6 +25,10 @@ import java.util.Objects; public class VisualRegressionService { + private static float defaultDiffTolerance() { + return ConfigurationService.get(VisualRegressionSettings.class).getDefaultDiffTolerance(); + } + private static final ThreadLocal VISUAL_REGRESSION_TRACKER_THREAD_LOCAL; private static final ThreadLocal VISUAL_REGRESSION_ATTRIBUTE; @@ -71,7 +74,7 @@ public static TestRunResult track(String name, Float diffTolerance) { } public static TestRunResult track(String name) { - return track(name, 0.000f); + return track(name, defaultDiffTolerance()); } public static String takeSnapshot(String name) { diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionSettings.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionSettings.java index ac661b6d..4891e569 100644 --- a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionSettings.java +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionSettings.java @@ -26,4 +26,5 @@ public class VisualRegressionSettings { private boolean enableSoftAssert; private String ciBuildId; private int httpTimeout; + private float defaultDiffTolerance; } From d877eb992c25c3f78965879a6739d06c3fb4e53e Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Tue, 26 Nov 2024 10:09:57 +0200 Subject: [PATCH 08/13] Update Selenium from 4.11.0 to 4.26.0 The old version doesn't always properly release resources. With the update, this anomaly doesn't occur anymore. --- bellatrix.core/pom.xml | 2 +- .../solutions/bellatrix/web/infrastructure/ProxyServer.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bellatrix.core/pom.xml b/bellatrix.core/pom.xml index 667a658e..e585f30d 100644 --- a/bellatrix.core/pom.xml +++ b/bellatrix.core/pom.xml @@ -24,7 +24,7 @@ 1.0 - 4.11.0 + 4.26.0 8.3.0 7.7.0 5.9.2 diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/ProxyServer.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/ProxyServer.java index f9461bc6..4c7b873d 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/ProxyServer.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/ProxyServer.java @@ -19,7 +19,6 @@ import net.lightbody.bmp.core.har.HarEntry; import net.lightbody.bmp.proxy.CaptureType; import org.apache.http.HttpStatus; -import org.asynchttpclient.uri.Uri; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.http.HttpMethod; @@ -33,6 +32,7 @@ import java.io.IOException; import java.lang.reflect.Type; import java.net.ServerSocket; +import java.net.URI; import java.time.Duration; import java.time.LocalDateTime; import java.time.OffsetDateTime; @@ -178,7 +178,7 @@ private static String getSimilarRequestsString(String requestPartialUrl, List allUrls = new ArrayList<>(); allHarEntries.stream().forEach(e -> { - Uri uri = Uri.create(requestPartialUrl); + URI uri = URI.create(requestPartialUrl); if(e.getRequest().getUrl().contains(uri.getHost()) || e.getRequest().getUrl().contains(requestPartialUrl)){ allUrls.add(String.format("[%s]%s[%s]", e.getRequest().getMethod(), e.getRequest().getUrl(), e.getResponse().getStatusText())); } From b28908baa25725e0224614677d279e227e20f4ab Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Tue, 17 Dec 2024 18:18:31 +0200 Subject: [PATCH 09/13] fixes --- .../plugins/vrt/VisualRegressionService.java | 17 +++++++++-------- .../plugins/vrt/VisualRegressionSettings.java | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java index 42862ed7..ad660a35 100644 --- a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java @@ -22,20 +22,17 @@ import solutions.bellatrix.core.utilities.SingletonFactory; import java.io.IOException; -import java.util.Objects; public class VisualRegressionService { - private static float defaultDiffTolerance() { - return ConfigurationService.get(VisualRegressionSettings.class).getDefaultDiffTolerance(); - } + private static final float DEFAULT_DIFF_TOLERANCE = ConfigurationService.get(VisualRegressionSettings.class).getDefaultDiffTolerance(); private static final ThreadLocal VISUAL_REGRESSION_TRACKER_THREAD_LOCAL; private static final ThreadLocal VISUAL_REGRESSION_ATTRIBUTE; static { try { - VISUAL_REGRESSION_TRACKER_THREAD_LOCAL = new ThreadLocal<>(); - VISUAL_REGRESSION_ATTRIBUTE = new ThreadLocal<>(); + VISUAL_REGRESSION_TRACKER_THREAD_LOCAL = ThreadLocal.withInitial(() -> null); + VISUAL_REGRESSION_ATTRIBUTE = ThreadLocal.withInitial(() -> null); } catch (Exception e) { throw new RuntimeException("Failed to initialize VisualRegressionService", e); } @@ -74,12 +71,16 @@ public static TestRunResult track(String name, Float diffTolerance) { } public static TestRunResult track(String name) { - return track(name, defaultDiffTolerance()); + return track(name, DEFAULT_DIFF_TOLERANCE); } public static String takeSnapshot(String name) { var screenshotPlugin = SingletonFactory.getInstance(ScreenshotPlugin.class); - return Objects.requireNonNull(screenshotPlugin).takeScreenshot(name); + if (screenshotPlugin == null) { + throw new IllegalArgumentException("It seems that the screenshot plugin isn't registered by the 'ScreenshotPlugin.class' key inside SingletonFactory's map or isn't registered at all!"); + } + + return screenshotPlugin.takeScreenshot(name); } public static TestRunOptions buildRunOptions(Float diffTolerance) { diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionSettings.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionSettings.java index 4891e569..07205757 100644 --- a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionSettings.java +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionSettings.java @@ -13,11 +13,12 @@ package solutions.bellatrix.plugins.vrt; +import lombok.Data; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -@Getter @Setter @NoArgsConstructor +@Data public class VisualRegressionSettings { private String apiUrl; private String apiKey; From ca5403c362ca6e4a49efb5748f5ce0150cdededc Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Tue, 17 Dec 2024 18:25:52 +0200 Subject: [PATCH 10/13] Moved map() and asserts() methods' implementation of POMs to PageObjectModel.java --- .../bellatrix/android/pages/AndroidPage.java | 18 --------------- .../bellatrix/android/pages/AppSection.java | 18 --------------- .../core/utilities/PageObjectModel.java | 22 ++++++++++++++++--- .../bellatrix/desktop/pages/AppSection.java | 18 --------------- .../bellatrix/desktop/pages/DesktopPage.java | 18 --------------- .../bellatrix/ios/pages/AppSection.java | 18 --------------- .../bellatrix/ios/pages/IOSPage.java | 18 --------------- .../bellatrix/playwright/pages/WebPage.java | 8 ------- .../playwright/pages/WebSection.java | 8 ------- .../bellatrix/web/pages/WebPage.java | 18 --------------- .../bellatrix/web/pages/WebSection.java | 18 --------------- 11 files changed, 19 insertions(+), 163 deletions(-) diff --git a/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AndroidPage.java b/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AndroidPage.java index 6088e873..4ca596ac 100644 --- a/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AndroidPage.java +++ b/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AndroidPage.java @@ -22,22 +22,4 @@ public abstract class AndroidPage)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - return elementsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } - - public AssertsT asserts() { - try { - var assertionsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[1]; - return assertionsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } } diff --git a/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AppSection.java b/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AppSection.java index 63301531..37faf026 100644 --- a/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AppSection.java +++ b/bellatrix.android/src/main/java/solutions/bellatrix/android/pages/AppSection.java @@ -22,22 +22,4 @@ public abstract class AppSection)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - return elementsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } - - public AssertionsT asserts() { - try { - var assertionsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[1]; - return assertionsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } } diff --git a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java index 5750dbbc..2420fea2 100644 --- a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java +++ b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java @@ -1,8 +1,24 @@ -package solutions.bellatrix.core.utilities; +/* + * Copyright 2024 Automate The Planet Ltd. + * Author: Miriam Kyoseva + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package solutions.bellatrix.core.utilities; public interface PageObjectModel { - MapT map(); + default MapT map() { + return InstanceFactory.createByTypeParameter(this.getClass(), 0); + } - AssertsT asserts(); + default AssertsT asserts() { + return InstanceFactory.createByTypeParameter(this.getClass(), 1); + } } diff --git a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java index ca2e196d..2571fd1b 100644 --- a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java +++ b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/AppSection.java @@ -27,22 +27,4 @@ public AppService browser() { public ComponentCreateService create() { return new ComponentCreateService(); } - - public MapT map() { - try { - var elementsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - return elementsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } - - public AssertionsT asserts() { - try { - var assertionsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[1]; - return assertionsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } } diff --git a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java index 805589da..5c20bae1 100644 --- a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java +++ b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/pages/DesktopPage.java @@ -27,22 +27,4 @@ public AppService appService() { public ComponentCreateService create() { return new ComponentCreateService(); } - - public MapT map() { - try { - var elementsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - return elementsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } - - public AssertsT asserts() { - try { - var assertionsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[1]; - return assertionsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } } diff --git a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java index c0227ad0..73d6c0e7 100644 --- a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java +++ b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/AppSection.java @@ -27,22 +27,4 @@ public AppService browser() { public ComponentCreateService create() { return new ComponentCreateService(); } - - public MapT map() { - try { - var elementsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - return elementsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } - - public AssertionsT asserts() { - try { - var assertionsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[1]; - return assertionsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } } diff --git a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java index 816b46d6..8220e313 100644 --- a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java +++ b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/pages/IOSPage.java @@ -27,22 +27,4 @@ public AppService appService() { public ComponentCreateService create() { return new ComponentCreateService(); } - - public MapT map() { - try { - var elementsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - return elementsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } - - public AssertsT asserts() { - try { - var assertionsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[1]; - return assertionsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } } diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java index 36a9934a..7aff8578 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java @@ -33,14 +33,6 @@ public App app() { return SingletonFactory.getInstance(App.class); } - public MapT map() { - return InstanceFactory.createByTypeParameter(this.getClass(), 0); - } - - public AssertionsT asserts() { - return InstanceFactory.createByTypeParameter(this.getClass(), 1); - } - public NavigationService navigate() { return SingletonFactory.getInstance(NavigationService.class); } diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java index cf7b021d..042026d5 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java @@ -26,12 +26,4 @@ public BrowserService browser() { public ComponentCreateService create() { return SingletonFactory.getInstance(ComponentCreateService.class); } - - public MapT map() { - return InstanceFactory.createByTypeParameter(this.getClass(), 0); - } - - public AssertionsT asserts() { - return InstanceFactory.createByTypeParameter(this.getClass(), 1); - } } diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java index 61bdde6d..4c2ceaad 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebPage.java @@ -40,24 +40,6 @@ public App app() { return new App(); } - public MapT map() { - try { - var elementsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - return elementsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } - - public AssertsT asserts() { - try { - var assertionsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[1]; - return assertionsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } - public NavigationService navigate() { return new NavigationService(); } diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java index c8b4944d..2412f601 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/pages/WebSection.java @@ -27,22 +27,4 @@ public BrowserService browser() { public ComponentCreateService create() { return new ComponentCreateService(); } - - public MapT map() { - try { - var elementsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - return elementsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } - - public AssertionsT asserts() { - try { - var assertionsClass = (Class)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[1]; - return assertionsClass.getDeclaredConstructor().newInstance(); - } catch (Exception e) { - return null; - } - } } From e904566131dcdbe41d7e75200bb103c09746af56 Mon Sep 17 00:00:00 2001 From: MiriamKyoseva <133047546+MiriamKyoseva@users.noreply.github.com> Date: Thu, 19 Dec 2024 13:43:54 +0200 Subject: [PATCH 11/13] Rename addPluginWithKey to addPluginAs --- .../bellatrix/android/infrastructure/junit/AndroidTest.java | 3 +-- .../bellatrix/android/infrastructure/testng/AndroidTest.java | 2 +- .../java/solutions/bellatrix/core/plugins/UsesPlugins.java | 2 +- .../bellatrix/desktop/infrastructure/junit/DesktopTest.java | 2 +- .../bellatrix/desktop/infrastructure/testng/DesktopTest.java | 2 +- .../solutions/bellatrix/ios/infrastructure/junit/IOSTest.java | 2 +- .../solutions/bellatrix/ios/infrastructure/testng/IOSTest.java | 2 +- .../bellatrix/playwright/infrastructure/junit/WebTest.java | 2 +- .../bellatrix/playwright/infrastructure/testng/WebTest.java | 2 +- .../solutions/bellatrix/web/infrastructure/junit/WebTest.java | 2 +- .../solutions/bellatrix/web/infrastructure/testng/WebTest.java | 2 +- 11 files changed, 11 insertions(+), 12 deletions(-) diff --git a/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/junit/AndroidTest.java b/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/junit/AndroidTest.java index 150c15e1..bff09573 100644 --- a/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/junit/AndroidTest.java +++ b/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/junit/AndroidTest.java @@ -17,7 +17,6 @@ import plugins.screenshots.ScreenshotPlugin; import solutions.bellatrix.android.components.listeners.BddLogging; import solutions.bellatrix.android.infrastructure.AppLifecyclePlugin; -import solutions.bellatrix.android.infrastructure.DownloadDemoAppsPlugin; import solutions.bellatrix.android.infrastructure.MobileScreenshotPlugin; import solutions.bellatrix.android.infrastructure.MobileVideoPlugin; import solutions.bellatrix.android.services.App; @@ -34,7 +33,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPluginWithKey(ScreenshotPlugin.class, MobileScreenshotPlugin.class); + addPluginAs(ScreenshotPlugin.class, MobileScreenshotPlugin.class); addPlugin(MobileVideoPlugin.class); //addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/testng/AndroidTest.java b/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/testng/AndroidTest.java index db2550b3..d2188da8 100644 --- a/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/testng/AndroidTest.java +++ b/bellatrix.android/src/main/java/solutions/bellatrix/android/infrastructure/testng/AndroidTest.java @@ -31,7 +31,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPluginWithKey(ScreenshotPlugin.class, MobileScreenshotPlugin.class); + addPluginAs(ScreenshotPlugin.class, MobileScreenshotPlugin.class); addPlugin(MobileVideoPlugin.class); addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/UsesPlugins.java b/bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/UsesPlugins.java index 1a144a85..1a19de78 100644 --- a/bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/UsesPlugins.java +++ b/bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/UsesPlugins.java @@ -9,7 +9,7 @@ public void addPlugin(Class plugin, Object... args) { PluginExecutionEngine.addPlugin(SingletonFactory.getInstance(plugin, args)); } - public void addPluginWithKey(Class key, Class plugin, Object... args) { + public void addPluginAs(Class key, Class plugin, Object... args) { var instance = SingletonFactory.getInstance(plugin, args); SingletonFactory.register(key, instance); PluginExecutionEngine.addPlugin(instance); diff --git a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/junit/DesktopTest.java b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/junit/DesktopTest.java index a98f777b..40f0566d 100644 --- a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/junit/DesktopTest.java +++ b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/junit/DesktopTest.java @@ -31,7 +31,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPluginWithKey(ScreenshotPlugin.class, DesktopScreenshotPlugin.class); + addPluginAs(ScreenshotPlugin.class, DesktopScreenshotPlugin.class); addPlugin(DesktopVideoPlugin.class); addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/testng/DesktopTest.java b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/testng/DesktopTest.java index 0e516046..9822fd80 100644 --- a/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/testng/DesktopTest.java +++ b/bellatrix.desktop/src/main/java/solutions/bellatrix/desktop/infrastructure/testng/DesktopTest.java @@ -31,7 +31,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPluginWithKey(ScreenshotPlugin.class, DesktopScreenshotPlugin.class); + addPluginAs(ScreenshotPlugin.class, DesktopScreenshotPlugin.class); addPlugin(DesktopVideoPlugin.class); addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/junit/IOSTest.java b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/junit/IOSTest.java index eede942e..dc72f4c3 100644 --- a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/junit/IOSTest.java +++ b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/junit/IOSTest.java @@ -30,7 +30,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPluginWithKey(ScreenshotPlugin.class, MobileScreenshotPlugin.class); + addPluginAs(ScreenshotPlugin.class, MobileScreenshotPlugin.class); addPlugin(MobileVideoPlugin.class); addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/testng/IOSTest.java b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/testng/IOSTest.java index 6fa84034..96ea2e75 100644 --- a/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/testng/IOSTest.java +++ b/bellatrix.ios/src/main/java/solutions/bellatrix/ios/infrastructure/testng/IOSTest.java @@ -30,7 +30,7 @@ public App app() { @Override protected void configure() { addPlugin(AppLifecyclePlugin.class); - addPluginWithKey(ScreenshotPlugin.class, MobileScreenshotPlugin.class); + addPluginAs(ScreenshotPlugin.class, MobileScreenshotPlugin.class); addPlugin(MobileVideoPlugin.class); addPlugin(DownloadDemoAppsPlugin.class); addListener(BddLogging.class); diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/junit/WebTest.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/junit/WebTest.java index b9a21984..78bae81e 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/junit/WebTest.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/junit/WebTest.java @@ -36,7 +36,7 @@ public App app() { @Override protected void configure() { addPlugin(BrowserLifecyclePlugin.class); - addPluginWithKey(ScreenshotPlugin.class, WebScreenshotPlugin.class); + addPluginAs(ScreenshotPlugin.class, WebScreenshotPlugin.class); addPlugin(WebVideoPlugin.class); addPlugin(LogLifecyclePlugin.class); addListener(BddConsoleLogging.class); diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/testng/WebTest.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/testng/WebTest.java index 0591ec94..e9f49a2e 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/testng/WebTest.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/infrastructure/testng/WebTest.java @@ -32,7 +32,7 @@ public App app() { @Override protected void configure() { addPlugin(BrowserLifecyclePlugin.class); - addPluginWithKey(ScreenshotPlugin.class, WebScreenshotPlugin.class); + addPluginAs(ScreenshotPlugin.class, WebScreenshotPlugin.class); addPlugin(WebVideoPlugin.class); addPlugin(LogLifecyclePlugin.class); addListener(BddConsoleLogging.class); diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/junit/WebTest.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/junit/WebTest.java index cc98ec8d..0d0e44ec 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/junit/WebTest.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/junit/WebTest.java @@ -37,7 +37,7 @@ public App app() { @Override protected void configure() { addPlugin(BrowserLifecyclePlugin.class); - addPluginWithKey(ScreenshotPlugin.class, WebScreenshotPlugin.class); + addPluginAs(ScreenshotPlugin.class, WebScreenshotPlugin.class); addPlugin(WebVideoPlugin.class); addPlugin(LogLifecyclePlugin.class); addListener(BddConsoleLogging.class); diff --git a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/testng/WebTest.java b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/testng/WebTest.java index d7d41790..a67a81f0 100644 --- a/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/testng/WebTest.java +++ b/bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/testng/WebTest.java @@ -33,7 +33,7 @@ public App app() { @Override protected void configure() { addPlugin(BrowserLifecyclePlugin.class); - addPluginWithKey(ScreenshotPlugin.class, WebScreenshotPlugin.class); + addPluginAs(ScreenshotPlugin.class, WebScreenshotPlugin.class); addPlugin(WebVideoPlugin.class); addPlugin(LogLifecyclePlugin.class); addListener(BddConsoleLogging.class); From e80822bcbbab99ff6165abb69414b53221c2b9e3 Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Thu, 23 Jan 2025 16:09:51 +0200 Subject: [PATCH 12/13] changes due to merging --- .../core/utilities/PageObjectModel.java | 24 ------------------- .../bellatrix/playwright/pages/WebPage.java | 2 -- .../playwright/pages/WebSection.java | 3 +-- .../vrt/VisualRegressionAssertions.java | 2 +- 4 files changed, 2 insertions(+), 29 deletions(-) delete mode 100644 bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java diff --git a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java b/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java deleted file mode 100644 index 2420fea2..00000000 --- a/bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/PageObjectModel.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2024 Automate The Planet Ltd. - * Author: Miriam Kyoseva - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package solutions.bellatrix.core.utilities; - -public interface PageObjectModel { - default MapT map() { - return InstanceFactory.createByTypeParameter(this.getClass(), 0); - } - - default AssertsT asserts() { - return InstanceFactory.createByTypeParameter(this.getClass(), 1); - } -} diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java index e3ae0a86..963ec93b 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebPage.java @@ -14,8 +14,6 @@ package solutions.bellatrix.playwright.pages; import solutions.bellatrix.core.infrastructure.PageObjectModel; -import solutions.bellatrix.core.utilities.InstanceFactory; -import solutions.bellatrix.core.utilities.PageObjectModel; import solutions.bellatrix.core.utilities.SingletonFactory; import solutions.bellatrix.playwright.services.App; import solutions.bellatrix.playwright.services.BrowserService; diff --git a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java index b2bb6961..b958696f 100644 --- a/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java +++ b/bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/pages/WebSection.java @@ -14,11 +14,10 @@ package solutions.bellatrix.playwright.pages; import solutions.bellatrix.core.infrastructure.PageObjectModel; -import solutions.bellatrix.core.utilities.InstanceFactory; -import solutions.bellatrix.core.utilities.PageObjectModel; import solutions.bellatrix.core.utilities.SingletonFactory; import solutions.bellatrix.playwright.services.BrowserService; import solutions.bellatrix.playwright.services.ComponentCreateService; + public abstract class WebSection> implements PageObjectModel { public BrowserService browser() { return SingletonFactory.getInstance(BrowserService.class); diff --git a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java index 5fd8da61..e6d21c5c 100644 --- a/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java +++ b/bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionAssertions.java @@ -18,7 +18,7 @@ import lombok.experimental.UtilityClass; import org.junit.jupiter.api.Assertions; import solutions.bellatrix.core.configuration.ConfigurationService; -import solutions.bellatrix.core.utilities.PageObjectModel; +import solutions.bellatrix.core.infrastructure.PageObjectModel; @UtilityClass public class VisualRegressionAssertions { From 56a935fee4731d7620a8fd71d115079fca8ff8d5 Mon Sep 17 00:00:00 2001 From: MiriamKyoseva Date: Thu, 23 Jan 2025 16:14:38 +0200 Subject: [PATCH 13/13] update playwright dependency version 1.44.0 -> 1.49.0 --- bellatrix.playwright/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bellatrix.playwright/pom.xml b/bellatrix.playwright/pom.xml index 1cceb608..ef684b0d 100644 --- a/bellatrix.playwright/pom.xml +++ b/bellatrix.playwright/pom.xml @@ -21,7 +21,7 @@ com.microsoft.playwright playwright - 1.44.0 + 1.49.0 org.junit.jupiter