-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathTestBase.cs
More file actions
75 lines (64 loc) · 2.34 KB
/
Copy pathTestBase.cs
File metadata and controls
75 lines (64 loc) · 2.34 KB
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
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
namespace NUnitExamples;
// Immutable build info for clarity
public static class BuildInfo
{
public static readonly string Name = "DotNet NUnit Examples";
public static readonly string Identifier = $"{Name}: {DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}";
}
[TestFixture]
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
public abstract class TestBase
{
public required IWebDriver Driver { get; set; }
[SetUp]
public void BaseSetUp()
{
string testName = TestContext.CurrentContext.Test.Name;
var options = new ChromeOptions();
options.AddUserProfilePreference("profile.password_manager_leak_detection", false);
var sauceOptions = new Dictionary<string, object?>
{
["username"] = Environment.GetEnvironmentVariable("SAUCE_USERNAME"),
["accessKey"] = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY"),
["name"] = testName,
["build"] = BuildInfo.Identifier,
["seleniumVersion"] = "4.33.0"
};
options.AddAdditionalOption("sauce:options", sauceOptions);
options.PlatformName = "Windows 11";
Driver = new RemoteWebDriver(new Uri("https://ondemand.us-west-1.saucelabs.com/wd/hub"), options);
}
[TearDown]
public void BaseTearDown()
{
try
{
string sessionId = ((RemoteWebDriver)Driver).SessionId.ToString();
string testName = TestContext.CurrentContext.Test.Name;
string result = TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed ? "passed" : "failed";
((IJavaScriptExecutor)Driver).ExecuteScript($"sauce:job-result={result}");
Console.WriteLine($"SauceOnDemandSessionID={sessionId} job-name={testName}");
Console.WriteLine($"Test Job Link: https://app.saucelabs.com/tests/{sessionId}");
}
catch (Exception e)
{
Console.WriteLine("Problem updating Sauce job result: " + e);
}
finally
{
try
{
Driver.Quit();
}
catch (Exception e)
{
Console.WriteLine("Problem quitting driver: " + e);
}
}
}
}