33using NUnit . Framework ;
44using OpenQA . Selenium ;
55using OpenQA . Selenium . Chrome ;
6+ using OpenQA . Selenium . Remote ;
67using System . Drawing ;
78using ScreenOrientation = Applitools . VisualGrid . ScreenOrientation ;
89
@@ -13,21 +14,30 @@ namespace Applitools.Example.Tests;
1314/// </summary>
1415public class AcmeBankTest
1516{
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+
1624 // Test control inputs to read once and share for all tests
1725 private static string ? ApplitoolsApiKey ;
1826 private static bool Headless ;
1927
2028 // Applitools objects to share for all tests
2129 private static BatchInfo Batch ;
2230 private static Configuration Config ;
23- private static VisualGridRunner Runner ;
31+ private static EyesRunner Runner ;
2432
2533 // Test-specific objects
2634 private WebDriver Driver ;
2735 private Eyes Eyes ;
2836
37+ #pragma warning restore CS8618
38+
2939 /// <summary>
30- /// Sets up the configuration for running visual tests in the Ultrafast Grid .
40+ /// Sets up the configuration for running visual tests.
3141 /// The configuration is shared by all tests in a test suite, so it belongs in a `OneTimeSetUp` method.
3242 /// If you have more than one test class, then you should abstract this configuration to avoid duplication.
3343 /// <summary>
@@ -42,15 +52,24 @@ public static void SetUpConfigAndRunner()
4252 // Use headed mode for local development.
4353 Headless = Environment . GetEnvironmentVariable ( "HEADLESS" ) ? . ToLower ( ) == "true" ;
4454
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+ }
4967
5068 // Create a new batch for tests.
5169 // A batch is the collection of visual checkpoints for a test suite.
5270 // 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 } ") ;
5473
5574 // Create a configuration for Applitools Eyes.
5675 Config = new Configuration ( ) ;
@@ -63,16 +82,19 @@ public static void SetUpConfigAndRunner()
6382 // Set the batch for the config.
6483 Config . SetBatch ( Batch ) ;
6584
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+ }
7698 }
7799
78100 /// <summary>
@@ -86,15 +108,25 @@ public void OpenBrowserAndEyes()
86108 // it still needs to run the test one time locally to capture snapshots.
87109 ChromeOptions options = new ChromeOptions ( ) ;
88110 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+ }
90122
91123 // Set an implicit wait of 10 seconds.
92124 // For larger projects, use explicit waits for better control.
93125 // https://www.selenium.dev/documentation/webdriver/waits/
94126 // The following call works for Selenium 4:
95127 Driver . Manage ( ) . Timeouts ( ) . ImplicitWait = TimeSpan . FromSeconds ( 10 ) ;
96128
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.
98130 Eyes = new Eyes ( Runner ) ;
99131 Eyes . SetConfiguration ( Config ) ;
100132 Eyes . SaveNewTests = true ;
@@ -179,4 +211,6 @@ public static void PrintResults()
179211 TestResultsSummary allTestResults = Runner . GetAllTestResults ( ) ;
180212 Console . WriteLine ( allTestResults ) ;
181213 }
214+
215+ #pragma warning restore CS0162
182216}
0 commit comments