Skip to content

Commit 99a4745

Browse files
authored
Merge pull request #4 from itaibh/master
updated visual grid tutorial.
2 parents fad0895 + e5c9fdb commit 99a4745

2 files changed

Lines changed: 38 additions & 28 deletions

File tree

ApplitoolsTutorial/ApplitoolsTutorial.csproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<ApplicationIcon />
6-
<OutputType>Exe</OutputType>
7-
<StartupObject>ApplitoolsTutorial.Program</StartupObject>
6+
<OutputType>Library</OutputType>
7+
<StartupObject></StartupObject>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Eyes.Selenium" Version="2.22.27" />
11+
<PackageReference Include="Eyes.Selenium" Version="2.22.31" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
13+
<PackageReference Include="NUnit" Version="3.12.0" />
14+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
1218
</ItemGroup>
1319

1420
<ItemGroup>
Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Applitools;
22
using Applitools.Selenium;
33
using Applitools.VisualGrid;
4+
using NUnit.Framework;
45
using OpenQA.Selenium;
56
using OpenQA.Selenium.Chrome;
67
using Configuration = Applitools.Selenium.Configuration;
@@ -9,15 +10,12 @@
910
namespace 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

Comments
 (0)