@@ -14,71 +14,79 @@ namespace ApplitoolsTutorial
1414 public class VisualGridDemo
1515 {
1616
17- [ Test ]
18- public void VGTest ( )
19- {
20- // Create a new webdriver
21- IWebDriver webDriver = new ChromeDriver ( ) ;
22-
23- // Navigate to the url we want to test
24- webDriver . Url = "https://demo.applitools.com" ;
17+ IWebDriver driver ;
18+ VisualGridRunner runner ;
19+ Eyes eyes ;
2520
26- // ⭐️ Note to see visual bugs, run the test using the above URL for the 1st run.
27- //but then change the above URL to https://demo.applitools.com/index_v2.html (for the 2nd run)
21+ [ SetUp ]
22+ public void BeforeEach ( )
23+ {
24+ // Use Chrome browser
25+ driver = new ChromeDriver ( ) ;
2826
29- // Create a runner with concurrency of 10
30- VisualGridRunner runner = new VisualGridRunner ( 10 ) ;
27+ //Create a runner with concurrency of 10
28+ runner = new VisualGridRunner ( 10 ) ;
3129
32- // Create Eyes object with the runner, meaning it'll be a Visual Grid eyes .
33- Eyes eyes = new Eyes ( runner ) ;
30+ // Initialize the eyes SDK (IMPORTANT: make sure your API key is set in the APPLITOOLS_API_KEY env variable) .
31+ eyes = new Eyes ( runner ) ;
3432
3533 // Get current Eyes configuration object
3634 Configuration conf = eyes . GetConfiguration ( ) ;
3735
3836
39- //conf.SetApiKey("APPLITOOLS_API_KEY"); // Set the Applitools API KEY here or as an environment variable "APPLITOOLS_API_KEY"
40- conf . SetTestName ( "C# VisualGrid demo" ) // Set test name
41- . SetAppName ( "Demo app" ) ; // Set app name
37+ conf . SetApiKey ( "APPLITOOLS_API_KEY" ) ; // Set the Applitools API KEY here or as an environment variable "APPLITOOLS_API_KEY"
4238
4339 // Add browsers with different viewports
4440 conf . AddBrowser ( 800 , 600 , BrowserType . CHROME ) ;
4541 conf . AddBrowser ( 700 , 500 , BrowserType . FIREFOX ) ;
46- conf . AddBrowser ( 1200 , 800 , BrowserType . IE_10 ) ;
4742 conf . AddBrowser ( 1600 , 1200 , BrowserType . IE_11 ) ;
48- conf . AddBrowser ( 1024 , 768 , BrowserType . EDGE ) ;
43+ conf . AddBrowser ( 1024 , 768 , BrowserType . EDGE_CHROMIUM ) ;
4944 conf . AddBrowser ( 800 , 600 , BrowserType . SAFARI ) ;
5045
5146 // Add iPhone 4 device emulation in Portrait mode
52- conf . AddDeviceEmulation ( DeviceName . iPhone_4 , ScreenOrientation . Portrait ) ;
47+ conf . AddDeviceEmulation ( DeviceName . iPhone_X , ScreenOrientation . Portrait ) ;
48+ conf . AddDeviceEmulation ( DeviceName . Pixel_2 , ScreenOrientation . Portrait ) ;
5349
5450
5551 // Set the configuration object to eyes
5652 eyes . SetConfiguration ( conf ) ;
53+ }
5754
58- try
59- {
60- // Call Open on eyes to initialize a test session
61- eyes . Open ( webDriver ) ;
55+ [ Test ]
56+ public void VGTest ( )
57+ {
58+ // Navigate to the url we want to test
59+ driver . Url = "https://demo.applitools.com" ;
60+ // ⭐️ Note to see visual bugs, run the test using the above URL for the 1st run.
61+ //but then change the above URL to https://demo.applitools.com/index_v2.html (for the 2nd run)
62+
63+ // Call Open on eyes to initialize a test session
64+ eyes . Open ( driver , "Demo App" , "Ultrafast grid demo" ) ;
6265
63- // check the login page
64- eyes . Check ( Target . Window ( ) . Fully ( ) . WithName ( "Login page" ) ) ;
65- webDriver . FindElement ( By . Id ( "log-in" ) ) . Click ( ) ;
66+ // check the login page
67+ eyes . Check ( Target . Window ( ) . Fully ( ) . WithName ( "Login page" ) ) ;
68+ driver . FindElement ( By . Id ( "log-in" ) ) . Click ( ) ;
6669
67- // Check the app page
68- eyes . Check ( Target . Window ( ) . Fully ( ) . WithName ( "App page" ) ) ;
70+ // Check the app page
71+ eyes . Check ( Target . Window ( ) . Fully ( ) . WithName ( "App page" ) ) ;
6972
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- }
73+ // Call Close on eyes to let the server know it should display the results
74+ eyes . CloseAsync ( ) ;
75+ }
7876
77+ [ TearDown ]
78+ public void AfterEach ( )
79+ {
80+ // Close the browser
81+ driver . Quit ( ) ;
7982 // Wait and collect all test results
80- TestResultsSummary allTestResults = runner . GetAllTestResults ( ) ;
81- TestContext . Progress . WriteLine ( allTestResults ) ;
83+ // we pass false to this method to suppress the exception that is thrown if we
84+ // find visual differences
85+ TestResultsSummary allTestResults = runner . GetAllTestResults ( false ) ;
86+ // Print results
87+ System . Console . WriteLine ( allTestResults ) ;
88+ // If the test was aborted before eyes.close was called, ends the test as aborted.
89+ eyes . AbortIfNotClosed ( ) ;
8290 }
8391
8492 }
0 commit comments