Skip to content

Commit a058ec1

Browse files
Combined UFG + Classic runner into one project
1 parent 0a73b64 commit a058ec1

File tree

3 files changed

+51
-34
lines changed

3 files changed

+51
-34
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# Applitools Example: Playwright Java JUnit with the Ultrafast Grid
1+
# Applitools Example: Playwright in Java with JUnit
22

33
This is the example project for the [Playwright Java tutorial](https://applitools.com/tutorials/quickstart/web/playwright/java).
44
It shows how to start automating visual tests
55
with [Applitools Eyes](https://applitools.com/platform/eyes/)
6-
and the [Ultrafast Grid](https://applitools.com/platform/ultrafast-grid/)
7-
using [Playwright](https://playwright.dev/java) in Java.
6+
and [Playwright](https://playwright.dev/java) in Java.
87

98
It uses:
109

@@ -14,6 +13,9 @@ It uses:
1413
* [Apache Maven](https://maven.apache.org/index.html) for dependency management
1514
* [JUnit 5](https://junit.org/junit5/) as the core test framework
1615
* [Applitools Eyes](https://applitools.com/platform/eyes/) for visual testing
16+
17+
It can also run tests with:
18+
1719
* [Applitools Ultrafast Grid](https://applitools.com/platform/ultrafast-grid/) for cross-browser execution
1820

1921
To run this example project, you'll need:
@@ -24,6 +26,8 @@ To run this example project, you'll need:
2426
4. [Apache Maven](https://maven.apache.org/download.cgi) (typically bundled with IDEs).
2527

2628
The main test case is [`AcmeBankTests.java`](src/test/java/com/applitools/example/AcmeBankTests.java).
29+
By default, the project will run tests with Ultrafast Grid.
30+
You can change these settings in the test class.
2731

2832
To execute tests, set the `APPLITOOLS_API_KEY` environment variable
2933
to your [account's API key](https://applitools.com/tutorials/guides/getting-started/registering-an-account),

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>com.applitools.example</groupId>
8-
<artifactId>example-playwright-java-ufg</artifactId>
9-
<version>1.0.0</version>
8+
<artifactId>example-playwright-java</artifactId>
9+
<version>2.0.0</version>
1010

1111
<properties>
1212
<maven.compiler.source>1.8</maven.compiler.source>
@@ -18,7 +18,7 @@
1818
<plugin>
1919
<groupId>org.apache.maven.plugins</groupId>
2020
<artifactId>maven-surefire-plugin</artifactId>
21-
<version>3.0.0-M6</version>
21+
<version>3.1.0</version>
2222
</plugin>
2323
</plugins>
2424
</build>
@@ -27,13 +27,13 @@
2727
<dependency>
2828
<groupId>com.applitools</groupId>
2929
<artifactId>eyes-playwright-java5</artifactId>
30-
<version>5.41.0</version>
30+
<version>5.50.0</version>
3131
<scope>test</scope>
3232
</dependency>
3333
<dependency>
3434
<groupId>org.junit.jupiter</groupId>
3535
<artifactId>junit-jupiter</artifactId>
36-
<version>5.9.1</version>
36+
<version>5.9.3</version>
3737
<scope>test</scope>
3838
</dependency>
3939
</dependencies>

src/test/java/com/applitools/example/AcmeBankTests.java

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.applitools.example;
22

33
import com.applitools.eyes.BatchInfo;
4+
import com.applitools.eyes.EyesRunner;
45
import com.applitools.eyes.RectangleSize;
56
import com.applitools.eyes.TestResultsSummary;
67
import com.applitools.eyes.config.Configuration;
8+
import com.applitools.eyes.playwright.ClassicRunner;
79
import com.applitools.eyes.playwright.Eyes;
810
import com.applitools.eyes.playwright.fluent.Target;
911
import com.applitools.eyes.visualgrid.BrowserType;
@@ -21,17 +23,22 @@
2123

2224
public class AcmeBankTests {
2325
// This JUnit test case class contains everything needed to run a full visual test against the ACME bank site.
24-
// It runs the test once locally,
25-
// and then it performs cross-browser testing against multiple unique browsers in Applitools Ultrafast Grid.
26+
// It runs the test once locally.
27+
// If you use the Ultrafast Grid, then it performs cross-browser testing against multiple unique browsers.
28+
29+
// Runner Settings.
30+
// These could be set by environment variables or other input mechanisms.
31+
// They are hard-coded here to keep the example project simple.
32+
private final static boolean USE_ULTRAFAST_GRID = true;
33+
private final static boolean HEADLESS = false;
2634

2735
// Test control inputs to read once and share for all tests
2836
private static String applitoolsApiKey;
29-
private static boolean headless;
3037

3138
// Applitools objects to share for all tests
3239
private static BatchInfo batch;
3340
private static Configuration config;
34-
private static VisualGridRunner runner;
41+
private static EyesRunner runner;
3542

3643
// Test-specific objects
3744
private static Playwright playwright;
@@ -42,27 +49,29 @@ public class AcmeBankTests {
4249

4350
@BeforeAll
4451
public static void setUpConfigAndRunner() {
45-
// This method sets up the configuration for running visual tests in the Ultrafast Grid.
52+
// This method sets up the configuration for running visual tests.
4653
// The configuration is shared by all tests in a test suite, so it belongs in a `BeforeAll` method.
4754
// If you have more than one test class, then you should abstract this configuration to avoid duplication.
4855

4956
// Read the Applitools API key from an environment variable.
5057
applitoolsApiKey = System.getenv("APPLITOOLS_API_KEY");
5158

52-
// Read the headless mode setting from an environment variable.
53-
// Use headless mode for Continuous Integration (CI) execution.
54-
// Use headed mode for local development.
55-
headless = Boolean.parseBoolean(System.getenv().getOrDefault("HEADLESS", "true"));
56-
57-
// Create the runner for the Ultrafast Grid.
58-
// Concurrency refers to the number of visual checkpoints Applitools will perform in parallel.
59-
// Warning: If you have a free account, then concurrency will be limited to 1.
60-
runner = new VisualGridRunner(new RunnerOptions().testConcurrency(5));
59+
if (USE_ULTRAFAST_GRID) {
60+
// Create the runner for the Ultrafast Grid.
61+
// Concurrency refers to the number of visual checkpoints Applitools will perform in parallel.
62+
// Warning: If you have a free account, then concurrency will be limited to 1.
63+
runner = new VisualGridRunner(new RunnerOptions().testConcurrency(5));
64+
}
65+
else {
66+
// Create the Classic runner.
67+
runner = new ClassicRunner();
68+
}
6169

6270
// Create a new batch for tests.
6371
// A batch is the collection of visual checkpoints for a test suite.
6472
// Batches are displayed in the Eyes Test Manager, so use meaningful names.
65-
batch = new BatchInfo("Example: Playwright Java JUnit with the Ultrafast Grid");
73+
String runnerName = (USE_ULTRAFAST_GRID) ? "Ultrafast Grid" : "Classic runner";
74+
batch = new BatchInfo("Example: Playwright Java JUnit with the " + runnerName);
6675

6776
// Create a configuration for Applitools Eyes.
6877
config = new Configuration();
@@ -75,20 +84,24 @@ public static void setUpConfigAndRunner() {
7584
// Set the batch for the config.
7685
config.setBatch(batch);
7786

78-
// Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid.
79-
// Other browsers are also available, like Edge and IE.
80-
config.addBrowser(800, 600, BrowserType.CHROME);
81-
config.addBrowser(1600, 1200, BrowserType.FIREFOX);
82-
config.addBrowser(1024, 768, BrowserType.SAFARI);
87+
// If running tests on the Ultrafast Grid, configure browsers.
88+
if (USE_ULTRAFAST_GRID) {
89+
90+
// Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid.
91+
// Other browsers are also available, like Edge and IE.
92+
config.addBrowser(800, 600, BrowserType.CHROME);
93+
config.addBrowser(1600, 1200, BrowserType.FIREFOX);
94+
config.addBrowser(1024, 768, BrowserType.SAFARI);
8395

84-
// Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid.
85-
// Other mobile devices are available, including iOS.
86-
config.addDeviceEmulation(DeviceName.Pixel_2, ScreenOrientation.PORTRAIT);
87-
config.addDeviceEmulation(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE);
96+
// Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid.
97+
// Other mobile devices are available, including iOS.
98+
config.addDeviceEmulation(DeviceName.Pixel_2, ScreenOrientation.PORTRAIT);
99+
config.addDeviceEmulation(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE);
100+
}
88101

89102
// Start Playwright and launch the browser.
90103
playwright = Playwright.create();
91-
browser = playwright.chromium().launch(new com.microsoft.playwright.BrowserType.LaunchOptions().setHeadless(headless));
104+
browser = playwright.chromium().launch(new com.microsoft.playwright.BrowserType.LaunchOptions().setHeadless(HEADLESS));
92105
}
93106

94107
@BeforeEach
@@ -103,7 +116,7 @@ public void openBrowserAndEyes(TestInfo testInfo) {
103116
// page = browser.newPage();
104117
page = context.newPage();
105118

106-
// Create the Applitools Eyes object connected to the VisualGridRunner and set its configuration.
119+
// Create the Applitools Eyes object connected to the runner and set its configuration.
107120
eyes = new Eyes(runner);
108121
eyes.setConfiguration(config);
109122

0 commit comments

Comments
 (0)