Skip to content

Commit fa6ea0d

Browse files
Merge pull request #7 from YuriiChere/master
Update code according to the same java tutorial
2 parents 795333a + 27c805b commit fa6ea0d

4 files changed

Lines changed: 136 additions & 111 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: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
}

ApplitoolsTutorial/VisualGridDemo.cs

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

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,39 @@
22

33
1. Visual Studio installed on your machine. Workload ".NET desktop development" should be installed in Visual Studio too (if no - add it with Visual Studio Installer)
44
* [Install it from here](https://visualstudio.microsoft.com/downloads/)
5-
2. Chrome Webdriver is on your machine and is in the PATH. Here are some resources from the internet that'll help you.
5+
2. Chrome browser is installed on your machine.
6+
7+
* [Install Chrome browser](https://support.google.com/chrome/answer/95346?co=GENIE.Platform%3DDesktop&hl=en&oco=0)
8+
3. Chrome Webdriver is on your machine and is in the PATH. Here are some resources from the internet that'll help you.
9+
* [Download Chrome Webdriver](https://chromedriver.chromium.org/downloads)
610
* https://splinter.readthedocs.io/en/0.1/setup-chrome.html
711
* https://stackoverflow.com/questions/38081021/using-selenium-on-mac-chrome
812
* https://www.youtube.com/watch?time_continue=182&v=dz59GsdvUF8
13+
4. Git is installed on your machine.
14+
15+
* [Install git](https://www.atlassian.com/git/tutorials/install-git)
16+
5. Restart your machine to implement updated environment variables (need for some OS).
917

1018
# Steps to run this example
1119

1220
1. Git clone this repo
13-
21+
1422
* `git clone https://github.com/applitools/tutorial-selenium-csharp-ultrafastgrid.git`
1523

16-
2. Open the folder `tutorial-selenium-csharp-ultrafastgrid`
24+
2. Get your API key to set it in code (or in the APPLITOOLS_API_KEY environment variable).
1725

18-
3. Get your API key to set it in code (or in the APPLITOOLS_API_KEY environment variable).
19-
2026
* You can get your API key by logging into Applitools > Person Icon > My API Key.
21-
22-
4. Double click the `ApplitoolsTutorial.sln`. This will open the project in Visual Studio
2327

24-
5. Change the `APPLITOOLS_API_KEY` with your own in code.
25-
Set your ApiKey in string 'conf.SetApiKey("...") ' (or comment the string and set APPLITOOLS_API_KEY environment variable)
28+
4. Navigate to folder `tutorial-selenium-csharp-ultrafastgrid` and double click the `ApplitoolsTutorial.sln`. This will open the project in Visual Studio
29+
30+
5. In Visual Studio open file UFGDemo.cs and change the `APPLITOOLS_API_KEY` with your own in code.
31+
Set your ApiKey in string 'config.SetApiKey("...") ' (or comment the string and set APPLITOOLS_API_KEY environment variable)
2632

27-
6. Build the project. It can take several minutes.
33+
6. In Visual Studio open Package Manager Console (Tools > NuGet Package Manager > Package Manager Console) and enter command `dotnet restore` in the console. Command execution can take several minutes.
34+
35+
6. Build the solution (Build > Build Solution). It can take several minutes.
2836

29-
7. Navigate to Test Explorer, select test VGTest and hit Run
37+
7. Run project (Debug > Start Without Debugging). Execution of project can take several minutes.
3038

3139
8. If needed, in case of some problems - update package Eyes.Selenium by NuGet Package Manager - Tools > NuGet Package Manager > Manage Nuget Packages for Solution, tab Updates. Select package for update (Eyes.Selenium), select needed version in right panel and tap Install
3240

0 commit comments

Comments
 (0)