|
1 | 1 | // This test case spec contains everything needed to run a full visual test against the ACME bank site. |
2 | | -// It runs the test once locally, and then it performs cross-browser testing against multiple unique browsers in Applitools Ultrafast Grid. |
| 2 | +// It runs the test once locally. |
| 3 | +// If you use the Ultrafast Grid, then it performs cross-browser testing against multiple unique browsers. |
3 | 4 |
|
4 | 5 | import { test } from '@playwright/test'; |
5 | | -import { BatchInfo, Configuration, VisualGridRunner, BrowserType, DeviceName, ScreenOrientation, Eyes, Target } from '@applitools/eyes-playwright'; |
| 6 | +import { |
| 7 | + BatchInfo, |
| 8 | + Configuration, |
| 9 | + EyesRunner, |
| 10 | + ClassicRunner, |
| 11 | + VisualGridRunner, |
| 12 | + BrowserType, |
| 13 | + DeviceName, |
| 14 | + ScreenOrientation, |
| 15 | + Eyes, |
| 16 | + Target |
| 17 | +} from '@applitools/eyes-playwright'; |
| 18 | + |
| 19 | +// Settings |
| 20 | +export const USE_ULTRAFAST_GRID: boolean = true; |
6 | 21 |
|
7 | 22 | // Applitools objects to share for all tests |
8 | 23 | export let Batch: BatchInfo; |
9 | 24 | export let Config: Configuration; |
10 | | -export let Runner: VisualGridRunner; |
| 25 | +export let Runner: EyesRunner; |
11 | 26 |
|
12 | | -// This method sets up the configuration for running visual tests in the Ultrafast Grid. |
| 27 | +// This method sets up the configuration for running visual tests. |
13 | 28 | // The configuration is shared by all tests in a test suite, so it belongs in a `beforeAll` method. |
14 | 29 | // If you have more than one test class, then you should abstract this configuration to avoid duplication. |
15 | 30 | test.beforeAll(async() => { |
16 | 31 |
|
17 | | - // Create the runner for the Ultrafast Grid. |
18 | | - // Concurrency refers to the number of visual checkpoints Applitools will perform in parallel. |
19 | | - // Warning: If you have a free account, then concurrency will be limited to 1. |
20 | | - Runner = new VisualGridRunner({ testConcurrency: 5 }); |
| 32 | + if (USE_ULTRAFAST_GRID) { |
| 33 | + // Create the runner for the Ultrafast Grid. |
| 34 | + // Concurrency refers to the number of visual checkpoints Applitools will perform in parallel. |
| 35 | + // Warning: If you have a free account, then concurrency will be limited to 1. |
| 36 | + Runner = new VisualGridRunner({ testConcurrency: 5 }); |
| 37 | + } |
| 38 | + else { |
| 39 | + // Create the classic runner. |
| 40 | + Runner = new ClassicRunner(); |
| 41 | + } |
21 | 42 |
|
22 | 43 | // Create a new batch for tests. |
23 | 44 | // A batch is the collection of visual checkpoints for a test suite. |
24 | 45 | // Batches are displayed in the Eyes Test Manager, so use meaningful names. |
25 | | - Batch = new BatchInfo({name: 'Example: Playwright TypeScript with the Ultrafast Grid'}); |
| 46 | + const runnerName = (USE_ULTRAFAST_GRID) ? 'Ultrafast Grid' : 'Classic runner' |
| 47 | + Batch = new BatchInfo({name: `Example: Playwright TypeScript with the ${runnerName}`}); |
26 | 48 |
|
27 | 49 | // Create a configuration for Applitools Eyes. |
28 | 50 | Config = new Configuration(); |
29 | 51 |
|
30 | 52 | // Set the batch for the config. |
31 | 53 | Config.setBatch(Batch); |
32 | 54 |
|
33 | | - // Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid. |
34 | | - // Other browsers are also available, like Edge and IE. |
35 | | - Config.addBrowser(800, 600, BrowserType.CHROME); |
36 | | - Config.addBrowser(1600, 1200, BrowserType.FIREFOX); |
37 | | - Config.addBrowser(1024, 768, BrowserType.SAFARI); |
| 55 | + // If running tests on the Ultrafast Grid, configure browsers. |
| 56 | + if (USE_ULTRAFAST_GRID) { |
38 | 57 |
|
39 | | - // Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid. |
40 | | - // Other mobile devices are available, including iOS. |
41 | | - Config.addDeviceEmulation(DeviceName.Pixel_2, ScreenOrientation.PORTRAIT); |
42 | | - Config.addDeviceEmulation(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE); |
| 58 | + // Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid. |
| 59 | + // Other browsers are also available, like Edge and IE. |
| 60 | + Config.addBrowser(800, 600, BrowserType.CHROME); |
| 61 | + Config.addBrowser(1600, 1200, BrowserType.FIREFOX); |
| 62 | + Config.addBrowser(1024, 768, BrowserType.SAFARI); |
| 63 | + |
| 64 | + // Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid. |
| 65 | + // Other mobile devices are available. |
| 66 | + Config.addDeviceEmulation(DeviceName.iPhone_11, ScreenOrientation.PORTRAIT); |
| 67 | + Config.addDeviceEmulation(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE); |
| 68 | + } |
43 | 69 | }); |
44 | 70 |
|
45 | 71 | // This "describe" method contains related test cases with per-test setup and cleanup. |
@@ -106,14 +132,7 @@ test.describe('ACME Bank', () => { |
106 | 132 | test.afterEach(async () => { |
107 | 133 |
|
108 | 134 | // Close Eyes to tell the server it should display the results. |
109 | | - await eyes.closeAsync(); |
110 | | - |
111 | | - // Warning: `eyes.closeAsync()` will NOT wait for visual checkpoints to complete. |
112 | | - // You will need to check the Eyes Test Manager for visual results per checkpoint. |
113 | | - // Note that "unresolved" and "failed" visual checkpoints will not cause the Playwright test to fail. |
114 | | - |
115 | | - // If you want the Playwright test to wait synchronously for all checkpoints to complete, then use `eyes.close()`. |
116 | | - // If any checkpoints are unresolved or failed, then `eyes.close()` will make the Playwright test fail. |
| 135 | + await eyes.close(); |
117 | 136 | }); |
118 | 137 | }); |
119 | 138 |
|
|
0 commit comments