3
3
using NUnit . Framework ;
4
4
using OpenQA . Selenium ;
5
5
using OpenQA . Selenium . Chrome ;
6
+ using OpenQA . Selenium . Remote ;
6
7
using System . Drawing ;
7
8
using ScreenOrientation = Applitools . VisualGrid . ScreenOrientation ;
8
9
@@ -13,21 +14,30 @@ namespace Applitools.Example.Tests;
13
14
/// </summary>
14
15
public class AcmeBankTest
15
16
{
17
+ #pragma warning disable CS0162
18
+ #pragma warning disable CS8618
19
+
20
+ // Test constants
21
+ public const bool UseUltrafastGrid = true ;
22
+ public const bool UseExecutionCloud = false ;
23
+
16
24
// Test control inputs to read once and share for all tests
17
25
private static string ? ApplitoolsApiKey ;
18
26
private static bool Headless ;
19
27
20
28
// Applitools objects to share for all tests
21
29
private static BatchInfo Batch ;
22
30
private static Configuration Config ;
23
- private static VisualGridRunner Runner ;
31
+ private static EyesRunner Runner ;
24
32
25
33
// Test-specific objects
26
34
private WebDriver Driver ;
27
35
private Eyes Eyes ;
28
36
37
+ #pragma warning restore CS8618
38
+
29
39
/// <summary>
30
- /// Sets up the configuration for running visual tests in the Ultrafast Grid .
40
+ /// Sets up the configuration for running visual tests.
31
41
/// The configuration is shared by all tests in a test suite, so it belongs in a `OneTimeSetUp` method.
32
42
/// If you have more than one test class, then you should abstract this configuration to avoid duplication.
33
43
/// <summary>
@@ -42,15 +52,24 @@ public static void SetUpConfigAndRunner()
42
52
// Use headed mode for local development.
43
53
Headless = Environment . GetEnvironmentVariable ( "HEADLESS" ) ? . ToLower ( ) == "true" ;
44
54
45
- // Create the runner for the Ultrafast Grid.
46
- // Concurrency refers to the number of visual checkpoints Applitools will perform in parallel.
47
- // Warning: If you have a free account, then concurrency will be limited to 1.
48
- Runner = new VisualGridRunner ( new RunnerOptions ( ) . TestConcurrency ( 5 ) ) ;
55
+ if ( UseUltrafastGrid )
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 ) ) ;
61
+ }
62
+ else
63
+ {
64
+ // Create the Classic runner for local execution.
65
+ Runner = new ClassicRunner ( ) ;
66
+ }
49
67
50
68
// Create a new batch for tests.
51
69
// A batch is the collection of visual checkpoints for a test suite.
52
70
// Batches are displayed in the Eyes Test Manager, so use meaningful names.
53
- Batch = new BatchInfo ( "Example: Selenium C# NUnit with the Ultrafast Grid" ) ;
71
+ String runnerName = ( UseUltrafastGrid ) ? "Ultrafast Grid" : "Classic Runner" ;
72
+ Batch = new BatchInfo ( $ "Example: Selenium C# NUnit with the { runnerName } ") ;
54
73
55
74
// Create a configuration for Applitools Eyes.
56
75
Config = new Configuration ( ) ;
@@ -63,16 +82,19 @@ public static void SetUpConfigAndRunner()
63
82
// Set the batch for the config.
64
83
Config . SetBatch ( Batch ) ;
65
84
66
- // Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid.
67
- // Other browsers are also available, like Edge and IE.
68
- Config . AddBrowser ( 800 , 600 , BrowserType . CHROME ) ;
69
- Config . AddBrowser ( 1600 , 1200 , BrowserType . FIREFOX ) ;
70
- Config . AddBrowser ( 1024 , 768 , BrowserType . SAFARI ) ;
71
-
72
- // Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid.
73
- // Other mobile devices are available, including iOS.
74
- Config . AddDeviceEmulation ( DeviceName . Pixel_2 , ScreenOrientation . Portrait ) ;
75
- Config . AddDeviceEmulation ( DeviceName . Nexus_10 , ScreenOrientation . Landscape ) ;
85
+ if ( UseUltrafastGrid )
86
+ {
87
+ // Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid.
88
+ // Other browsers are also available, like Edge and IE.
89
+ Config . AddBrowser ( 800 , 600 , BrowserType . CHROME ) ;
90
+ Config . AddBrowser ( 1600 , 1200 , BrowserType . FIREFOX ) ;
91
+ Config . AddBrowser ( 1024 , 768 , BrowserType . SAFARI ) ;
92
+
93
+ // Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid.
94
+ // Other mobile devices are available, including iOS.
95
+ Config . AddDeviceEmulation ( DeviceName . Pixel_2 , ScreenOrientation . Portrait ) ;
96
+ Config . AddDeviceEmulation ( DeviceName . Nexus_10 , ScreenOrientation . Landscape ) ;
97
+ }
76
98
}
77
99
78
100
/// <summary>
@@ -86,15 +108,25 @@ public void OpenBrowserAndEyes()
86
108
// it still needs to run the test one time locally to capture snapshots.
87
109
ChromeOptions options = new ChromeOptions ( ) ;
88
110
if ( Headless ) options . AddArgument ( "headless" ) ;
89
- Driver = new ChromeDriver ( options ) ;
111
+
112
+ if ( UseExecutionCloud )
113
+ {
114
+ // Open the browser remotely in the Execution Cloud.
115
+ Driver = new RemoteWebDriver ( new Uri ( Eyes . GetExecutionCloudURL ( ) ) , options ) ;
116
+ }
117
+ else
118
+ {
119
+ // Create a local WebDriver.
120
+ Driver = new ChromeDriver ( options ) ;
121
+ }
90
122
91
123
// Set an implicit wait of 10 seconds.
92
124
// For larger projects, use explicit waits for better control.
93
125
// https://www.selenium.dev/documentation/webdriver/waits/
94
126
// The following call works for Selenium 4:
95
127
Driver . Manage ( ) . Timeouts ( ) . ImplicitWait = TimeSpan . FromSeconds ( 10 ) ;
96
128
97
- // Create the Applitools Eyes object connected to the VisualGridRunner and set its configuration.
129
+ // Create the Applitools Eyes object connected to the runner and set its configuration.
98
130
Eyes = new Eyes ( Runner ) ;
99
131
Eyes . SetConfiguration ( Config ) ;
100
132
Eyes . SaveNewTests = true ;
@@ -179,4 +211,6 @@ public static void PrintResults()
179
211
TestResultsSummary allTestResults = Runner . GetAllTestResults ( ) ;
180
212
Console . WriteLine ( allTestResults ) ;
181
213
}
214
+
215
+ #pragma warning restore CS0162
182
216
}
0 commit comments