Skip to content

Commit 6f28e3b

Browse files
Combined UFG + Classic
1 parent d81aac4 commit 6f28e3b

File tree

3 files changed

+66
-27
lines changed

3 files changed

+66
-27
lines changed

Applitools.Example.Tests/AcmeBankTest.cs

+53-19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using NUnit.Framework;
44
using OpenQA.Selenium;
55
using OpenQA.Selenium.Chrome;
6+
using OpenQA.Selenium.Remote;
67
using System.Drawing;
78
using ScreenOrientation = Applitools.VisualGrid.ScreenOrientation;
89

@@ -13,21 +14,30 @@ namespace Applitools.Example.Tests;
1314
/// </summary>
1415
public 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
}

Applitools.Example.Tests/Applitools.Example.Tests.csproj

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Eyes.Selenium4" Version="3.33.0" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
12+
<PackageReference Include="Eyes.Selenium4" Version="3.51.0" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
1414
<PackageReference Include="NUnit" Version="3.13.3" />
15-
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
16-
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
17-
<PackageReference Include="coverlet.collector" Version="3.1.2" />
15+
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
16+
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
17+
<PackageReference Include="coverlet.collector" Version="3.2.0" />
1818
</ItemGroup>
1919

2020
</Project>

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# Applitools Example: Selenium C# NUnit with the Ultrafast Grid
1+
# Applitools Example: Selenium in C# with NUnit
22

33
This is the example project for the [Selenium C# NUnit tutorial](https://applitools.com/tutorials/quickstart/web/selenium/csharp/nunit).
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 [Selenium WebDriver](https://www.selenium.dev/) in C#.
6+
and using [Selenium WebDriver](https://www.selenium.dev/) in C#.
87

98
It uses:
109

@@ -14,7 +13,11 @@ It uses:
1413
* [NuGet](https://www.nuget.org/) for dependency management
1514
* [NUnit](https://nunit.org/) as the core test framework
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
20+
* [Applitools Execution Cloud](https://applitools.com/platform/execution-cloud/) for self-healing remote WebDriver sessions
1821

1922
To run this example project, you'll need:
2023

@@ -26,6 +29,8 @@ To run this example project, you'll need:
2629
5. A corresponding version of [ChromeDriver](https://chromedriver.chromium.org/downloads).
2730

2831
The main test case is [`AcmeBankTest.cs`](Applitools.Example.Tests/AcmeBankTest.cs).
32+
By default, the project will run tests with Ultrafast Grid but not Execution Cloud.
33+
You can change these settings in the test class.
2934

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

0 commit comments

Comments
 (0)