From d3f9a6f449a6b45c925b2b463335bc5c75210239 Mon Sep 17 00:00:00 2001 From: Andrew Gray Date: Sat, 21 Dec 2024 15:50:34 +1100 Subject: [PATCH] Feat/dojo improvement (#207) * dojo improvement * add external tests * target real devices * fix asserts * prepare next tunit release * prepare next release --- .github/workflows/pipeline.yml | 26 +- .../ClickLinkTests.cs | 31 ++ .../DataDrivenTests.cs | 35 ++ .../ExternalMerlin.TUnit.RealDevices.csproj | 8 + .../MyParallelLimit.cs | 8 + .../RequestedPlatformData.cs | 29 ++ ExternalMerlin.TUnit/ClickLinkTests.cs | 31 ++ ExternalMerlin.TUnit/DataDrivenTests.cs | 35 ++ .../ExternalMerlin.TUnit.csproj | 8 + ExternalMerlin.TUnit/MyParallelLimit.cs | 8 + ExternalMerlin.TUnit/RequestedPlatformData.cs | 34 ++ Merlin.TUnit.RealDevices/ClickLinkTests.cs | 2 +- Merlin.TUnit.RealDevices/DataDrivenTests.cs | 21 +- .../Merlin.TUnit.RealDevices.csproj | 2 +- Merlin.TUnit/ClickLinkTests.cs | 2 +- Merlin.TUnit/DataDrivenTests.cs | 21 +- Merlin.TUnit/Merlin.TUnit.csproj | 2 +- Sandbox.TUnit/MethodDataSourceTests.cs | 25 +- Sandbox.TUnit/Sandbox.TUnit.csproj | 2 +- Saucery.Core/DataSources/SauceryTestData.cs | 1 - Saucery.Core/Dojo/DojoExtensions.cs | 408 ++++++++---------- Saucery.Core/Dojo/PlatformConfigurator.cs | 162 ++++--- Saucery.Core/Options/OptionFactory.cs | 32 +- Saucery.TUnit/Saucery.TUnit.csproj | 6 +- Saucery.TUnit/SauceryTBase.cs | 6 - .../PageObjects/GuineaPigPage.cs | 4 +- 26 files changed, 547 insertions(+), 402 deletions(-) create mode 100644 ExternalMerlin.TUnit.RealDevices/ClickLinkTests.cs create mode 100644 ExternalMerlin.TUnit.RealDevices/DataDrivenTests.cs create mode 100644 ExternalMerlin.TUnit.RealDevices/MyParallelLimit.cs create mode 100644 ExternalMerlin.TUnit.RealDevices/RequestedPlatformData.cs create mode 100644 ExternalMerlin.TUnit/ClickLinkTests.cs create mode 100644 ExternalMerlin.TUnit/DataDrivenTests.cs create mode 100644 ExternalMerlin.TUnit/MyParallelLimit.cs create mode 100644 ExternalMerlin.TUnit/RequestedPlatformData.cs diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 15557799..aecc5743 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -337,7 +337,12 @@ jobs: tunit-real-integration-tests: runs-on: ubuntu-latest - needs: tunit-integration-tests + needs: [nunit-integration-tests, + xunit-integration-tests, + xunit-external-tests, + nunit-external-tests, + xunit-real-external-tests, + nunit-real-external-tests] steps: - name: Checkout Code @@ -372,7 +377,8 @@ jobs: tunit-external-tests: runs-on: ubuntu-latest - needs: tunit-real-integration-tests + needs: [tunit-real-integration-tests, + tunit-integration-tests] steps: - name: Checkout Code @@ -392,7 +398,8 @@ jobs: tunit-real-external-tests: runs-on: ubuntu-latest - needs: tunit-external-tests + needs: [tunit-real-integration-tests, + tunit-integration-tests] steps: - name: Checkout Code @@ -412,18 +419,7 @@ jobs: generate-report: runs-on: ubuntu-latest - needs: [build, - nunit-integration-tests, - xunit-integration-tests, - nunit-real-integration-tests, - xunit-real-integration-tests, - nunit-external-tests, - xunit-external-tests, - nunit-real-external-tests, - xunit-real-external-tests, - tunit-integration-tests, - tunit-real-integration-tests, - tunit-external-tests, + needs: [tunit-external-tests, tunit-real-external-tests] steps: diff --git a/ExternalMerlin.TUnit.RealDevices/ClickLinkTests.cs b/ExternalMerlin.TUnit.RealDevices/ClickLinkTests.cs new file mode 100644 index 00000000..ddea694d --- /dev/null +++ b/ExternalMerlin.TUnit.RealDevices/ClickLinkTests.cs @@ -0,0 +1,31 @@ +using ExternalMerlin.TUnit.RealDevices; +using Saucery.Core.Dojo; +using Saucery.Tests.Common.PageObjects; +using Saucery.TUnit; +using Shouldly; + +[assembly: ParallelLimiter] + +namespace ExternalMerlin.TUnit.RealDevices; + +public class ClickLinkTests : SauceryTBase +{ + [Test] + [MethodDataSource(typeof(RequestedPlatformData), nameof(RequestedPlatformData.AllPlatforms))] + public async Task ClickLinkTest(BrowserVersion requestedPlatform) + { + InitialiseDriver(requestedPlatform); + + var guineaPigPage = new GuineaPigPage(SauceryDriver(), "https://saucelabs.com/"); + + guineaPigPage.ClickLink(SauceryDriver()); + + // verify the browser was navigated to the correct page + await Assert.That(Driver!.Url).Contains("saucelabs.com/test-guinea-pig2.html"); + } +} +/* +* Copyright Andrew Gray, SauceForge +* Date: 7th December 2024 +* +*/ \ No newline at end of file diff --git a/ExternalMerlin.TUnit.RealDevices/DataDrivenTests.cs b/ExternalMerlin.TUnit.RealDevices/DataDrivenTests.cs new file mode 100644 index 00000000..31b9d64f --- /dev/null +++ b/ExternalMerlin.TUnit.RealDevices/DataDrivenTests.cs @@ -0,0 +1,35 @@ +using Saucery.Core.Dojo; +using Saucery.Tests.Common.PageObjects; +using Saucery.TUnit; + +namespace ExternalMerlin.TUnit.RealDevices; + +public class DataDrivenTests : SauceryTBase +{ + [Test] + [MethodDataSource(nameof(AllCombinations), Arguments = [new[] { 4, 5 }])] + public async Task DataDrivenTest(BrowserVersion requestedPlatform, int data) + { + InitialiseDriver(requestedPlatform); + + var guineaPigPage = new GuineaPigPage(SauceryDriver(), "https://saucelabs.com/"); + + guineaPigPage.TypeField(SauceryDriver(), "comments", data.ToString()); + + var commentField = guineaPigPage.GetField(SauceryDriver(), "comments"); + await Assert.That(commentField).IsNotNull(); + + var commentText = commentField.GetDomProperty("value"); + await Assert.That(commentText).Contains(data.ToString()); + } + + public static IEnumerable<(BrowserVersion, int)> AllCombinations(int[] data) => from browserVersion in RequestedPlatformData.AllPlatformsAsList() + from datum in data + select (browserVersion, datum); +} + +/* +* Copyright Andrew Gray, SauceForge +* Date: 7th December 2024 +* +*/ \ No newline at end of file diff --git a/ExternalMerlin.TUnit.RealDevices/ExternalMerlin.TUnit.RealDevices.csproj b/ExternalMerlin.TUnit.RealDevices/ExternalMerlin.TUnit.RealDevices.csproj index 125f4c93..4cb7bcfe 100644 --- a/ExternalMerlin.TUnit.RealDevices/ExternalMerlin.TUnit.RealDevices.csproj +++ b/ExternalMerlin.TUnit.RealDevices/ExternalMerlin.TUnit.RealDevices.csproj @@ -6,4 +6,12 @@ enable + + + + + + + + diff --git a/ExternalMerlin.TUnit.RealDevices/MyParallelLimit.cs b/ExternalMerlin.TUnit.RealDevices/MyParallelLimit.cs new file mode 100644 index 00000000..10abc461 --- /dev/null +++ b/ExternalMerlin.TUnit.RealDevices/MyParallelLimit.cs @@ -0,0 +1,8 @@ +using TUnit.Core.Interfaces; + +namespace ExternalMerlin.TUnit.RealDevices; + +public record MyParallelLimit : IParallelLimit +{ + public int Limit => 3; +} diff --git a/ExternalMerlin.TUnit.RealDevices/RequestedPlatformData.cs b/ExternalMerlin.TUnit.RealDevices/RequestedPlatformData.cs new file mode 100644 index 00000000..110b17af --- /dev/null +++ b/ExternalMerlin.TUnit.RealDevices/RequestedPlatformData.cs @@ -0,0 +1,29 @@ +using Saucery.Core.DataSources; +using Saucery.Core.Dojo; +using Saucery.Core.OnDemand; +using Saucery.Core.OnDemand.Base; + +namespace ExternalMerlin.TUnit.RealDevices; + +public class RequestedPlatformData : SauceryTestData +{ + static RequestedPlatformData() + { + var platforms = new List + { + //Real Devices + new AndroidRealDevice("Google.*", "15"), + new IOSRealDevice("iPhone 14 Pro Max", "16"), + }; + + SetPlatforms(platforms); + } + + public static List> AllPlatforms() => GetAllPlatformsAsFunc(); + public static List AllPlatformsAsList() => GetAllPlatformsAsList(); +} +/* +* Copyright Andrew Gray, SauceForge +* Date: 12th July 2024 +* +*/ \ No newline at end of file diff --git a/ExternalMerlin.TUnit/ClickLinkTests.cs b/ExternalMerlin.TUnit/ClickLinkTests.cs new file mode 100644 index 00000000..77bba556 --- /dev/null +++ b/ExternalMerlin.TUnit/ClickLinkTests.cs @@ -0,0 +1,31 @@ +using ExternalMerlin.TUnit; +using Saucery.Core.Dojo; +using Saucery.Tests.Common.PageObjects; +using Saucery.TUnit; +using Shouldly; + +[assembly: ParallelLimiter] + +namespace ExternalMerlin.TUnit; + +public class ClickLinkTests : SauceryTBase +{ + [Test] + [MethodDataSource(typeof(RequestedPlatformData), nameof(RequestedPlatformData.AllPlatforms))] + public async Task ClickLinkTest(BrowserVersion requestedPlatform) + { + InitialiseDriver(requestedPlatform); + + var guineaPigPage = new GuineaPigPage(SauceryDriver(), "https://saucelabs.com/"); + + guineaPigPage.ClickLink(SauceryDriver()); + + // verify the browser was navigated to the correct page + await Assert.That(Driver!.Url).Contains("saucelabs.com/test-guinea-pig2.html"); + } +} +/* +* Copyright Andrew Gray, SauceForge +* Date: 7th December 2024 +* +*/ \ No newline at end of file diff --git a/ExternalMerlin.TUnit/DataDrivenTests.cs b/ExternalMerlin.TUnit/DataDrivenTests.cs new file mode 100644 index 00000000..06d27fcd --- /dev/null +++ b/ExternalMerlin.TUnit/DataDrivenTests.cs @@ -0,0 +1,35 @@ +using Saucery.Core.Dojo; +using Saucery.Tests.Common.PageObjects; +using Saucery.TUnit; + +namespace ExternalMerlin.TUnit; + +public class DataDrivenTests : SauceryTBase +{ + [Test] + [MethodDataSource(nameof(AllCombinations), Arguments = [new[] { 4, 5 }])] + public async Task DataDrivenTest(BrowserVersion requestedPlatform, int data) + { + InitialiseDriver(requestedPlatform); + + var guineaPigPage = new GuineaPigPage(SauceryDriver(), "https://saucelabs.com/"); + + guineaPigPage.TypeField(SauceryDriver(), "comments", data.ToString()); + + var commentField = guineaPigPage.GetField(SauceryDriver(), "comments"); + await Assert.That(commentField).IsNotNull(); + + var commentText = commentField.GetDomProperty("value"); + await Assert.That(commentText).Contains(data.ToString()); + } + + public static IEnumerable<(BrowserVersion, int)> AllCombinations(int[] data) => from browserVersion in RequestedPlatformData.AllPlatformsAsList() + from datum in data + select (browserVersion, datum); +} + +/* +* Copyright Andrew Gray, SauceForge +* Date: 7th December 2024 +* +*/ \ No newline at end of file diff --git a/ExternalMerlin.TUnit/ExternalMerlin.TUnit.csproj b/ExternalMerlin.TUnit/ExternalMerlin.TUnit.csproj index 125f4c93..4cb7bcfe 100644 --- a/ExternalMerlin.TUnit/ExternalMerlin.TUnit.csproj +++ b/ExternalMerlin.TUnit/ExternalMerlin.TUnit.csproj @@ -6,4 +6,12 @@ enable + + + + + + + + diff --git a/ExternalMerlin.TUnit/MyParallelLimit.cs b/ExternalMerlin.TUnit/MyParallelLimit.cs new file mode 100644 index 00000000..0214c40d --- /dev/null +++ b/ExternalMerlin.TUnit/MyParallelLimit.cs @@ -0,0 +1,8 @@ +using TUnit.Core.Interfaces; + +namespace ExternalMerlin.TUnit; + +public record MyParallelLimit : IParallelLimit +{ + public int Limit => 3; +} diff --git a/ExternalMerlin.TUnit/RequestedPlatformData.cs b/ExternalMerlin.TUnit/RequestedPlatformData.cs new file mode 100644 index 00000000..fb8057c3 --- /dev/null +++ b/ExternalMerlin.TUnit/RequestedPlatformData.cs @@ -0,0 +1,34 @@ +using Saucery.Core.DataSources; +using Saucery.Core.Dojo; +using Saucery.Core.OnDemand; +using Saucery.Core.OnDemand.Base; +using Saucery.Core.Util; + +namespace ExternalMerlin.TUnit; + +public class RequestedPlatformData : SauceryTestData +{ + static RequestedPlatformData() + { + var platforms = new List + { + //Emulated Mobile Platforms + new AndroidPlatform("Google Pixel 8 Pro GoogleAPI Emulator", "15.0", SauceryConstants.DEVICE_ORIENTATION_PORTRAIT), + new IOSPlatform("iPhone 14 Pro Max Simulator", "16.2", SauceryConstants.DEVICE_ORIENTATION_LANDSCAPE), + + //Desktop Platforms + new DesktopPlatform(SauceryConstants.PLATFORM_WINDOWS_11, SauceryConstants.BROWSER_CHROME, "123"), + new DesktopPlatform(SauceryConstants.PLATFORM_WINDOWS_10, SauceryConstants.BROWSER_CHROME, "124", SauceryConstants.SCREENRES_2560_1600) + }; + + SetPlatforms(platforms); + } + + public static List> AllPlatforms() => GetAllPlatformsAsFunc(); + public static List AllPlatformsAsList() => GetAllPlatformsAsList(); +} +/* +* Copyright Andrew Gray, SauceForge +* Date: 12th July 2024 +* +*/ \ No newline at end of file diff --git a/Merlin.TUnit.RealDevices/ClickLinkTests.cs b/Merlin.TUnit.RealDevices/ClickLinkTests.cs index f271eba0..a3f7967c 100644 --- a/Merlin.TUnit.RealDevices/ClickLinkTests.cs +++ b/Merlin.TUnit.RealDevices/ClickLinkTests.cs @@ -21,7 +21,7 @@ public async Task ClickLinkTest(BrowserVersion requestedPlatform) guineaPigPage.ClickLink(SauceryDriver()); // verify the browser was navigated to the correct page - Driver!.Url.ShouldContain("saucelabs.com/test-guinea-pig2.html"); + await Assert.That(Driver!.Url).Contains("saucelabs.com/test-guinea-pig2.html"); } } /* diff --git a/Merlin.TUnit.RealDevices/DataDrivenTests.cs b/Merlin.TUnit.RealDevices/DataDrivenTests.cs index 434abae2..37efcedc 100644 --- a/Merlin.TUnit.RealDevices/DataDrivenTests.cs +++ b/Merlin.TUnit.RealDevices/DataDrivenTests.cs @@ -7,7 +7,7 @@ namespace Merlin.TUnit.RealDevices; public class DataDrivenTests : SauceryTBase { [Test] - [MethodDataSource(nameof(AllCombinations), Arguments = [ new[] { 4, 5 } ])] + [MethodDataSource(nameof(AllCombinations), Arguments = [new[] { 4, 5 }])] public async Task DataDrivenTest(BrowserVersion requestedPlatform, int data) { InitialiseDriver(requestedPlatform); @@ -15,18 +15,17 @@ public async Task DataDrivenTest(BrowserVersion requestedPlatform, int data) var guineaPigPage = new GuineaPigPage(SauceryDriver(), "https://saucelabs.com/"); guineaPigPage.TypeField(SauceryDriver(), "comments", data.ToString()); - } - public static IEnumerable<(BrowserVersion, int)> AllCombinations(int[] data) - { - foreach (var browserVersion in RequestedPlatformData.AllPlatformsAsList()) - { - foreach (var datum in data) - { - yield return (browserVersion, datum); - } - } + var commentField = guineaPigPage.GetField(SauceryDriver(), "comments"); + await Assert.That(commentField).IsNotNull(); + + var commentText = commentField.GetDomProperty("value"); + await Assert.That(commentText).Contains(data.ToString()); } + + public static IEnumerable<(BrowserVersion, int)> AllCombinations(int[] data) => from browserVersion in RequestedPlatformData.AllPlatformsAsList() + from datum in data + select (browserVersion, datum); } /* diff --git a/Merlin.TUnit.RealDevices/Merlin.TUnit.RealDevices.csproj b/Merlin.TUnit.RealDevices/Merlin.TUnit.RealDevices.csproj index 8a71d1d1..b6e6fead 100644 --- a/Merlin.TUnit.RealDevices/Merlin.TUnit.RealDevices.csproj +++ b/Merlin.TUnit.RealDevices/Merlin.TUnit.RealDevices.csproj @@ -15,7 +15,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Merlin.TUnit/ClickLinkTests.cs b/Merlin.TUnit/ClickLinkTests.cs index 95e8ade7..92e9cc88 100644 --- a/Merlin.TUnit/ClickLinkTests.cs +++ b/Merlin.TUnit/ClickLinkTests.cs @@ -21,7 +21,7 @@ public async Task ClickLinkTest(BrowserVersion requestedPlatform) guineaPigPage.ClickLink(SauceryDriver()); // verify the browser was navigated to the correct page - Driver!.Url.ShouldContain("saucelabs.com/test-guinea-pig2.html"); + await Assert.That(Driver!.Url).Contains("saucelabs.com/test-guinea-pig2.html"); } } /* diff --git a/Merlin.TUnit/DataDrivenTests.cs b/Merlin.TUnit/DataDrivenTests.cs index 91b487a1..4c8bd338 100644 --- a/Merlin.TUnit/DataDrivenTests.cs +++ b/Merlin.TUnit/DataDrivenTests.cs @@ -7,7 +7,7 @@ namespace Merlin.TUnit; public class DataDrivenTests : SauceryTBase { [Test] - [MethodDataSource(nameof(AllCombinations), Arguments = [ new[] { 4, 5 } ])] + [MethodDataSource(nameof(AllCombinations), Arguments = [new[] { 4, 5 }])] public async Task DataDrivenTest(BrowserVersion requestedPlatform, int data) { InitialiseDriver(requestedPlatform); @@ -15,18 +15,17 @@ public async Task DataDrivenTest(BrowserVersion requestedPlatform, int data) var guineaPigPage = new GuineaPigPage(SauceryDriver(), "https://saucelabs.com/"); guineaPigPage.TypeField(SauceryDriver(), "comments", data.ToString()); - } - public static IEnumerable<(BrowserVersion, int)> AllCombinations(int[] data) - { - foreach (var browserVersion in RequestedPlatformData.AllPlatformsAsList()) - { - foreach (var datum in data) - { - yield return (browserVersion, datum); - } - } + var commentField = guineaPigPage.GetField(SauceryDriver(), "comments"); + await Assert.That(commentField).IsNotNull(); + + var commentText = commentField.GetDomProperty("value"); + await Assert.That(commentText).Contains(data.ToString()); } + + public static IEnumerable<(BrowserVersion, int)> AllCombinations(int[] data) => from browserVersion in RequestedPlatformData.AllPlatformsAsList() + from datum in data + select (browserVersion, datum); } /* diff --git a/Merlin.TUnit/Merlin.TUnit.csproj b/Merlin.TUnit/Merlin.TUnit.csproj index cf7f6e8e..564ca00c 100644 --- a/Merlin.TUnit/Merlin.TUnit.csproj +++ b/Merlin.TUnit/Merlin.TUnit.csproj @@ -15,7 +15,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Sandbox.TUnit/MethodDataSourceTests.cs b/Sandbox.TUnit/MethodDataSourceTests.cs index a1919005..1cf637a9 100644 --- a/Sandbox.TUnit/MethodDataSourceTests.cs +++ b/Sandbox.TUnit/MethodDataSourceTests.cs @@ -1,4 +1,6 @@ -namespace Sandbox.TUnit; +using System.Linq; + +namespace Sandbox.TUnit; public class MethodDataSourceTests { @@ -19,30 +21,21 @@ private int Add(int x, int y) public async Task DataDrivenTest(int first, int second) { Console.WriteLine($"First Second:{first} {second}"); - } - public static IEnumerable<(int, int)> AllCombinations() - { - foreach (var firstInt in new[] { 1, 2 }) - { - foreach (var secondInt in new[] { 4, 5 }) - { - yield return (firstInt, secondInt); - } - } + await Assert.That(first).IsNotNull(); } + + public static IEnumerable<(int, int)> AllCombinations() => from firstInt in new[] { 1, 2 } + from secondInt in new[] { 4, 5 } + select (firstInt, secondInt); } public record AdditionTestData(int value1, int value2, int expectedResult); public static class MyTestDataSources { - public static List> AdditionTestData() - { - return - [ + public static List> AdditionTestData() => [ () => new AdditionTestData(1, 2, 3), () => new AdditionTestData(2, 3, 5) ]; - } } diff --git a/Sandbox.TUnit/Sandbox.TUnit.csproj b/Sandbox.TUnit/Sandbox.TUnit.csproj index ee905ce0..8cdf143a 100644 --- a/Sandbox.TUnit/Sandbox.TUnit.csproj +++ b/Sandbox.TUnit/Sandbox.TUnit.csproj @@ -8,7 +8,7 @@ - + diff --git a/Saucery.Core/DataSources/SauceryTestData.cs b/Saucery.Core/DataSources/SauceryTestData.cs index 3a176636..2b58ac6c 100644 --- a/Saucery.Core/DataSources/SauceryTestData.cs +++ b/Saucery.Core/DataSources/SauceryTestData.cs @@ -2,7 +2,6 @@ using Saucery.Core.OnDemand; using Saucery.Core.OnDemand.Base; using System.Collections; -using System.Linq; namespace Saucery.Core.DataSources; diff --git a/Saucery.Core/Dojo/DojoExtensions.cs b/Saucery.Core/Dojo/DojoExtensions.cs index 339fbcc5..2fd2d405 100644 --- a/Saucery.Core/Dojo/DojoExtensions.cs +++ b/Saucery.Core/Dojo/DojoExtensions.cs @@ -15,314 +15,260 @@ namespace Saucery.Core.Dojo; public static class DojoExtensions { - public static void AddRealPlatform(this List platforms, SupportedPlatform sp) { - var p = platforms.FindRealPlatform(sp); - if(p == null) { - //first one - p = PlatformFactory.CreateRealPlatform(sp); - if(p == null) { - //SauceLabs may have just added it to the platform configurator. Don't fall over. - return; + public static void AddRealPlatform(this List platforms, SupportedPlatform sp) + { + var platform = platforms.FindRealPlatform(sp); + if (platform == null) + { + platform = PlatformFactory.CreateRealPlatform(sp); + if (platform != null) + { + platforms.Add(platform); } - platforms.Add(p); } } public static void AddPlatform(this List platforms, SupportedPlatform sp) { - var p = platforms.FindPlatform(sp); - if (p == null) + var platform = platforms.FindPlatform(sp); + if (platform == null) { - //first one - p = PlatformFactory.CreatePlatform(sp); - if(p == null) + platform = PlatformFactory.CreatePlatform(sp); + if (platform != null) { - //SauceLabs may have just added it to the platform configurator. Don't fall over. - return; + platform.Browsers.AddBrowser(sp, platform.ScreenResolutions!); + platforms.Add(platform); } - p.Browsers.AddBrowser(sp, p.ScreenResolutions!); - platforms.Add(p); } else { - p.Browsers.AddBrowser(sp, p.ScreenResolutions!); + platform.Browsers.AddBrowser(sp, platform.ScreenResolutions!); } } public static PlatformBase? FindRealPlatform(this List platforms, SupportedPlatform sp) => - platforms.Count == 0 - ? null - : platforms - .Find(mp => - mp.Name.Equals(sp.Os, StringComparison.Ordinal) && - mp.PlatformVersion!.Equals(sp.OsVersion?.Split(".")[0], StringComparison.Ordinal)); + platforms.FirstOrDefault(mp => + mp.Name.Equals(sp.Os, StringComparison.Ordinal) && + mp.PlatformVersion!.Equals(sp.OsVersion?.Split(".")[0], StringComparison.Ordinal)); public static PlatformBase? FindPlatform(this List platforms, SupportedPlatform sp) { - if(platforms.Count == 0) - return null; - - var mobilePlatforms = platforms.FindAll(p => p.AutomationBackend.Equals("appium")); - var desktopPlatforms = platforms.FindAll(p=> p.AutomationBackend.Equals("webdriver")); + var mobilePlatforms = platforms.Where(p => p.AutomationBackend.Equals("appium")).ToList(); + var desktopPlatforms = platforms.Where(p => p.AutomationBackend.Equals("webdriver")).ToList(); return sp.IsMobilePlatform() - ? mobilePlatforms - .Find(mp => - mp.Name.Equals(sp.Os, StringComparison.Ordinal) && - mp.PlatformVersion!.Equals(sp.short_version, StringComparison.Ordinal)) - : desktopPlatforms.Find(dp => dp.Name.Equals(sp.Os, StringComparison.Ordinal)); + ? mobilePlatforms.FirstOrDefault(mp => + mp.Name.Equals(sp.Os, StringComparison.Ordinal) && + mp.PlatformVersion!.Equals(sp.short_version, StringComparison.Ordinal)) + : desktopPlatforms.FirstOrDefault(dp => dp.Name.Equals(sp.Os, StringComparison.Ordinal)); } public static void AddBrowser(this List browsers, SupportedPlatform sp, List screenResolutions) { - var b = browsers.FindBrowser(sp); - - if (b == null) { - //first one - b = BrowserFactory.CreateBrowser(sp, screenResolutions); - b?.AddVersion(browsers, sp, false); - } else + var browser = browsers.FindBrowser(sp); + if (browser == null) { - b.AddVersion(browsers, sp, true); + browser = BrowserFactory.CreateBrowser(sp, screenResolutions); + browser?.AddVersion(browsers, sp, false); + } + else + { + browser.AddVersion(browsers, sp, true); } } - //public static void AddRealBrowser(this List browsers, SupportedPlatform sp) { - // var b = browsers.FindRealBrowser(sp); - - // if(b == null) { - // //first one - // b = BrowserFactory.CreateRealBrowser(sp); - // b?.AddVersion(browsers, sp, false); - // } else { - // b.AddVersion(browsers, sp, true); - // } - //} - - private static void AddVersion(this BrowserBase b, List browsers, SupportedPlatform sp, bool findVersion) + private static void AddVersion(this BrowserBase browser, List browsers, SupportedPlatform sp, bool findVersion) { if (findVersion) { - //Browser found or created, now add version - if (b.IsSupportedVersion(sp) && b.FindVersion(sp) == null) + if (browser.IsSupportedVersion(sp) && browser.FindVersion(sp) == null) { - var bv = new BrowserVersion(sp, b); - b.BrowserVersions.Add(bv); + var browserVersion = new BrowserVersion(sp, browser); + browser.BrowserVersions.Add(browserVersion); } } else { - if (b.IsSupportedVersion(sp)) + if (browser.IsSupportedVersion(sp)) { - var bv = new BrowserVersion(sp, b); - b.BrowserVersions.Add(bv); - browsers.Add(b); + var browserVersion = new BrowserVersion(sp, browser); + browser.BrowserVersions.Add(browserVersion); + browsers.Add(browser); } } } - public static IList GetPlatform(this List availablePlatforms) where T : PlatformBase => availablePlatforms.OfType().ToList(); + public static IList GetPlatform(this List availablePlatforms) where T : PlatformBase => + availablePlatforms.OfType().ToList(); public static BrowserVersion? FindDesktopBrowser(this List platforms, SaucePlatform sp) { PlatformBase? platform = sp.Os switch { - SauceryConstants.PLATFORM_LINUX => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_WINDOWS_11 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_WINDOWS_10 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_WINDOWS_81 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_WINDOWS_8 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_WINDOWS_7 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_MAC_13 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_MAC_12 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_MAC_11 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_MAC_1015 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_MAC_1014 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_MAC_1013 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_MAC_1012 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_MAC_1011 => platforms.GetPlatform()[0], - SauceryConstants.PLATFORM_MAC_1010 => platforms.GetPlatform()[0], + SauceryConstants.PLATFORM_LINUX => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_WINDOWS_11 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_WINDOWS_10 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_WINDOWS_81 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_WINDOWS_8 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_WINDOWS_7 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_MAC_13 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_MAC_12 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_MAC_11 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_MAC_1015 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_MAC_1014 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_MAC_1013 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_MAC_1012 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_MAC_1011 => platforms.GetPlatform().FirstOrDefault(), + SauceryConstants.PLATFORM_MAC_1010 => platforms.GetPlatform().FirstOrDefault(), _ => null }; - var browsers = platform?.Browsers.Find(b => - b.Os.Equals(sp.Os, StringComparison.Ordinal) && - b.Name.ToLower().Equals(sp.Browser.ToLower())); - - if (browsers == null) - { - return null; - } + var browser = platform?.Browsers.FirstOrDefault(b => + b.Os.Equals(sp.Os, StringComparison.Ordinal) && + b.Name.Equals(sp.Browser, StringComparison.OrdinalIgnoreCase)); return sp.ScreenResolution == string.Empty - ? browsers.BrowserVersions - .Find(v => - v.Os.Equals(sp.Os, StringComparison.Ordinal) && - v.BrowserName.ToLower().Equals(sp.Browser.ToLower()) && - v.Name!.ToLower().Equals(sp.BrowserVersion.ToLower())) - : browsers.BrowserVersions - .Find(v => - v.Os.Equals(sp.Os, StringComparison.Ordinal) && - v.BrowserName.ToLower().Equals(sp.Browser.ToLower()) && - v.Name!.ToLower().Equals(sp.BrowserVersion.ToLower()) && - v.ScreenResolutions.Contains(sp.ScreenResolution)); + ? browser?.BrowserVersions.FirstOrDefault(v => + v.Os.Equals(sp.Os, StringComparison.Ordinal) && + v.BrowserName.Equals(sp.Browser, StringComparison.OrdinalIgnoreCase) && + v.Name!.Equals(sp.BrowserVersion, StringComparison.OrdinalIgnoreCase)) + : browser?.BrowserVersions.FirstOrDefault(v => + v.Os.Equals(sp.Os, StringComparison.Ordinal) && + v.BrowserName.Equals(sp.Browser, StringComparison.OrdinalIgnoreCase) && + v.Name!.Equals(sp.BrowserVersion, StringComparison.OrdinalIgnoreCase) && + v.ScreenResolutions.Contains(sp.ScreenResolution)); } public static BrowserVersion? FindAndroidBrowser(this List platforms, SaucePlatform sp) { - PlatformBase? platform = null; - var platformToSearchFor = $"{sp.Os} {sp.LongVersion}"; - platform = platformToSearchFor switch { - "Linux 15.0" => platforms.GetPlatform()[0], - "Linux 14.0" => platforms.GetPlatform()[0], - "Linux 13.0" => platforms.GetPlatform()[0], - "Linux 12.0" => platforms.GetPlatform()[0], - "Linux 11.0" => platforms.GetPlatform()[0], - "Linux 10.0" => platforms.GetPlatform()[0], - "Linux 9.0" => platforms.GetPlatform()[0], - "Linux 8.1" => platforms.GetPlatform()[0], - "Linux 8.0" => platforms.GetPlatform()[0], - "Linux 7.1" => platforms.GetPlatform()[0], - "Linux 7.0" => platforms.GetPlatform()[0], - "Linux 6.0" => platforms.GetPlatform()[0], - "Linux 5.1" => platforms.GetPlatform()[0], - _ => platform - }; + string platformToSearchFor = $"{sp.Os} {sp.LongVersion}"; + PlatformBase? platform = platformToSearchFor switch + { + "Linux 15.0" => platforms.GetPlatform().FirstOrDefault(), + "Linux 14.0" => platforms.GetPlatform().FirstOrDefault(), + "Linux 13.0" => platforms.GetPlatform().FirstOrDefault(), + "Linux 12.0" => platforms.GetPlatform().FirstOrDefault(), + "Linux 11.0" => platforms.GetPlatform().FirstOrDefault(), + "Linux 10.0" => platforms.GetPlatform().FirstOrDefault(), + "Linux 9.0" => platforms.GetPlatform().FirstOrDefault(), + "Linux 8.1" => platforms.GetPlatform().FirstOrDefault(), + "Linux 8.0" => platforms.GetPlatform().FirstOrDefault(), + "Linux 7.1" => platforms.GetPlatform().FirstOrDefault(), + "Linux 7.0" => platforms.GetPlatform().FirstOrDefault(), + "Linux 6.0" => platforms.GetPlatform().FirstOrDefault(), + "Linux 5.1" => platforms.GetPlatform().FirstOrDefault(), + _ => null + }; - var browsers = platform?.Browsers - .Find(b => - b.Os.Equals(sp.Os, StringComparison.Ordinal) && - b.DeviceName.Equals(sp.LongName, StringComparison.Ordinal)); + var browser = platform?.Browsers.FirstOrDefault(b => + b.Os.Equals(sp.Os, StringComparison.Ordinal) && + b.DeviceName.Equals(sp.LongName, StringComparison.Ordinal)); - return browsers == null - ? null - : browsers.BrowserVersions.Count == 1 - ? browsers.BrowserVersions[0] - : browsers.BrowserVersions - .Find(v => - v.Os.Equals(sp.Os, StringComparison.Ordinal) && - v.DeviceName.Equals(sp.LongName, StringComparison.Ordinal) && - v.Name!.Equals(sp.BrowserVersion, StringComparison.Ordinal)); + return browser?.BrowserVersions.Count == 1 + ? browser.BrowserVersions[0] + : browser?.BrowserVersions.FirstOrDefault(v => + v.Os.Equals(sp.Os, StringComparison.Ordinal) && + v.DeviceName.Equals(sp.LongName, StringComparison.Ordinal) && + v.Name!.Equals(sp.BrowserVersion, StringComparison.Ordinal)); } - public static PlatformBase FindAndroidPlatform(this List platforms, SaucePlatform sp) { - PlatformBase? platform = null; - var platformToSearchFor = $"{sp.Os} {sp.LongVersion}"; - platform = platformToSearchFor switch { - "Linux 15" => platforms.GetPlatform()[0], - "Linux 14" => platforms.GetPlatform()[0], - "Linux 13" => platforms.GetPlatform()[0], - "Linux 12" => platforms.GetPlatform()[0], - "Linux 11" => platforms.GetPlatform()[0], - "Linux 10" => platforms.GetPlatform()[0], - "Linux 9" => platforms.GetPlatform()[0], - //"Linux 8" => platforms.GetPlatform()[0], - //"Linux 7" => platforms.GetPlatform()[0], - _ => platform + public static PlatformBase? FindAndroidPlatform(this List platforms, SaucePlatform sp) + { + string platformToSearchFor = $"{sp.Os} {sp.LongVersion}"; + return platformToSearchFor switch + { + "Linux 15" => platforms.GetPlatform().FirstOrDefault(), + "Linux 14" => platforms.GetPlatform().FirstOrDefault(), + "Linux 13" => platforms.GetPlatform().FirstOrDefault(), + "Linux 12" => platforms.GetPlatform().FirstOrDefault(), + "Linux 11" => platforms.GetPlatform().FirstOrDefault(), + "Linux 10" => platforms.GetPlatform().FirstOrDefault(), + "Linux 9" => platforms.GetPlatform().FirstOrDefault(), + _ => null }; - - return platform!; } - public static BrowserVersion? FindIOSBrowser(this List platforms, SaucePlatform sp) { - PlatformBase? platform = null; - var platformToSearchFor = $"{sp.Os} {sp.LongVersion}"; - platform = platformToSearchFor switch { - "iOS 17.0" => platforms.GetPlatform()[0], - "iOS 16.2" => platforms.GetPlatform()[0], - "iOS 16.1" => platforms.GetPlatform()[0], - "iOS 16.0" => platforms.GetPlatform()[0], - "iOS 15.4" => platforms.GetPlatform()[0], - "iOS 15.2" => platforms.GetPlatform()[0], - "iOS 15.0" => platforms.GetPlatform()[0], - "iOS 14.5" => platforms.GetPlatform()[0], - "iOS 14.4" => platforms.GetPlatform()[0], - "iOS 14.3" => platforms.GetPlatform()[0], - "iOS 14.0" => platforms.GetPlatform()[0], - "iOS 13.4" => platforms.GetPlatform()[0], - "iOS 13.2" => platforms.GetPlatform()[0], - "iOS 13.0" => platforms.GetPlatform()[0], - "iOS 12.4" => platforms.GetPlatform()[0], - "iOS 12.2" => platforms.GetPlatform()[0], - "iOS 12.0" => platforms.GetPlatform()[0], - "iOS 11.3" => platforms.GetPlatform()[0], - "iOS 11.2" => platforms.GetPlatform()[0], - "iOS 11.1" => platforms.GetPlatform()[0], - "iOS 11.0" => platforms.GetPlatform()[0], - "iOS 10.3" => platforms.GetPlatform()[0], - _ => platform - }; + public static BrowserVersion? FindIOSBrowser(this List platforms, SaucePlatform sp) + { + string platformToSearchFor = $"{sp.Os} {sp.LongVersion}"; + PlatformBase? platform = platformToSearchFor switch + { + "iOS 17.0" => platforms.GetPlatform().FirstOrDefault(), + "iOS 16.2" => platforms.GetPlatform().FirstOrDefault(), + "iOS 16.1" => platforms.GetPlatform().FirstOrDefault(), + "iOS 16.0" => platforms.GetPlatform().FirstOrDefault(), + "iOS 15.4" => platforms.GetPlatform().FirstOrDefault(), + "iOS 15.2" => platforms.GetPlatform().FirstOrDefault(), + "iOS 15.0" => platforms.GetPlatform().FirstOrDefault(), + "iOS 14.5" => platforms.GetPlatform().FirstOrDefault(), + "iOS 14.4" => platforms.GetPlatform().FirstOrDefault(), + "iOS 14.3" => platforms.GetPlatform().FirstOrDefault(), + "iOS 14.0" => platforms.GetPlatform().FirstOrDefault(), + "iOS 13.4" => platforms.GetPlatform().FirstOrDefault(), + "iOS 13.2" => platforms.GetPlatform().FirstOrDefault(), + "iOS 13.0" => platforms.GetPlatform().FirstOrDefault(), + "iOS 12.4" => platforms.GetPlatform().FirstOrDefault(), + "iOS 12.2" => platforms.GetPlatform().FirstOrDefault(), + "iOS 12.0" => platforms.GetPlatform().FirstOrDefault(), + "iOS 11.3" => platforms.GetPlatform().FirstOrDefault(), + "iOS 11.2" => platforms.GetPlatform().FirstOrDefault(), + "iOS 11.1" => platforms.GetPlatform().FirstOrDefault(), + "iOS 11.0" => platforms.GetPlatform().FirstOrDefault(), + "iOS 10.3" => platforms.GetPlatform().FirstOrDefault(), + _ => null + }; - var browsers = platform?.Browsers - .Find(b => - b.PlatformNameForOption.Equals(sp.Os, StringComparison.Ordinal) && - b.DeviceName.Equals(sp.LongName, StringComparison.Ordinal)); + var browser = platform?.Browsers.FirstOrDefault(b => + b.PlatformNameForOption.Equals(sp.Os, StringComparison.Ordinal) && + b.DeviceName.Equals(sp.LongName, StringComparison.Ordinal)); - return browsers == null - ? null - : browsers.BrowserVersions.Count == 1 - ? browsers.BrowserVersions[0] - : browsers.BrowserVersions - .Find(v => - v.PlatformNameForOption.Equals(sp.Os, StringComparison.Ordinal) && - v.DeviceName.Equals(sp.LongName, StringComparison.Ordinal) && - v.Name!.Equals(sp.BrowserVersion, StringComparison.Ordinal)); + return browser?.BrowserVersions.Count == 1 + ? browser.BrowserVersions[0] + : browser?.BrowserVersions.FirstOrDefault(v => + v.PlatformNameForOption.Equals(sp.Os, StringComparison.Ordinal) && + v.DeviceName.Equals(sp.LongName, StringComparison.Ordinal) && + v.Name!.Equals(sp.BrowserVersion, StringComparison.Ordinal)); } - public static PlatformBase FindIOSPlatform(this List platforms, SaucePlatform sp) { - PlatformBase? platform = null; - var platformToSearchFor = $"{sp.Os} {sp.LongVersion}"; - platform = platformToSearchFor switch { - "iOS 18" => platforms.GetPlatform()[0], - "iOS 17" => platforms.GetPlatform()[0], - "iOS 16" => platforms.GetPlatform()[0], - "iOS 15" => platforms.GetPlatform()[0], - "iOS 14" => platforms.GetPlatform()[0], - "iOS 13" => platforms.GetPlatform()[0], - "iOS 12" => platforms.GetPlatform()[0], - _ => platform - }; - - return platform!; + public static PlatformBase? FindIOSPlatform(this List platforms, SaucePlatform sp) + { + string platformToSearchFor = $"{sp.Os} {sp.LongVersion}"; + return platformToSearchFor switch + { + "iOS 18" => platforms.GetPlatform().FirstOrDefault(), + "iOS 17" => platforms.GetPlatform().FirstOrDefault(), + "iOS 16" => platforms.GetPlatform().FirstOrDefault(), + "iOS 15" => platforms.GetPlatform().FirstOrDefault(), + "iOS 14" => platforms.GetPlatform().FirstOrDefault(), + "iOS 13" => platforms.GetPlatform().FirstOrDefault(), + "iOS 12" => platforms.GetPlatform().FirstOrDefault(), + _ => null + }; } - private static BrowserBase? FindBrowser(this IEnumerable browsers, SupportedPlatform sp) => - browsers.FirstOrDefault(b => + private static BrowserBase? FindBrowser(this IEnumerable 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)); - //private static BrowserBase? FindRealBrowser(this IEnumerable 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)); - public static BrowserVersion Classify(this BrowserVersion browserVersion) { - if (browserVersion.IsAnAndroidDevice()) + browserVersion.PlatformType = browserVersion switch { - browserVersion.PlatformType = PlatformType.Android; - return browserVersion; - } - - if (browserVersion.IsAnAppleDevice()) - { - browserVersion.PlatformType = PlatformType.Apple; - return browserVersion; - } - - //Desktop - browserVersion.PlatformType = browserVersion.BrowserName.ToLower() switch - { - SauceryConstants.BROWSER_CHROME => PlatformType.Chrome, - SauceryConstants.BROWSER_FIREFOX => PlatformType.Firefox, - SauceryConstants.BROWSER_IE => PlatformType.IE, - SauceryConstants.BROWSER_EDGE_LOWER => PlatformType.Edge, - SauceryConstants.BROWSER_SAFARI => PlatformType.Safari, - _ => browserVersion.PlatformType + _ when browserVersion.IsAnAndroidDevice() => PlatformType.Android, + _ when browserVersion.IsAnAppleDevice() => PlatformType.Apple, + _ => browserVersion.BrowserName.ToLower() switch + { + SauceryConstants.BROWSER_CHROME => PlatformType.Chrome, + SauceryConstants.BROWSER_FIREFOX => PlatformType.Firefox, + SauceryConstants.BROWSER_IE => PlatformType.IE, + SauceryConstants.BROWSER_EDGE_LOWER => PlatformType.Edge, + SauceryConstants.BROWSER_SAFARI => PlatformType.Safari, + _ => browserVersion.PlatformType + } }; return browserVersion; } -} \ No newline at end of file +} diff --git a/Saucery.Core/Dojo/PlatformConfigurator.cs b/Saucery.Core/Dojo/PlatformConfigurator.cs index ec69adad..d3c50eb6 100644 --- a/Saucery.Core/Dojo/PlatformConfigurator.cs +++ b/Saucery.Core/Dojo/PlatformConfigurator.cs @@ -54,20 +54,19 @@ private void ConstructRealDevices() { var supportedRealDevices = RealDeviceAcquirer.AcquireRealDevicePlatforms(); - foreach(var sp in supportedRealDevices!) { + foreach (var sp in supportedRealDevices!) + { AvailableRealDevices.AddRealPlatform(sp); } } - private static List FilterSupportedPlatforms(List supportedPlatforms) - { - List filteredPlatforms = + private static List FilterSupportedPlatforms(List supportedPlatforms) => [ - //Not filtered for Min and Max Versions yet - .. FindLinuxPlatforms(supportedPlatforms), - .. FindWindowsPlatforms(supportedPlatforms), - .. FindMacPlatforms(supportedPlatforms, [ - SauceryConstants.PLATFORM_MAC_1010, + ..FindLinuxPlatforms(supportedPlatforms), + ..FindWindowsPlatforms(supportedPlatforms), + ..FindMacPlatforms(supportedPlatforms, + [ + SauceryConstants.PLATFORM_MAC_1010, SauceryConstants.PLATFORM_MAC_1011, SauceryConstants.PLATFORM_MAC_1012, SauceryConstants.PLATFORM_MAC_1013, @@ -75,132 +74,121 @@ .. FindMacPlatforms(supportedPlatforms, [ SauceryConstants.PLATFORM_MAC_1015, SauceryConstants.PLATFORM_MAC_11, SauceryConstants.PLATFORM_MAC_12, - SauceryConstants.PLATFORM_MAC_13 ]), - .. FindMobilePlatforms(supportedPlatforms, ["iphone", "ipad"]), - .. FindMobilePlatforms(supportedPlatforms, ["android"]), + SauceryConstants.PLATFORM_MAC_13 + ]), + ..FindMobilePlatforms(supportedPlatforms, ["iphone", "ipad"]), + ..FindMobilePlatforms(supportedPlatforms, ["android"]) ]; - return filteredPlatforms; - } - internal int FindMaxBrowserVersion(SaucePlatform platform) { - //Desktop Platform Only var availablePlatform = AvailablePlatforms.Find(p => p.Name.Equals(platform.Os)); var browser = availablePlatform?.Browsers.Find(b => b.Name.Equals(platform.Browser)); var numericBrowserVersions = browser?.BrowserVersions - .Where(x => - x.Name!.Any(char.IsNumber) && + .Where(x => + x.Name!.Any(char.IsNumber) && x.Name != SauceryConstants.BROWSER_VERSION_LATEST_MINUS1); var browserVersion = numericBrowserVersions? - .Aggregate((maxItem, nextItem) => - int.Parse(maxItem.Name!) > int.Parse(nextItem.Name!) - ? maxItem + .Aggregate((maxItem, nextItem) => + int.Parse(maxItem.Name!) > int.Parse(nextItem.Name!) + ? maxItem : nextItem); return int.Parse(browserVersion?.Name!); } - private static List FindLinuxPlatforms(List platforms) => - platforms.FindAll(p => - p.Os! == "Linux" && - p.automation_backend!.Equals("webdriver") && - p.device! == null); + private static List FindLinuxPlatforms(List platforms) => + platforms.FindAll(p => + p.Os == "Linux" && + p.automation_backend!.Equals("webdriver") && + p.device == null); - private static List FindWindowsPlatforms(List platforms) => - platforms.FindAll(p => - p.Os!.Contains("Windows") && + private static List FindWindowsPlatforms(List platforms) => + platforms.FindAll(p => + p.Os!.Contains("Windows") && p.automation_backend!.Equals("webdriver")); - private static List FindMacPlatforms(List platforms, IReadOnlyCollection oses) => - platforms.FindAll(p => - oses.Any(o => o.Equals(p.Os)) && - p.automation_backend!.Equals("webdriver") && - !p.api_name!.Equals("ipad") && + private static List FindMacPlatforms(List platforms, IReadOnlyCollection 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")); - private static List FindMobilePlatforms(List platforms, IReadOnlyCollection apis) => - platforms.FindAll(p => - apis.Any(a => a.Equals(p.api_name)) && + private static List FindMobilePlatforms(List platforms, IReadOnlyCollection apis) => + platforms.FindAll(p => + apis.Any(a => a.Equals(p.api_name)) && p.automation_backend!.Equals("appium")); public void AddLatestBrowserVersion(string version) { - foreach (var b in AvailablePlatforms - .SelectMany(p => - p.Browsers.Where(b => - p.BrowsersWithLatestVersion != null && + foreach (var browser in AvailablePlatforms + .SelectMany(p => + p.Browsers.Where(b => + p.BrowsersWithLatestVersion != null && p.BrowsersWithLatestVersion.Contains(b.Name)))) { - b.BrowserVersions.Add(new BrowserVersion(b, version, version, null, null)); + browser.BrowserVersions.Add(new BrowserVersion(browser, version, version, null, null)); } } public List FilterAll(List platforms) { - var bvs = (from p in platforms - let bv = Filter(p) - where bv != null - select bv).ToList(); - Console.WriteLine(SauceryConstants.NUM_VALID_PLATFORMS, bvs.Count, platforms.Count); - - return bvs; + var browserVersions = platforms + .Select(Filter) + .Where(bv => bv != null) + .ToList(); + + Console.WriteLine(SauceryConstants.NUM_VALID_PLATFORMS, browserVersions.Count, platforms.Count); + + return browserVersions!; } public BrowserVersion? Filter(SaucePlatform platform) { - if(platform.IsARealDevice()) { - return ValidateReal(platform) != null - ? new BrowserVersion(platform) + if (platform.IsARealDevice()) + { + return ValidateReal(platform) != null + ? new BrowserVersion(platform) : null; } - var bv = Validate(platform); - if(bv != null) { - bv.ScreenResolution = platform.ScreenResolution; - bv.DeviceOrientation = platform.DeviceOrientation; + var browserVersion = Validate(platform); + if (browserVersion != null) + { + browserVersion.ScreenResolution = platform.ScreenResolution; + browserVersion.DeviceOrientation = platform.DeviceOrientation; } - return bv; + return browserVersion; } public BrowserVersion? Validate(SaucePlatform requested) { requested.Classify(); - BrowserVersion? browserVersion; - switch (requested.PlatformType) + BrowserVersion? browserVersion = requested.PlatformType switch { - case PlatformType.Chrome: - case PlatformType.Edge: - case PlatformType.Firefox: - case PlatformType.IE: - case PlatformType.Safari: - browserVersion = AvailablePlatforms.FindDesktopBrowser(requested); - break; - case PlatformType.Android: - browserVersion = AvailablePlatforms.FindAndroidBrowser(requested); - break; - case PlatformType.Apple: - browserVersion = AvailablePlatforms.FindIOSBrowser(requested); - break; - default: - Console.WriteLine("Requested Platform Not Found: {0}", requested.LongName); - return null; - } + PlatformType.Chrome or + PlatformType.Edge or + PlatformType.Firefox or + PlatformType.IE or + PlatformType.Safari => AvailablePlatforms.FindDesktopBrowser(requested), + PlatformType.Android => AvailablePlatforms.FindAndroidBrowser(requested), + PlatformType.Apple => AvailablePlatforms.FindIOSBrowser(requested), + _ => null + }; return browserVersion?.Classify(); } - public PlatformBase? ValidateReal(SaucePlatform requested) { + public PlatformBase? ValidateReal(SaucePlatform requested) + { requested.Classify(); - switch(requested.PlatformType) { - case PlatformType.Android: - return AvailableRealDevices.FindAndroidPlatform(requested); - case PlatformType.Apple: - return AvailableRealDevices.FindIOSPlatform(requested); - default: - Console.WriteLine("Requested Real Platform Not Found: {0}", requested.LongName); - return null; - } + return requested.PlatformType switch + { + PlatformType.Android => AvailableRealDevices.FindAndroidPlatform(requested), + PlatformType.Apple => AvailableRealDevices.FindIOSPlatform(requested), + _ => null + }; } -} \ No newline at end of file +} diff --git a/Saucery.Core/Options/OptionFactory.cs b/Saucery.Core/Options/OptionFactory.cs index 99bfeff7..641cd8be 100644 --- a/Saucery.Core/Options/OptionFactory.cs +++ b/Saucery.Core/Options/OptionFactory.cs @@ -15,41 +15,43 @@ public class OptionFactory(BrowserVersion bv) : IDisposable if (!BrowserVersion.IsAMobileDevice()) { DebugMessages.PrintHaveDesktopPlatform(); - return (GetDesktopOptions(testName), bv); + return (GetDesktopOptions(testName), BrowserVersion); } //Mobile Device - if(BrowserVersion.IsARealDevice()) + if (BrowserVersion.IsARealDevice()) { - if(BrowserVersion.PlatformType.Equals(OnDemand.PlatformType.Apple)) { + if (BrowserVersion.PlatformType.Equals(OnDemand.PlatformType.Apple)) + { DebugMessages.PrintHaveApplePlatform(true); return (new RealDeviceIOSCreator() .Create(BrowserVersion, testName) - .GetOpts(BrowserVersion.PlatformType), - bv); + .GetOpts(BrowserVersion.PlatformType), + BrowserVersion); } DebugMessages.PrintHaveAndroidPlatform(true); return (new RealDeviceAndroidCreator() .Create(BrowserVersion, testName) - .GetOpts(BrowserVersion.PlatformType), - bv); + .GetOpts(BrowserVersion.PlatformType), + BrowserVersion); } //Emulated Mobile Platform - if(BrowserVersion.PlatformType.Equals(OnDemand.PlatformType.Apple)) { + if (BrowserVersion.PlatformType.Equals(OnDemand.PlatformType.Apple)) + { DebugMessages.PrintHaveApplePlatform(false); return (new EmulatedIOSCreator() .Create(BrowserVersion, testName) - .GetOpts(BrowserVersion.PlatformType), - bv); + .GetOpts(BrowserVersion.PlatformType), + BrowserVersion); } DebugMessages.PrintHaveAndroidPlatform(false); return (new EmulatedAndroidCreator() .Create(BrowserVersion, testName) - .GetOpts(BrowserVersion.PlatformType), - bv); + .GetOpts(BrowserVersion.PlatformType), + BrowserVersion); } private DriverOptions? GetDesktopOptions(string testName) => BrowserVersion.BrowserName.ToLower() switch @@ -62,13 +64,13 @@ public class OptionFactory(BrowserVersion bv) : IDisposable _ => new ChromeCreator().Create(BrowserVersion, testName).GetOpts(BrowserVersion.PlatformType), }; - public bool IsApple() => + public bool IsApple() => BrowserVersion.PlatformType.Equals(OnDemand.PlatformType.Apple); - public bool IsAndroid() => + public bool IsAndroid() => BrowserVersion.PlatformType.Equals(OnDemand.PlatformType.Android); - public void Dispose() => + public void Dispose() => GC.SuppressFinalize(this); } /* diff --git a/Saucery.TUnit/Saucery.TUnit.csproj b/Saucery.TUnit/Saucery.TUnit.csproj index 512c3174..d0030719 100644 --- a/Saucery.TUnit/Saucery.TUnit.csproj +++ b/Saucery.TUnit/Saucery.TUnit.csproj @@ -11,7 +11,7 @@ true Saucery.TUnit - 0.5.6 + 0.5.22 README.md Andrew Gray SauceForge @@ -29,8 +29,8 @@ - - + + diff --git a/Saucery.TUnit/SauceryTBase.cs b/Saucery.TUnit/SauceryTBase.cs index ce332a9d..9176d906 100644 --- a/Saucery.TUnit/SauceryTBase.cs +++ b/Saucery.TUnit/SauceryTBase.cs @@ -7,7 +7,6 @@ namespace Saucery.TUnit; -//public class SauceryTBase //: IClassFixture public class SauceryTBase : BaseFixture { private string? _testName; @@ -62,11 +61,6 @@ public void TearDown() } } - //protected SauceryTBase(ITestOutputHelper outputHelper, BaseFixture baseFixture) : base(outputHelper) - //{ - // _outputHelper = outputHelper; - //} - private static string GetTestName() => TestContext.Current?.TestDetails.TestName ?? ""; protected static IEnumerable GetAllCombinations(object[] data) { diff --git a/Saucery.Tests.Common/PageObjects/GuineaPigPage.cs b/Saucery.Tests.Common/PageObjects/GuineaPigPage.cs index 88eeeffb..a4aeae21 100644 --- a/Saucery.Tests.Common/PageObjects/GuineaPigPage.cs +++ b/Saucery.Tests.Common/PageObjects/GuineaPigPage.cs @@ -21,12 +21,14 @@ public GuineaPigPage ClickLink(WebDriver driver) { return this; } + public IWebElement GetField(WebDriver driver, string fieldId) => driver.FindElement(By.Id(fieldId)); + public string GetUserAgent(WebDriver driver) => //Could also use a "Selectors" class here. driver.FindElement(By.Id("useragent")).Text; public GuineaPigPage TypeField(WebDriver driver, string fieldId, string data) { - var element = driver.FindElement(By.Id(fieldId)); + var element = GetField(driver, fieldId); element.Clear(); element.SendKeys(data); return this;