Skip to content

Commit 53029fe

Browse files
committed
Update code according to the same java tutorial
1 parent 795333a commit 53029fe

3 files changed

Lines changed: 118 additions & 100 deletions

File tree

ApplitoolsTutorial/ApplitoolsTutorial.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<ApplicationIcon />
6-
<OutputType>Library</OutputType>
6+
<OutputType>Exe</OutputType>
77
<StartupObject></StartupObject>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<PackageReference Include="Eyes.Selenium" Version="*" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="*" />
13-
<PackageReference Include="NUnit" Version="*" />
14-
<PackageReference Include="NUnit3TestAdapter" Version="*">
15-
<PrivateAssets>all</PrivateAssets>
16-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17-
</PackageReference>
1812
</ItemGroup>
1913

2014
<ItemGroup>

ApplitoolsTutorial/UFGDemo.cs

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

ApplitoolsTutorial/VisualGridDemo.cs

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)