Skip to content

Commit f2ca51c

Browse files
committed
getting started for visual regression tracker
1 parent d25bf97 commit f2ca51c

File tree

12 files changed

+201
-0
lines changed

12 files changed

+201
-0
lines changed

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
}

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

0 commit comments

Comments
 (0)