Skip to content

Commit 6944a16

Browse files
authored
Merge pull request #5 from YuriiChere/master
Update tutorial test and README
2 parents fda9179 + 07cc3c3 commit 6944a16

3 files changed

Lines changed: 54 additions & 43 deletions

File tree

ApplitoolsTutorial/ApplitoolsTutorial.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Eyes.Selenium" Version="2.22.31" />
11+
<PackageReference Include="Eyes.Selenium" Version="*" />
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
1313
<PackageReference Include="NUnit" Version="3.12.0" />
1414
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">

ApplitoolsTutorial/VisualGridDemo.cs

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
1. Git clone this repo
1313
* `git clone https://github.com/applitools/tutorial-selenium-csharp-ultrafastgrid.git`
1414
2. Open the folder `tutorial-selenium-csharp-ultrafastgrid`
15-
3. Double click the `ApplitoolsTutorial.sln`. This will open the project in Visual Studio
16-
3. Change the `APPLITOOLS_API_KEY` with your own.
15+
3. Get your API key to set it in code (or in the APPLITOOLS_API_KEY environment variable).
16+
* You can get your API key by logging into Applitools > Person Icon > My API Key.
17+
4. Double click the `ApplitoolsTutorial.sln`. This will open the project in Visual Studio
18+
5. Change the `APPLITOOLS_API_KEY` with your own.
1719
* Login to Applitools > Click on the Person icon > My API Key
18-
4. Hit Run
20+
Set your ApiKey in string 'conf.SetApiKey("...") ' (or comment the string and set APPLITOOLS_API_KEY environment variable)
21+
6. Navigate to Test Explorer, select test VGTest and hit Run

0 commit comments

Comments
 (0)