11using Applitools ;
22using Applitools . Selenium ;
33using Applitools . VisualGrid ;
4+ using NUnit . Framework ;
45using OpenQA . Selenium ;
56using OpenQA . Selenium . Chrome ;
67using Configuration = Applitools . Selenium . Configuration ;
910namespace ApplitoolsTutorial
1011{
1112
12- class Program
13+ [ TestFixture ]
14+ public class VisualGridDemo
1315 {
14- public static void Main ( )
15- {
16- Program program = new Program ( ) ;
17- program . Run ( ) ;
18- }
1916
20- private void Run ( )
17+ [ Test ]
18+ public void VGTest ( )
2119 {
2220 // Create a new webdriver
2321 IWebDriver webDriver = new ChromeDriver ( ) ;
@@ -34,12 +32,11 @@ private void Run()
3432 // Create Eyes object with the runner, meaning it'll be a Visual Grid eyes.
3533 Eyes eyes = new Eyes ( runner ) ;
3634
37- // Create configuration object
38- Configuration conf = new Configuration ( ) ;
35+ // Get current Eyes configuration object
36+ Configuration conf = eyes . GetConfiguration ( ) ;
3937
4038
41-
42- //conf.SetApiKey("APPLITOOLS_API_KEY"); // Set the Applitools API KEY here or as an environment variable "APPLITOOLS_API_KEY"
39+ //conf.SetApiKey("APPLITOOLS_API_KEY"); // Set the Applitools API KEY here or as an environment variable "APPLITOOLS_API_KEY"
4340 conf . SetTestName ( "C# VisualGrid demo" ) // Set test name
4441 . SetAppName ( "Demo app" ) ; // Set app name
4542
@@ -49,6 +46,7 @@ private void Run()
4946 conf . AddBrowser ( 1200 , 800 , BrowserType . IE_10 ) ;
5047 conf . AddBrowser ( 1600 , 1200 , BrowserType . IE_11 ) ;
5148 conf . AddBrowser ( 1024 , 768 , BrowserType . EDGE ) ;
49+ conf . AddBrowser ( 800 , 600 , BrowserType . SAFARI ) ;
5250
5351 // Add iPhone 4 device emulation in Portrait mode
5452 conf . AddDeviceEmulation ( DeviceName . iPhone_4 , ScreenOrientation . Portrait ) ;
@@ -57,24 +55,30 @@ private void Run()
5755 // Set the configuration object to eyes
5856 eyes . SetConfiguration ( conf ) ;
5957
60- // Call Open on eyes to initialize a test session
61- eyes . Open ( webDriver ) ;
62-
63- // check the login page
64- eyes . Check ( Target . Window ( ) . Fully ( ) . WithName ( "Login page" ) ) ;
65- webDriver . FindElement ( By . Id ( "log-in" ) ) . Click ( ) ;
58+ try
59+ {
60+ // Call Open on eyes to initialize a test session
61+ eyes . Open ( webDriver ) ;
6662
67- // Check the app page
68- eyes . Check ( Target . Window ( ) . Fully ( ) . WithName ( "App page" ) ) ;
63+ // check the login page
64+ eyes . Check ( Target . Window ( ) . Fully ( ) . WithName ( "Login page" ) ) ;
65+ webDriver . FindElement ( By . Id ( "log-in" ) ) . Click ( ) ;
6966
70- // Close the browser
71- webDriver . Quit ( ) ;
67+ // Check the app page
68+ eyes . Check ( Target . Window ( ) . Fully ( ) . WithName ( "App page" ) ) ;
7269
73- eyes . CloseAsync ( ) ;
70+ // Call Close on eyes to let the server know it should display the results
71+ eyes . CloseAsync ( ) ;
72+ }
73+ finally
74+ {
75+ // Close the browser
76+ webDriver . Quit ( ) ;
77+ }
7478
75- //Wait and collect all test results
79+ // Wait and collect all test results
7680 TestResultsSummary allTestResults = runner . GetAllTestResults ( ) ;
77- System . Console . WriteLine ( allTestResults ) ;
81+ TestContext . Progress . WriteLine ( allTestResults ) ;
7882 }
7983
8084 }
0 commit comments