-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
77 lines (66 loc) · 2.11 KB
/
Utils.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
using System;
using System.Collections.Generic;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Safari;
namespace SauceLabs.Visual.IntegrationTests;
internal static class Utils
{
public static Dictionary<string, string> GetSauceOptions()
{
return new Dictionary<string, string>
{
{ "username", GetSauceUsername() },
{ "accessKey", GetSauceAccessKey() }
};
}
public static string GetSauceUsername()
{
var username = Environment.GetEnvironmentVariable("SAUCE_USERNAME");
if (string.IsNullOrEmpty(username))
{
throw new Exception("No SAUCE_USERNAME found");
}
return username;
}
public static string GetSauceAccessKey()
{
var accessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY");
if (string.IsNullOrEmpty(accessKey))
{
throw new Exception("No SAUCE_ACCESS_KEY found");
}
return accessKey;
}
public static string GetSauceRegion()
{
var region = Environment.GetEnvironmentVariable("SAUCE_REGION");
if (string.IsNullOrEmpty(region))
{
return "us-west-1";
}
return region;
}
public static Uri GetOnDemandURL()
{
var regionName = GetSauceRegion();
var tld = regionName == "staging" ? "net" : "com";
return new Uri("https://ondemand." + regionName + ".saucelabs." + tld + "/wd/hub");
}
public static DriverOptions GetBrowserOptions()
{
var browser = Environment.GetEnvironmentVariable("BROWSER_NAME");
DriverOptions browserOptions = browser switch
{
"Firefox" => new FirefoxOptions(),
"Safari" => new SafariOptions(),
_ => new ChromeOptions(),
};
browserOptions.PlatformName =
Environment.GetEnvironmentVariable("PLATFORM_NAME") ?? "Windows 11";
browserOptions.BrowserVersion =
Environment.GetEnvironmentVariable("BROWSER_VERSION") ?? "latest";
return browserOptions;
}
}