Skip to content

Commit 7f4ef7e

Browse files
Combined classic and UFG
1 parent dae69df commit 7f4ef7e

File tree

2 files changed

+52
-29
lines changed

2 files changed

+52
-29
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 TypeScript with the Ultrafast Grid
1+
# Applitools Example: Playwright in TypeScript
22

33
This is the example project for the [Playwright TypeScript tutorial](https://applitools.com/tutorials/quickstart/web/playwright/typescript).
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/) in TypeScript.
6+
and [Playwright](https://playwright.dev/) in TypeScript.
87

98
It uses:
109

@@ -14,6 +13,9 @@ It uses:
1413
* [Chromium](https://www.chromium.org/chromium-projects/) as the local browser for testing
1514
* [npm](https://www.npmjs.com/) for dependency management
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:
@@ -30,6 +32,8 @@ npx playwright install
3032
```
3133

3234
The main test case spec is [`acme-bank.spec.ts`](tests/acme-bank.spec.ts).
35+
By default, the project will run tests with Ultrafast Grid.
36+
You can change this setting in the test spec.
3337

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

tests/acme-bank.spec.ts

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,71 @@
11
// 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.
34

45
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;
621

722
// Applitools objects to share for all tests
823
export let Batch: BatchInfo;
924
export let Config: Configuration;
10-
export let Runner: VisualGridRunner;
25+
export let Runner: EyesRunner;
1126

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.
1328
// The configuration is shared by all tests in a test suite, so it belongs in a `beforeAll` method.
1429
// If you have more than one test class, then you should abstract this configuration to avoid duplication.
1530
test.beforeAll(async() => {
1631

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+
}
2142

2243
// Create a new batch for tests.
2344
// A batch is the collection of visual checkpoints for a test suite.
2445
// 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}`});
2648

2749
// Create a configuration for Applitools Eyes.
2850
Config = new Configuration();
2951

3052
// Set the batch for the config.
3153
Config.setBatch(Batch);
3254

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) {
3857

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+
}
4369
});
4470

4571
// This "describe" method contains related test cases with per-test setup and cleanup.
@@ -106,14 +132,7 @@ test.describe('ACME Bank', () => {
106132
test.afterEach(async () => {
107133

108134
// 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();
117136
});
118137
});
119138

0 commit comments

Comments
 (0)