|
| 1 | +using Applitools; |
| 2 | +using Applitools.Selenium; |
| 3 | +using Applitools.VisualGrid; |
| 4 | +using OpenQA.Selenium; |
| 5 | +using OpenQA.Selenium.Chrome; |
| 6 | +using System; |
| 7 | +using System.Drawing; |
| 8 | +using Configuration = Applitools.Selenium.Configuration; |
| 9 | +using ScreenOrientation = Applitools.VisualGrid.ScreenOrientation; |
| 10 | + |
| 11 | +namespace ApplitoolsTutorial |
| 12 | +{ |
| 13 | + public class UFGDemo |
| 14 | + { |
| 15 | + |
| 16 | + public static void Main(string[] args) |
| 17 | + { |
| 18 | + // Create a new chrome web driver |
| 19 | + IWebDriver webDriver = new ChromeDriver(); |
| 20 | + |
| 21 | + // Create a runner with concurrency of 1 |
| 22 | + VisualGridRunner runner = new VisualGridRunner(1); |
| 23 | + |
| 24 | + // Create Eyes object with the runner, meaning it'll be a Visual Grid eyes. |
| 25 | + Eyes eyes = new Eyes(runner); |
| 26 | + |
| 27 | + SetUp(eyes); |
| 28 | + |
| 29 | + try |
| 30 | + { |
| 31 | + // ⭐️ Note to see visual bugs, run the test using the above URL for the 1st run. |
| 32 | + // but then change the above URL to https://demo.applitools.com/index_v2.html |
| 33 | + // (for the 2nd run) |
| 34 | + UltraFastTest(webDriver, eyes); |
| 35 | + |
| 36 | + } |
| 37 | + finally |
| 38 | + { |
| 39 | + TearDown(webDriver, runner); |
| 40 | + } |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + public static void SetUp(Eyes eyes) |
| 45 | + { |
| 46 | + |
| 47 | + // Initialize eyes Configuration |
| 48 | + Configuration config = new Configuration(); |
| 49 | + |
| 50 | + // You can get your api key from the Applitools dashboard |
| 51 | + config.SetApiKey("APPLITOOLS_API_KEY"); |
| 52 | + |
| 53 | + // create a new batch info instance and set it to the configuration |
| 54 | + config.SetBatch(new BatchInfo("Ultrafast Batch")); |
| 55 | + |
| 56 | + // Add browsers with different viewports |
| 57 | + config.AddBrowser(800, 600, BrowserType.CHROME); |
| 58 | + config.AddBrowser(700, 500, BrowserType.FIREFOX); |
| 59 | + config.AddBrowser(1600, 1200, BrowserType.IE_11); |
| 60 | + config.AddBrowser(1024, 768, BrowserType.EDGE_CHROMIUM); |
| 61 | + config.AddBrowser(800, 600, BrowserType.SAFARI); |
| 62 | + |
| 63 | + // Add mobile emulation devices in Portrait mode |
| 64 | + config.AddDeviceEmulation(DeviceName.iPhone_X, ScreenOrientation.Portrait); |
| 65 | + config.AddDeviceEmulation(DeviceName.Pixel_2, ScreenOrientation.Portrait); |
| 66 | + |
| 67 | + // Set the configuration object to eyes |
| 68 | + eyes.SetConfiguration(config); |
| 69 | + |
| 70 | + } |
| 71 | + |
| 72 | + public static void UltraFastTest(IWebDriver webDriver, Eyes eyes) |
| 73 | + { |
| 74 | + |
| 75 | + try |
| 76 | + { |
| 77 | + |
| 78 | + // Navigate to the url we want to test |
| 79 | + webDriver.Url = "https://demo.applitools.com"; |
| 80 | + |
| 81 | + // Call Open on eyes to initialize a test session |
| 82 | + eyes.Open(webDriver, "Demo App", "Ultrafast grid demo", new Size(800, 600)); |
| 83 | + |
| 84 | + // check the login page with fluent api, see more info here |
| 85 | + // https://applitools.com/docs/topics/sdk/the-eyes-sdk-check-fluent-api.html |
| 86 | + eyes.Check(Target.Window().Fully().WithName("Login page")); |
| 87 | + |
| 88 | + webDriver.FindElement(By.Id("log-in")).Click(); |
| 89 | + |
| 90 | + // Check the app page |
| 91 | + eyes.Check(Target.Window().Fully().WithName("App page")); |
| 92 | + |
| 93 | + // Call Close on eyes to let the server know it should display the results |
| 94 | + eyes.CloseAsync(); |
| 95 | + |
| 96 | + } |
| 97 | + catch (Exception e) |
| 98 | + { |
| 99 | + eyes.AbortAsync(); |
| 100 | + } |
| 101 | + |
| 102 | + } |
| 103 | + |
| 104 | + private static void TearDown(IWebDriver webDriver, VisualGridRunner runner) |
| 105 | + { |
| 106 | + // Close the browser |
| 107 | + webDriver.Quit(); |
| 108 | + |
| 109 | + // we pass false to this method to suppress the exception that is thrown if we |
| 110 | + // find visual differences |
| 111 | + TestResultsSummary allTestResults = runner.GetAllTestResults(false); |
| 112 | + System.Console.WriteLine(allTestResults); |
| 113 | + } |
| 114 | + |
| 115 | + } |
| 116 | +} |
0 commit comments