Skip to content

Commit 4371db7

Browse files
authored
Merge pull request #61 from AutomateThePlanet/vrt-getting-started
VRT getting started
2 parents 57a8fcc + c306fe6 commit 4371db7

File tree

14 files changed

+222
-0
lines changed

14 files changed

+222
-0
lines changed

bellatrix.playwright/src/main/java/solutions/bellatrix/playwright/services/NavigationService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
package solutions.bellatrix.playwright.services;
1515

1616
import com.google.common.base.Strings;
17+
import lombok.SneakyThrows;
1718
import solutions.bellatrix.core.utilities.SingletonFactory;
19+
import solutions.bellatrix.playwright.pages.WebPage;
1820

21+
import java.lang.reflect.Method;
1922
import java.net.MalformedURLException;
2023
import java.net.URL;
2124
import java.net.URLDecoder;
@@ -28,6 +31,13 @@
2831

2932
@SuppressWarnings("ALL")
3033
public class NavigationService extends WebService {
34+
@SneakyThrows
35+
public void to(WebPage page) {
36+
Method method = page.getClass().getDeclaredMethod("getUrl");
37+
method.setAccessible(true);
38+
wrappedBrowser().getCurrentPage().navigate((String)method.invoke(page));
39+
}
40+
3141
public void to(String url) {
3242
wrappedBrowser().getCurrentPage().navigate(url);
3343
}

bellatrix.plugins.visual-regression-tracker/src/main/java/solutions/bellatrix/plugins/vrt/VisualRegressionService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public static TestRunResult track(String name) {
7676

7777
public static String takeSnapshot(String name) {
7878
var screenshotPlugin = SingletonFactory.getInstance(ScreenshotPlugin.class);
79+
7980
if (screenshotPlugin == null) {
8081
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!");
8182
}

bellatrix.web/src/main/java/solutions/bellatrix/web/services/NavigationService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
package solutions.bellatrix.web.services;
1515

1616
import com.google.common.base.Strings;
17+
import lombok.SneakyThrows;
1718
import org.openqa.selenium.TimeoutException;
1819
import org.openqa.selenium.support.ui.WebDriverWait;
1920
import solutions.bellatrix.core.configuration.ConfigurationService;
2021
import solutions.bellatrix.web.configuration.WebSettings;
22+
import solutions.bellatrix.web.pages.WebPage;
2123

24+
import java.lang.reflect.Method;
2225
import java.net.MalformedURLException;
2326
import java.net.URL;
2427
import java.net.URLDecoder;
@@ -37,6 +40,14 @@ public void to(String url) {
3740
getWrappedDriver().navigate().to(url);
3841
}
3942

43+
@SneakyThrows
44+
public void to(WebPage page) {
45+
Method method = page.getClass().getDeclaredMethod("getUrl");
46+
method.setAccessible(true);
47+
48+
getWrappedDriver().navigate().to((String)method.invoke(page));
49+
}
50+
4051
public void toLocalPage(String filePath) {
4152
URL testAppUrl = Thread.currentThread().getContextClassLoader().getResource(filePath);
4253
if (testAppUrl != null) {

getting-started/bellatrix.playwright.getting.started/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
<version>1.0</version>
4646
<scope>compile</scope>
4747
</dependency>
48+
<dependency>
49+
<groupId>solutions.bellatrix</groupId>
50+
<artifactId>bellatrix.plugins.visual-regression-tracker</artifactId>
51+
<version>1.0-SNAPSHOT</version>
52+
<scope>test</scope>
53+
</dependency>
4854
</dependencies>
4955

5056
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package O25_visual_regression_tracker;
2+
3+
import O25_visual_regression_tracker.data.MobileServicePage;
4+
import org.junit.jupiter.api.Test;
5+
import solutions.bellatrix.playwright.infrastructure.junit.WebTest;
6+
import solutions.bellatrix.plugins.vrt.VisualRegression;
7+
import solutions.bellatrix.plugins.vrt.VisualRegressionAssertions;
8+
import solutions.bellatrix.plugins.vrt.VisualRegressionPlugin;
9+
/*
10+
To begin tracking visual regression with BELLATRIX, one must have this in the config file:
11+
"visualRegressionSettings": {
12+
"apiUrl": "", (REQUIRED)
13+
"apiKey": "", (REQUIRED)
14+
"project": "", (REQUIRED)
15+
"branch": "vrt", (REQUIRED)
16+
"enableSoftAssert": "true", (REQUIRED)
17+
"ciBuildId": "vrt", (REQUIRED)
18+
"httpTimeout": "15", (REQUIRED)
19+
"defaultDiffTolerance": "0.1" (REQUIRED)
20+
}
21+
22+
These settings are all required to start. After we have set them, we can then begin.
23+
*/
24+
25+
// To mark a test class for visual regression, we simply use @VisualRegression annotation
26+
// One can also provide the VRT project name and the resolution, otherwise default values will be used
27+
@VisualRegression
28+
public class VisualRegressionTests extends WebTest {
29+
protected void configure() {
30+
super.configure();
31+
addPlugin(VisualRegressionPlugin.class);
32+
33+
// it is also important to have the screenshot plugin registered as the base class
34+
// addPluginAs(ScreenshotPlugin.class, WebScreenshotPlugin.class);
35+
// check in your base test if it is registered as that
36+
}
37+
// We need @VisualRegression annotation so that the tracker process could start at the beginning of the test
38+
// and be ready for use in said test.
39+
// After the test is over, the tracker is closed.
40+
41+
@Test
42+
public void visualRegressionTest_using_assertions() {
43+
app().navigate().to("https://www.automatetheplanet.com/services/web-automation/");
44+
45+
VisualRegressionAssertions.assertSameAsBaseline("web-automation-service-page");
46+
// This is the simplest way to start using VRT: by inserting a visual regression assertion method
47+
// here, the name required is the name of the baseline
48+
}
49+
50+
@Test
51+
@VisualRegression // If only one of our tests is for visual regression tracking,
52+
// the @VisualRegression annotation can be used on the method instead
53+
public void visualRegressionTest_using_assertByPageObjectModel() {
54+
var mobileServicePage = new MobileServicePage();
55+
56+
app().navigate().to(mobileServicePage);
57+
58+
// If our baseline has the same name as the POM, we can just pass the POM.
59+
VisualRegressionAssertions.assertSameAsBaseline(mobileServicePage);
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package O25_visual_regression_tracker.data;
2+
3+
import solutions.bellatrix.playwright.pages.PageAsserts;
4+
5+
public class MobileServiceAssertions extends PageAsserts<MobileServiceMap> {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package O25_visual_regression_tracker.data;
2+
3+
import solutions.bellatrix.playwright.components.Div;
4+
import solutions.bellatrix.playwright.pages.PageMap;
5+
6+
public class MobileServiceMap extends PageMap {
7+
public Div rightPeopleSection() {
8+
return app().create().byId(Div.class, "right-people-section bottom-40");
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package O25_visual_regression_tracker.data;
2+
3+
import solutions.bellatrix.playwright.pages.WebPage;
4+
5+
public class MobileServicePage extends WebPage<MobileServiceMap, MobileServiceAssertions> {
6+
@Override
7+
public String getUrl() {
8+
return "https://www.automatetheplanet.com/services/mobile-automation/";
9+
}
10+
}

getting-started/bellatrix.web.getting.started/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
<version>5.9.2</version>
5151
<scope>test</scope>
5252
</dependency>
53+
<dependency>
54+
<groupId>solutions.bellatrix</groupId>
55+
<artifactId>bellatrix.plugins.visual-regression-tracker</artifactId>
56+
<version>1.0-SNAPSHOT</version>
57+
<scope>test</scope>
58+
</dependency>
5359
</dependencies>
5460

5561
</project>

getting-started/bellatrix.web.getting.started/src/main/resources/testFrameworkSettings.dev.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
"troubleshootingSettings": {
33
"debugInformationEnabled": "true"
44
},
5+
"visualRegressionSettings": {
6+
"apiUrl": "http://localhost:4200",
7+
"apiKey": "DEFAULTUSERAPIKEYTOBECHANGED",
8+
"project": "vrt",
9+
"branch": "bellatrix-tests",
10+
"enableSoftAssert": "true",
11+
"ciBuildId": "local-automation-run",
12+
"httpTimeout": "15",
13+
"defaultDiffTolerance": "0.1"
14+
},
515
"webSettings": {
616
"baseUrl": "http://demos.bellatrix.solutions/",
717
"executionType":"regular",
@@ -17,6 +27,7 @@
1727
"screenshotsSaveLocation": "${user.home}/BELLATRIX/Screenshots",
1828
"videosOnFailEnabled": "false",
1929
"videosSaveLocation": "${user.home}/BELLATRIX/Videos",
30+
"toastNotificationBddLogging": "false",
2031
"timeoutSettings": {
2132
"elementWaitTimeout": "30",
2233
"pageLoadTimeout": "30",

0 commit comments

Comments
 (0)