11package com .applitools .example ;
22
33import com .applitools .eyes .BatchInfo ;
4+ import com .applitools .eyes .EyesRunner ;
45import com .applitools .eyes .RectangleSize ;
56import com .applitools .eyes .TestResultsSummary ;
67import com .applitools .eyes .config .Configuration ;
8+ import com .applitools .eyes .playwright .ClassicRunner ;
79import com .applitools .eyes .playwright .Eyes ;
810import com .applitools .eyes .playwright .fluent .Target ;
911import com .applitools .eyes .visualgrid .BrowserType ;
2123
2224public 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