Skip to content

Commit 1bd5d4b

Browse files
UFG + Classic + XCloud
1 parent 73e0ffa commit 1bd5d4b

File tree

1 file changed

+65
-31
lines changed

1 file changed

+65
-31
lines changed

test/acme-bank.test.js

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
'use strict';
22

3+
const { remote } = require('webdriverio');
4+
35
const { Eyes,
6+
ClassicRunner,
47
VisualGridRunner,
58
RunnerOptions,
69
Target,
@@ -16,6 +19,12 @@ describe('ACME Bank', function () {
1619
// It runs the test once locally,
1720
// and then it performs cross-browser testing against multiple unique browsers in Applitools Ultrafast Grid.
1821

22+
// Settings to control how tests are run.
23+
// These could be set by environment variables or other input mechanisms.
24+
// They are hard-coded here to keep the example project simple.
25+
const USE_ULTRAFAST_GRID = true;
26+
const USE_EXECUTION_CLOUD = true;
27+
1928
// Test control inputs to read once and share for all tests
2029
var applitoolsApiKey;
2130

@@ -29,7 +38,7 @@ describe('ACME Bank', function () {
2938

3039

3140
before(async () => {
32-
// This method sets up the configuration for running visual tests in the Ultrafast Grid.
41+
// This method sets up the configuration for running visual tests.
3342
// The configuration is shared by all tests in a test suite, so it belongs in a `before` method.
3443
// If you have more than one test class, then you should abstract this configuration to avoid duplication.
3544

@@ -38,15 +47,22 @@ describe('ACME Bank', function () {
3847
// https://applitools.com/tutorials/getting-started/setting-up-your-environment.html
3948
applitoolsApiKey = process.env.APPLITOOLS_API_KEY;
4049

41-
// Create the runner for the Ultrafast Grid.
42-
// Concurrency refers to the number of visual checkpoints Applitools will perform in parallel.
43-
// Warning: If you have a free account, then concurrency will be limited to 1.
44-
runner = new VisualGridRunner(new RunnerOptions().testConcurrency(5));
50+
if (USE_ULTRAFAST_GRID) {
51+
// Create the runner for the Ultrafast Grid.
52+
// Concurrency refers to the number of visual checkpoints Applitools will perform in parallel.
53+
// Warning: If you have a free account, then concurrency will be limited to 1.
54+
runner = new VisualGridRunner(new RunnerOptions().testConcurrency(5));
55+
}
56+
else {
57+
// Create the classic runner.
58+
runner = new ClassicRunner();
59+
}
4560

4661
// Create a new batch for tests.
4762
// A batch is the collection of visual checkpoints for a test suite.
4863
// Batches are displayed in the Eyes Test Manager, so use meaningful names.
49-
batch = new BatchInfo('Example: WebdriverIO JavaScript with the Ultrafast Grid');
64+
const runnerName = (USE_ULTRAFAST_GRID) ? 'Ultrafast Grid' : 'Classic runner';
65+
batch = new BatchInfo(`Example: WebdriverIO JavaScript with the ${runnerName}`);
5066

5167
// Create a configuration for Applitools Eyes.
5268
config = new Configuration();
@@ -59,16 +75,19 @@ describe('ACME Bank', function () {
5975
// Set the batch for the config.
6076
config.setBatch(batch);
6177

62-
// Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid.
63-
// Other browsers are also available, like Edge and IE.
64-
config.addBrowser(800, 600, BrowserType.CHROME);
65-
config.addBrowser(1600, 1200, BrowserType.FIREFOX);
66-
config.addBrowser(1024, 768, BrowserType.SAFARI);
78+
if (USE_ULTRAFAST_GRID) {
79+
80+
// Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid.
81+
// Other browsers are also available, like Edge and IE.
82+
config.addBrowser(800, 600, BrowserType.CHROME);
83+
config.addBrowser(1600, 1200, BrowserType.FIREFOX);
84+
config.addBrowser(1024, 768, BrowserType.SAFARI);
6785

68-
// Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid.
69-
// Other mobile devices are available, including iOS.
70-
config.addDeviceEmulation(DeviceName.Pixel_2, ScreenOrientation.PORTRAIT);
71-
config.addDeviceEmulation(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE);
86+
// Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid.
87+
// Other mobile devices are available, including iOS.
88+
config.addDeviceEmulation(DeviceName.Pixel_2, ScreenOrientation.PORTRAIT);
89+
config.addDeviceEmulation(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE);
90+
}
7291
});
7392

7493

@@ -81,27 +100,42 @@ describe('ACME Bank', function () {
81100
eyes = new Eyes(runner);
82101
eyes.setConfiguration(config);
83102

103+
// Set up Execution Cloud if it will be used.
104+
if (USE_EXECUTION_CLOUD) {
105+
const executionCloudUrl = new URL(await Eyes.getExecutionCloudUrl());
106+
const protocol_val = executionCloudUrl.protocol.substring(0, executionCloudUrl.protocol.length - 1);
107+
browser = await remote({
108+
logLevel: 'trace',
109+
protocol: protocol_val,
110+
hostname: executionCloudUrl.hostname,
111+
port: Number(executionCloudUrl.port),
112+
capabilities: {
113+
browserName: 'chrome',
114+
}
115+
});
116+
}
117+
84118
// Open Eyes to start visual testing.
85119
// It is a recommended practice to set all four inputs:
86120
browser = await eyes.open(
87121

88-
// WebDriver object to "watch".
89-
browser,
90-
91-
// The name of the application under test.
92-
// All tests for the same app should share the same app name.
93-
// Set this name wisely: Applitools features rely on a shared app name across tests.
94-
'ACME Bank',
95-
96-
// The name of the test case for the given application.
97-
// Additional unique characteristics of the test may also be specified as part of the test name,
98-
// such as localization information ("Home Page - EN") or different user permissions ("Login by admin").
99-
this.currentTest.fullTitle(),
122+
// WebDriver object to "watch".
123+
browser,
124+
125+
// The name of the application under test.
126+
// All tests for the same app should share the same app name.
127+
// Set this name wisely: Applitools features rely on a shared app name across tests.
128+
'ACME Bank',
100129

101-
// The viewport size for the local browser.
102-
// Eyes will resize the web browser to match the requested viewport size.
103-
// This parameter is optional but encouraged in order to produce consistent results.
104-
new RectangleSize(1024, 768)
130+
// The name of the test case for the given application.
131+
// Additional unique characteristics of the test may also be specified as part of the test name,
132+
// such as localization information ("Home Page - EN") or different user permissions ("Login by admin").
133+
this.currentTest.fullTitle(),
134+
135+
// The viewport size for the local browser.
136+
// Eyes will resize the web browser to match the requested viewport size.
137+
// This parameter is optional but encouraged in order to produce consistent results.
138+
new RectangleSize(1024, 768)
105139
);
106140
});
107141

0 commit comments

Comments
 (0)