Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agray committed Sep 6, 2024
1 parent c0810cf commit ada3e83
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Saucery.Core/Dojo/BrowserVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class BrowserVersion

public BrowserVersion(SupportedPlatform sp, BrowserBase b)
{
Os = sp.os!;
Os = sp.Os!;
PlatformNameForOption = b.PlatformNameForOption;
ScreenResolutions = b.ScreenResolutions;
BrowserName = sp.api_name!;
Expand Down
2 changes: 1 addition & 1 deletion Saucery.Core/Dojo/Browsers/Base/BrowserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class BrowserBase : IBrowser

protected BrowserBase(SupportedPlatform sp, List<string> screenResolutions, string platformNameForOption)
{
Os = sp.os!;
Os = sp.Os!;
PlatformNameForOption = platformNameForOption;
AutomationBackend = sp.automation_backend!;
Name = sp.api_name!;
Expand Down
2 changes: 1 addition & 1 deletion Saucery.Core/Dojo/Browsers/BrowserFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class BrowserFactory
? new AndroidBrowserCreator(sp).Create("Android", null!)
: sp.IsIOSPlatform()
? new IOSBrowserCreator(sp).Create("iOS", null!)
: sp.os switch
: sp.Os switch
{
SauceryConstants.PLATFORM_LINUX => new LinuxBrowserCreator(sp).Create("Linux", screenResolutions),
SauceryConstants.PLATFORM_WINDOWS_11 => new Windows11BrowserCreator(sp).Create("Windows 11", screenResolutions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class ChromeBrowser(SupportedPlatform sp, List<string> screenResolution
bv.Name!.Equals(sp.latest_stable_version) ||
bv.Name.Equals(sp.short_version));

public int MinimumVersion(SupportedPlatform sp) => sp.os switch
public int MinimumVersion(SupportedPlatform sp) => sp.Os switch
{
SauceryConstants.PLATFORM_WINDOWS_11 or
SauceryConstants.PLATFORM_WINDOWS_10 or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class IEBrowser(SupportedPlatform sp, List<string> screenResolutions, s
.Find(bv => bv.Name!.Equals(sp.latest_stable_version) ||
bv.Name.Equals(sp.short_version));

public int MinimumVersion(SupportedPlatform sp) => sp.os switch
public int MinimumVersion(SupportedPlatform sp) => sp.Os switch
{
SauceryConstants.PLATFORM_WINDOWS_10 => 11,
SauceryConstants.PLATFORM_WINDOWS_81 => 11,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class SafariBrowser(SupportedPlatform sp, List<string> screenResolution
.Find(bv => bv.Name!.Equals(sp.latest_stable_version) ||
bv.Name.Equals(sp.short_version));

public int MinimumVersion(SupportedPlatform sp) => sp.os switch
public int MinimumVersion(SupportedPlatform sp) => sp.Os switch
{
SauceryConstants.PLATFORM_MAC_12 => 15,
SauceryConstants.PLATFORM_MAC_11 => 14,
Expand Down
12 changes: 6 additions & 6 deletions Saucery.Core/Dojo/DojoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void AddRealPlatform(this List<PlatformBase> platforms, SupportedP
//first one
p = PlatformFactory.CreateRealPlatform(sp);
if(p == null) {
//SauceLabs may have just added it to the platform cornfigurato. Don't fall over.
//SauceLabs may have just added it to the platform configurator. Don't fall over.
return;
}
platforms.Add(p);
Expand Down Expand Up @@ -57,7 +57,7 @@ public static void AddPlatform(this List<PlatformBase> platforms, SupportedPlatf

foreach(var m in platforms) {
result = platforms
.Find(mp => mp.Name.Equals(sp.os, StringComparison.Ordinal) &&
.Find(mp => mp.Name.Equals(sp.Os, StringComparison.Ordinal) &&
mp.PlatformVersion!.Equals(sp.OsVersion?.Split(".")[0], StringComparison.Ordinal));

if(result != null) {
Expand All @@ -83,7 +83,7 @@ public static void AddPlatform(this List<PlatformBase> platforms, SupportedPlatf
foreach(var m in mobilePlatforms)
{
result = mobilePlatforms
.Find(mp => mp.Name.Equals(sp.os, StringComparison.Ordinal) &&
.Find(mp => mp.Name.Equals(sp.Os, StringComparison.Ordinal) &&
mp.PlatformVersion!.Equals(sp.short_version, StringComparison.Ordinal));

if(result != null) {
Expand All @@ -94,7 +94,7 @@ public static void AddPlatform(this List<PlatformBase> platforms, SupportedPlatf
} else {
foreach (var d in desktopPlatforms)
{
result = desktopPlatforms.Find(dp => dp.Name.Equals(sp.os, StringComparison.Ordinal));
result = desktopPlatforms.Find(dp => dp.Name.Equals(sp.Os, StringComparison.Ordinal));

if (result != null)
{
Expand Down Expand Up @@ -306,12 +306,12 @@ public static PlatformBase FindIOSPlatform(this List<PlatformBase> platforms, Sa
.FirstOrDefault(b => b.Name
.Equals(sp.api_name, StringComparison.Ordinal) &&
b.DeviceName.Equals(sp.long_name, StringComparison.Ordinal) &&
b.Os.Equals(sp.os, StringComparison.Ordinal));
b.Os.Equals(sp.Os, StringComparison.Ordinal));

private static BrowserBase? FindRealBrowser(this IEnumerable<BrowserBase> browsers, SupportedPlatform sp) => browsers
.FirstOrDefault(b => b.Name.Equals(sp.api_name, StringComparison.Ordinal) &&
b.DeviceName.Equals(sp.long_name, StringComparison.Ordinal) &&
b.Os.Equals(sp.os, StringComparison.Ordinal));
b.Os.Equals(sp.Os, StringComparison.Ordinal));

public static BrowserVersion Classify(this BrowserVersion browserVersion)
{
Expand Down
6 changes: 3 additions & 3 deletions Saucery.Core/Dojo/PlatformConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ internal int FindMaxBrowserVersion(SaucePlatform platform)
}

private static List<SupportedPlatform> FindLinuxPlatforms(List<SupportedPlatform> platforms) =>
platforms.FindAll(p => p.os! == "Linux" && p.automation_backend!.Equals("webdriver") && p.device! == null);
platforms.FindAll(p => p.Os! == "Linux" && p.automation_backend!.Equals("webdriver") && p.device! == null);

private static List<SupportedPlatform> FindWindowsPlatforms(List<SupportedPlatform> platforms) =>
platforms.FindAll(p => p.os!.Contains("Windows") && p.automation_backend!.Equals("webdriver"));
platforms.FindAll(p => p.Os!.Contains("Windows") && p.automation_backend!.Equals("webdriver"));

private static List<SupportedPlatform> FindMacPlatforms(List<SupportedPlatform> platforms, IReadOnlyCollection<string> oses) =>
platforms.FindAll(p => oses.Any(o => o.Equals(p.os)) && p.automation_backend!.Equals("webdriver") && !p.api_name!.Equals("ipad") && !p.api_name.Equals("iphone"));
platforms.FindAll(p => oses.Any(o => o.Equals(p.Os)) && p.automation_backend!.Equals("webdriver") && !p.api_name!.Equals("ipad") && !p.api_name.Equals("iphone"));

private static List<SupportedPlatform> FindMobilePlatforms(List<SupportedPlatform> platforms, IReadOnlyCollection<string> apis) =>
platforms.FindAll(p => apis.Any(a => a.Equals(p.api_name)) && p.automation_backend!.Equals("appium"));
Expand Down
2 changes: 1 addition & 1 deletion Saucery.Core/Dojo/Platforms/Base/PlatformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class PlatformBase

protected PlatformBase(SupportedPlatform sp)
{
Name = sp.os!;
Name = sp.Os!;
AutomationBackend = sp.automation_backend!;
RecommendedAppiumVersion = sp.recommended_backend_version!;
SupportedBackendVersions = sp.supported_backend_versions!;
Expand Down
2 changes: 1 addition & 1 deletion Saucery.Core/Dojo/Platforms/DesktopPlatformFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Saucery.Core.Dojo.Platforms;

public class DesktopPlatformFactory {
public static PlatformBase? CreatePlatform(SupportedPlatform sp) => sp.os switch {
public static PlatformBase? CreatePlatform(SupportedPlatform sp) => sp.Os switch {
SauceryConstants.PLATFORM_LINUX => new LinuxPlatformCreator(sp).Create(),
SauceryConstants.PLATFORM_WINDOWS_11 => new Windows11PlatformCreator(sp).Create(),
SauceryConstants.PLATFORM_WINDOWS_10 => new Windows10PlatformCreator(sp).Create(),
Expand Down
5 changes: 4 additions & 1 deletion Saucery.Core/RestAPI/FlowControl/SauceLabsFlowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ protected override bool TooManyTests() {
//Console.WriteLine(@"Debug: {0}", json);
var remainingSection = ExtractJsonSegment(json!, json!.IndexOf("\"remaining", StringComparison.Ordinal), json.Length - 3);
//Console.WriteLine(@"Debug: remainingsection = {0}", remainingSection);
var flowControl = JsonSerializer.Deserialize<FlowControl>(remainingSection);
var flowControl = JsonSerializer.Deserialize<FlowControl>(remainingSection, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});

return flowControl?.remaining!.overall <= 0;
}
Expand Down
3 changes: 1 addition & 2 deletions Saucery.Core/RestAPI/SupportedPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SupportedPlatform {
public string? device { get; set; }
public string? latest_stable_version { get; set; }
public string? automation_backend { get; set; }
public string? os { get; set; }
public string? Os { get; set; }


//REAL DEVICE
Expand All @@ -32,7 +32,6 @@ public class SupportedPlatform {
public bool IsTablet { get; set; }
public List<string>? Manufacturer { get; set; }
public string? ModelNumber { get; set; }
public string? Os { get; set; }
public string? OsVersion { get; set; }
public int PixelsPerPoint { get; set; }
public int RamSize { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public SauceLabsPlatformAcquirer()
}
public override List<SupportedPlatform>? AcquirePlatforms() {
var json = GetJsonResponse(SauceryConstants.SUPPORTED_PLATFORMS_REQUEST);
var supportedPlatforms = JsonSerializer.Deserialize<List<SupportedPlatform>>(json!);
var supportedPlatforms = JsonSerializer.Deserialize<List<SupportedPlatform>>(json!, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});

return supportedPlatforms;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public SauceLabsRealDeviceAcquirer()

public override List<SupportedPlatform>? AcquireRealDevicePlatforms() {
var json = GetJsonResponse(SauceryConstants.SUPPORTED_REALDEVICE_PLATFORMS_REQUEST);
var supportedPlatforms = JsonSerializer.Deserialize<List<SupportedPlatform>>(json!);
var supportedPlatforms = JsonSerializer.Deserialize<List<SupportedPlatform>>(json!, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});

return supportedPlatforms;
}
Expand Down

0 comments on commit ada3e83

Please sign in to comment.