forked from nikolay-advolodkin/dot-net-sauce
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathVisualTests.cs
87 lines (73 loc) · 2.76 KB
/
VisualTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using Core.BestPractices.Web.DesktopWebPageObjects;
using FluentAssertions;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace Core.BestPractices.Web.Tests.Desktop
{
[TestFixtureSource(typeof(TestConfigData), nameof(TestConfigData.PopularVisualResolutions))]
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class VisualTests : AllTestsBase
{
[SetUp]
public void VisualSetup()
{
SauceOptions = new Dictionary<string, object>
{
["username"] = SauceUserName,
["accessKey"] = SauceAccessKey,
["name"] = TestContext.CurrentContext.Test.Name
};
_visualOptions = new Dictionary<string, object>
{
{"apiKey", ScreenerApiKey},
{"projectName", "Sauce Demo C#"},
{"viewportSize", _viewportSize}
};
if (_browserOptions.BrowserName.Equals("chrome", StringComparison.OrdinalIgnoreCase))
{
((ChromeOptions) _browserOptions).AddAdditionalCapability("sauce:options", SauceOptions, true);
((ChromeOptions) _browserOptions).AddAdditionalCapability("sauce:visual", _visualOptions, true);
}
else
{
_browserOptions.AddAdditionalCapability("sauce:options", SauceOptions);
_browserOptions.AddAdditionalCapability("sauce:visual", _visualOptions);
}
Driver = GetVisualDriver(_browserOptions.ToCapabilities());
}
[TearDown]
public void CleanupVisual()
{
if (Driver == null)
return;
ExecuteSauceCleanupSteps(Driver);
Driver.Quit();
}
private readonly DriverOptions _browserOptions;
private readonly string _viewportSize;
private readonly string _deviceName;
private Dictionary<string, object> _visualOptions;
public VisualTests(DriverOptions browserOptions, string viewportSize, string deviceName)
{
_browserOptions = browserOptions;
_viewportSize = viewportSize;
_deviceName = deviceName;
}
[Test]
public void VisualE2EFlow()
{
JsExecutor.ExecuteScript("/*@visual.init*/", _deviceName);
var loginPage = new LoginPage(Driver);
loginPage.Visit();
loginPage.TakeSnapshot();
loginPage.Login("standard_user");
new ProductsPage(Driver).TakeSnapshot();
var result = (Dictionary<string, object>) JsExecutor.ExecuteScript("/*@visual.end*/");
result["message"].Should().BeNull();
}
}
}