Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
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;
import solutions.bellatrix.android.infrastructure.MobileScreenshotPlugin;
import solutions.bellatrix.android.infrastructure.MobileVideoPlugin;
import solutions.bellatrix.android.services.App;
Expand All @@ -33,7 +33,7 @@ public App app() {
@Override
protected void configure() {
addPlugin(AppLifecyclePlugin.class);
addPlugin(MobileScreenshotPlugin.class);
addPluginAs(ScreenshotPlugin.class, MobileScreenshotPlugin.class);
addPlugin(MobileVideoPlugin.class);
//addPlugin(DownloadDemoAppsPlugin.class);
addListener(BddLogging.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +31,7 @@ public App app() {
@Override
protected void configure() {
addPlugin(AppLifecyclePlugin.class);
addPlugin(MobileScreenshotPlugin.class);
addPluginAs(ScreenshotPlugin.class, MobileScreenshotPlugin.class);
addPlugin(MobileVideoPlugin.class);
addPlugin(DownloadDemoAppsPlugin.class);
addListener(BddLogging.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public <T extends Plugin> void addPlugin(Class<T> plugin, Object... args) {
PluginExecutionEngine.addPlugin(SingletonFactory.getInstance(plugin, args));
}

public <T extends Plugin> void addPluginAs(Class key, Class<T> plugin, Object... args) {
var instance = SingletonFactory.getInstance(plugin, args);
SingletonFactory.register(key, instance);
PluginExecutionEngine.addPlugin(instance);
}

public <T extends Listener> void addListener(Class<T> listener, Object... args) {
Objects.requireNonNull(SingletonFactory.getInstance(listener, args)).addListener();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +31,7 @@ public App app() {
@Override
protected void configure() {
addPlugin(AppLifecyclePlugin.class);
addPlugin(DesktopScreenshotPlugin.class);
addPluginAs(ScreenshotPlugin.class, DesktopScreenshotPlugin.class);
addPlugin(DesktopVideoPlugin.class);
addPlugin(DownloadDemoAppsPlugin.class);
addListener(BddLogging.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +31,7 @@ public App app() {
@Override
protected void configure() {
addPlugin(AppLifecyclePlugin.class);
addPlugin(DesktopScreenshotPlugin.class);
addPluginAs(ScreenshotPlugin.class, DesktopScreenshotPlugin.class);
addPlugin(DesktopVideoPlugin.class);
addPlugin(DownloadDemoAppsPlugin.class);
addListener(BddLogging.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +30,7 @@ public App app() {
@Override
protected void configure() {
addPlugin(AppLifecyclePlugin.class);
addPlugin(MobileScreenshotPlugin.class);
addPluginAs(ScreenshotPlugin.class, MobileScreenshotPlugin.class);
addPlugin(MobileVideoPlugin.class);
addPlugin(DownloadDemoAppsPlugin.class);
addListener(BddLogging.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +30,7 @@ public App app() {
@Override
protected void configure() {
addPlugin(AppLifecyclePlugin.class);
addPlugin(MobileScreenshotPlugin.class);
addPluginAs(ScreenshotPlugin.class, MobileScreenshotPlugin.class);
addPlugin(MobileVideoPlugin.class);
addPlugin(DownloadDemoAppsPlugin.class);
addListener(BddLogging.class);
Expand Down
2 changes: 1 addition & 1 deletion bellatrix.playwright/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.44.0</version>
<version>1.49.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +36,7 @@ public App app() {
@Override
protected void configure() {
addPlugin(BrowserLifecyclePlugin.class);
addPlugin(WebScreenshotPlugin.class);
addPluginAs(ScreenshotPlugin.class, WebScreenshotPlugin.class);
addPlugin(WebVideoPlugin.class);
addPlugin(LogLifecyclePlugin.class);
addListener(BddConsoleLogging.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +32,7 @@ public App app() {
@Override
protected void configure() {
addPlugin(BrowserLifecyclePlugin.class);
addPlugin(WebScreenshotPlugin.class);
addPluginAs(ScreenshotPlugin.class, WebScreenshotPlugin.class);
addPlugin(WebVideoPlugin.class);
addPlugin(LogLifecyclePlugin.class);
addListener(BddConsoleLogging.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package solutions.bellatrix.playwright.pages;

import solutions.bellatrix.core.infrastructure.PageObjectModel;
import solutions.bellatrix.core.utilities.InstanceFactory;
import solutions.bellatrix.core.utilities.SingletonFactory;
import solutions.bellatrix.playwright.services.App;
import solutions.bellatrix.playwright.services.BrowserService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
package solutions.bellatrix.playwright.pages;

import solutions.bellatrix.core.infrastructure.PageObjectModel;
import solutions.bellatrix.core.utilities.InstanceFactory;
import solutions.bellatrix.core.utilities.SingletonFactory;
import solutions.bellatrix.playwright.services.BrowserService;
import solutions.bellatrix.playwright.services.ComponentCreateService;

public abstract class WebSection<MapT extends PageMap, AssertionsT extends PageAsserts<MapT>> implements PageObjectModel<MapT, AssertionsT> {
public BrowserService browser() {
return SingletonFactory.getInstance(BrowserService.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.configuration.ConfigurationService;
import solutions.bellatrix.core.infrastructure.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), 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), defaultDiffTolerance(), 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()));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading
Loading