Skip to content

Commit

Permalink
Feat/fixflowcontrol (#183)
Browse files Browse the repository at this point in the history
* comment out flow control

* fix flow control
  • Loading branch information
agray authored Sep 13, 2024
1 parent 8929456 commit f33c919
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 61 deletions.
4 changes: 2 additions & 2 deletions Saucery.Core.Tests/AndroidFactoryVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public void AppiumAndroidOptionTest(SaucePlatform saucePlatform)
var factory = new OptionFactory(validPlatform);
factory.ShouldNotBeNull();

var opts = factory.CreateOptions("AppiumAndroidOptionTest");
opts.ShouldNotBeNull();
var tuple = factory.CreateOptions("AppiumAndroidOptionTest");
tuple.opts.ShouldNotBeNull();
}
}
public class AndroidDataClass
Expand Down
4 changes: 2 additions & 2 deletions Saucery.Core.Tests/DesktopFactoryVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void DesktopOptionTest(SaucePlatform saucePlatform)
var factory = new OptionFactory(validplatform);
factory.ShouldNotBeNull();

var opts = factory.CreateOptions("DesktopOptionTest");
opts.ShouldNotBeNull();
var tuple = factory.CreateOptions("DesktopOptionTest");
tuple.opts.ShouldNotBeNull();
}
}
public class DesktopDataClass
Expand Down
4 changes: 2 additions & 2 deletions Saucery.Core.Tests/IOSFactoryVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public void AppiumIOSOptionTest(SaucePlatform saucePlatform)
var factory = new OptionFactory(validPlatform);
factory.ShouldNotBeNull();

var opts = factory.CreateOptions("AppiumIOSOptionTest");
opts.ShouldNotBeNull();
var tuple = factory.CreateOptions("AppiumIOSOptionTest");
tuple.opts.ShouldNotBeNull();
}
}
public class IOSDataClass
Expand Down
11 changes: 10 additions & 1 deletion Saucery.Core.Tests/RESTTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using NUnit.Framework.Constraints;
using Saucery.Core.Dojo;
using Saucery.Core.Dojo.Platforms.Base;
using Saucery.Core.Dojo.Platforms.ConcreteProducts.Apple;
Expand Down Expand Up @@ -26,7 +27,15 @@ public void Setup()
public void FlowControlTest() {
var flowController = new SauceLabsFlowController();
//Console.WriteLine(@"RESTTests: About to call ControlFlow()");
flowController.ControlFlow();
flowController.ControlFlow(false);
}

[Test]
public void FlowControlTestRealDevice()
{
var flowController = new SauceLabsFlowController();
//Console.WriteLine(@"RESTTests: About to call ControlFlow()");
flowController.ControlFlow(true);
}

[Test]
Expand Down
4 changes: 2 additions & 2 deletions Saucery.Core.Tests/RealAndroidFactoryVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void AppiumAndroidOptionTest(SaucePlatform saucePlatform)
var factory = new OptionFactory(validPlatform);
factory.ShouldNotBeNull();

var opts = factory.CreateOptions("AppiumRealAndroidOptionTest");
opts.ShouldNotBeNull();
var tuple = factory.CreateOptions("AppiumRealAndroidOptionTest");
tuple.opts.ShouldNotBeNull();
}
}
public class RealAndroidDataClass
Expand Down
4 changes: 2 additions & 2 deletions Saucery.Core.Tests/RealIOSFactoryVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void AppiumIOSOptionTest(SaucePlatform saucePlatform)
var factory = new OptionFactory(validPlatform);
factory.ShouldNotBeNull();

var opts = factory.CreateOptions("AppiumRealIOSOptionTest");
opts.ShouldNotBeNull();
var tuple = factory.CreateOptions("AppiumRealIOSOptionTest");
tuple.opts.ShouldNotBeNull();
}
}
public class RealIOSDataClass
Expand Down
2 changes: 1 addition & 1 deletion Saucery.Core/OnDemand/PlatformExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Saucery.Core.OnDemand;

internal static class PlatformExtensions {
public static class PlatformExtensions {
public static bool IsAMobileDevice(this BrowserVersion browserVersion) =>
IsAnAndroidDevice(browserVersion) ||
IsAnAppleDevice(browserVersion);
Expand Down
24 changes: 18 additions & 6 deletions Saucery.Core/Options/OptionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,46 @@ public class OptionFactory(BrowserVersion bv) : IDisposable
{
private BrowserVersion BrowserVersion { get; set; } = bv;

Check warning on line 11 in Saucery.Core/Options/OptionFactory.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.Core

Parameter 'BrowserVersion bv' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

public DriverOptions? CreateOptions(string testName)
public (DriverOptions? opts, BrowserVersion browserVersion) CreateOptions(string testName)
{
if (!BrowserVersion.IsAMobileDevice())
{
DebugMessages.PrintHaveDesktopPlatform();
return GetDesktopOptions(testName);
return (GetDesktopOptions(testName), bv);
}

//Mobile Device
if(BrowserVersion.IsARealDevice())
{
if(BrowserVersion.PlatformType.Equals(OnDemand.PlatformType.Apple)) {
DebugMessages.PrintHaveApplePlatform(true);
return new RealDeviceIOSCreator().Create(BrowserVersion, testName).GetOpts(BrowserVersion.PlatformType);
return (new RealDeviceIOSCreator()
.Create(BrowserVersion, testName)
.GetOpts(BrowserVersion.PlatformType),
bv);
}

DebugMessages.PrintHaveAndroidPlatform(true);
return new RealDeviceAndroidCreator().Create(BrowserVersion, testName).GetOpts(BrowserVersion.PlatformType);
return (new RealDeviceAndroidCreator()
.Create(BrowserVersion, testName)
.GetOpts(BrowserVersion.PlatformType),
bv);
}

//Emulated Mobile Platform
if(BrowserVersion.PlatformType.Equals(OnDemand.PlatformType.Apple)) {
DebugMessages.PrintHaveApplePlatform(false);
return new EmulatedIOSCreator().Create(BrowserVersion, testName).GetOpts(BrowserVersion.PlatformType);
return (new EmulatedIOSCreator()
.Create(BrowserVersion, testName)
.GetOpts(BrowserVersion.PlatformType),
bv);
}

DebugMessages.PrintHaveAndroidPlatform(false);
return new EmulatedAndroidCreator().Create(BrowserVersion, testName).GetOpts(BrowserVersion.PlatformType);
return (new EmulatedAndroidCreator()
.Create(BrowserVersion, testName)
.GetOpts(BrowserVersion.PlatformType),
bv);
}

private DriverOptions? GetDesktopOptions(string testName) => BrowserVersion.BrowserName.ToLower() switch
Expand Down
4 changes: 2 additions & 2 deletions Saucery.Core/RestAPI/FlowControl/Base/FlowController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Saucery.Core.RestAPI.FlowControl.Base;

public abstract class FlowController : RestBase {
protected abstract bool TooManyTests();
public abstract void ControlFlow();
protected abstract bool TooManyTests(bool realDevices);
public abstract void ControlFlow(bool realDevices);
}
/*
* Copyright Andrew Gray, SauceForge
Expand Down
45 changes: 39 additions & 6 deletions Saucery.Core/RestAPI/FlowControl/FlowControl.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
namespace Saucery.Core.RestAPI.FlowControl;

public class FlowControl {
public Remaining? remaining { get; set; }
public class FlowControl
{
public double timestamp { get; set; }
public Concurrency concurrency { get; set; }
}

public class Remaining {
public int overall { get; set; }
public int mac { get; set; }
public int manual { get; set; }
public class Allowed
{
public int rds { get; set; }
public int mac_vms { get; set; }
public int mac_arm_vms { get; set; }
public int vms { get; set; }
}

public class Concurrency
{
public Organization organization { get; set; }

Check warning on line 19 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.Core

Non-nullable property 'organization' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 19 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery

Non-nullable property 'organization' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 19 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.XUnit

Non-nullable property 'organization' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public Team team { get; set; }

Check warning on line 20 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery

Non-nullable property 'team' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 20 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.XUnit

Non-nullable property 'team' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

public class Current
{
public int rds { get; set; }
public int mac_vms { get; set; }
public int mac_arm_vms { get; set; }
public int vms { get; set; }
}

public class Organization
{
public Current current { get; set; }

Check warning on line 33 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.Core

Non-nullable property 'current' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 33 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery

Non-nullable property 'current' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 33 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.XUnit

Non-nullable property 'current' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string id { get; set; }

Check warning on line 34 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.Core

Non-nullable property 'id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 34 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery

Non-nullable property 'id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 34 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.XUnit

Non-nullable property 'id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public Allowed allowed { get; set; }

Check warning on line 35 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.Core

Non-nullable property 'allowed' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 35 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery

Non-nullable property 'allowed' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 35 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.XUnit

Non-nullable property 'allowed' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

public class Team
{
public Current current { get; set; }

Check warning on line 40 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.Core

Non-nullable property 'current' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 40 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery

Non-nullable property 'current' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 40 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.XUnit

Non-nullable property 'current' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string id { get; set; }

Check warning on line 41 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.Core

Non-nullable property 'id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 41 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery

Non-nullable property 'id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 41 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.XUnit

Non-nullable property 'id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public Allowed allowed { get; set; }

Check warning on line 42 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.Core

Non-nullable property 'allowed' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 42 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery

Non-nullable property 'allowed' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 42 in Saucery.Core/RestAPI/FlowControl/FlowControl.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.XUnit

Non-nullable property 'allowed' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

/*
* Copyright Andrew Gray, SauceForge
* Date: 18th September 2014
Expand Down
21 changes: 15 additions & 6 deletions Saucery.Core/RestAPI/FlowControl/SauceLabsFlowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,34 @@ public SauceLabsFlowController()
Client = new RestClient(clientOptions);
}

public override void ControlFlow() {
while(TooManyTests()) {
public override void ControlFlow(bool realDevices) {
while(TooManyTests(realDevices)) {
Thread.Sleep(SauceryConstants.SAUCELABS_FLOW_WAIT);
}
}

protected override bool TooManyTests() {
protected override bool TooManyTests(bool realDevices) {
//int maxParallelMacSessionsAllowed; //Possible future use.
var json = GetJsonResponse(SauceryConstants.ACCOUNT_CONCURRENCY_REQUEST);

if (json == null)
{
return true;
}

//Console.WriteLine(@"Debug: {0}", json);
var remainingSection = ExtractJsonSegment(json!, json!.IndexOf("\"remaining", StringComparison.Ordinal), json.Length - 3);
//var remainingSection = ExtractJsonSegment(json!, json!.IndexOf("\"remaining", StringComparison.Ordinal), json.Length - 3);
//Console.WriteLine(@"Debug: remainingsection = {0}", remainingSection);
var flowControl = JsonSerializer.Deserialize<FlowControl>(remainingSection, new JsonSerializerOptions
var flowControl = JsonSerializer.Deserialize<FlowControl>(json, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});

return flowControl?.remaining!.overall <= 0;
var org = flowControl?.concurrency.organization;
var orgAllowed = realDevices ? org.allowed.rds : org.allowed.vms;

Check warning on line 44 in Saucery.Core/RestAPI/FlowControl/SauceLabsFlowController.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.Core

Dereference of a possibly null reference.

Check warning on line 44 in Saucery.Core/RestAPI/FlowControl/SauceLabsFlowController.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.Core

Dereference of a possibly null reference.

Check warning on line 44 in Saucery.Core/RestAPI/FlowControl/SauceLabsFlowController.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery

Dereference of a possibly null reference.

Check warning on line 44 in Saucery.Core/RestAPI/FlowControl/SauceLabsFlowController.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery

Dereference of a possibly null reference.

Check warning on line 44 in Saucery.Core/RestAPI/FlowControl/SauceLabsFlowController.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.XUnit

Dereference of a possibly null reference.

Check warning on line 44 in Saucery.Core/RestAPI/FlowControl/SauceLabsFlowController.cs

View workflow job for this annotation

GitHub Actions / build, pack & push Saucery.XUnit

Dereference of a possibly null reference.
var orgCurrent = realDevices ? org.current.rds : org.current.vms;

return orgAllowed - orgCurrent <= 0;
}
}
/*
Expand Down
14 changes: 7 additions & 7 deletions Saucery.Core/Util/SauceryConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public class SauceryConstants {
internal const string JSON_CONTENT_TYPE = "application/json";
internal const string RESTAPI_LIMIT_EXCEEDED_INDICATOR = "API rate limit exceeded for";
internal const string RESTAPI_LIMIT_EXCEEDED_MSG = "API rate limit exceeded. We have to wait. See https://saucelabs.com/blog/announcing-new-rest-api-rate-limits for more details.";
internal const string SAUCE_REST_BASE = "https://api.us-west-1.saucelabs.com/rest/v1/";
internal const string SAUCE_REAL_DEVICE_REST_BASE = "https://api.us-west-1.saucelabs.com/v1/";
internal const string ACCOUNT_CONCURRENCY_REQUEST = "users/{0}/concurrency";
internal const string JOB_REQUEST = "{0}/jobs/{1}";
internal const string RECOMMENDED_APPIUM_REQUEST = "info/platforms/appium";
internal const string SUPPORTED_PLATFORMS_REQUEST = "info/platforms/all";
internal const string SUPPORTED_REALDEVICE_PLATFORMS_REQUEST = "rdc/devices";
internal const string SAUCE_REST_BASE = "https://api.us-west-1.saucelabs.com/rest/";
internal const string SAUCE_REAL_DEVICE_REST_BASE = "https://api.us-west-1.saucelabs.com/";
internal const string ACCOUNT_CONCURRENCY_REQUEST = "v1.2/users/{0}/concurrency";
internal const string JOB_REQUEST = "v1/{0}/jobs/{1}";
internal const string RECOMMENDED_APPIUM_REQUEST = "v1/info/platforms/appium";
internal const string SUPPORTED_PLATFORMS_REQUEST = "v1/info/platforms/all";
internal const string SUPPORTED_REALDEVICE_PLATFORMS_REQUEST = "v1/rdc/devices";
internal const string JSON_SEGMENT_CONTAINER = "{{{0}}}";
internal const string NUGET_API = "https://packages.nuget.org/api/v2";
internal const string NUGET_VERSION = "{0}.{1}.{2}";
Expand Down
14 changes: 8 additions & 6 deletions Saucery.Playwright.NUnit/SauceryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using OpenQA.Selenium;
using Saucery.Core.Dojo;
using Saucery.Core.Driver;
using Saucery.Core.OnDemand;
using Saucery.Core.Options;
using Saucery.Core.RestAPI.FlowControl;
using Saucery.Core.RestAPI.TestStatus;
using Saucery.Core.Util;
using System;

namespace Saucery.Playwright.NUnit;

Expand Down Expand Up @@ -42,14 +44,14 @@ public void Setup()
//DebugMessages.PrintPlatformDetails(platform);
// set up the desired options
var factory = new OptionFactory(_browserVersion);
var opts = factory.CreateOptions(_testName);
var tuple = factory.CreateOptions(_testName);

var driverInitialised = InitialiseDriver(opts!, SauceryConstants.SELENIUM_COMMAND_TIMEOUT);
var driverInitialised = InitialiseDriver(tuple, SauceryConstants.SELENIUM_COMMAND_TIMEOUT);

while (!driverInitialised)
{
Console.WriteLine($"Driver failed to initialise: {TestContext.CurrentContext.Test.Name}.");
driverInitialised = InitialiseDriver(opts!, SauceryConstants.SELENIUM_COMMAND_TIMEOUT);
driverInitialised = InitialiseDriver(tuple, SauceryConstants.SELENIUM_COMMAND_TIMEOUT);
}
Console.WriteLine($"Driver successfully initialised: {TestContext.CurrentContext.Test.Name}.");
}
Expand Down Expand Up @@ -77,12 +79,12 @@ public void Cleanup()
}
}

private bool InitialiseDriver(DriverOptions opts, int waitSecs)
private bool InitialiseDriver((DriverOptions opts, BrowserVersion browserVersion) tuple, int waitSecs)
{
SauceLabsFlowController.ControlFlow();
SauceLabsFlowController.ControlFlow(tuple.browserVersion.IsARealDevice());
try
{
Driver = new SauceryRemoteWebDriver(new Uri(SauceryConstants.SAUCELABS_HUB), opts, waitSecs);
Driver = new SauceryRemoteWebDriver(new Uri(SauceryConstants.SAUCELABS_HUB), tuple.opts, waitSecs);
return true;
}
catch (Exception ex)
Expand Down
13 changes: 8 additions & 5 deletions Saucery.XUnit/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.iOS;
using OpenQA.Selenium.Appium.Service;
using Saucery.Core.Dojo;
using Saucery.Core.Driver;
using Saucery.Core.OnDemand;
using Saucery.Core.Options;
using Saucery.Core.RestAPI.FlowControl;
using Saucery.Core.RestAPI.TestStatus;
using Saucery.Core.Util;
using System;

//Needs XunitContext NuGet Package
//[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly, MaxParallelThreads = 4)]
Expand All @@ -31,18 +34,18 @@ public BaseFixture()
SauceLabsFlowController = new SauceLabsFlowController();
}

public bool InitialiseDriver(DriverOptions opts, int waitSecs)
public bool InitialiseDriver((DriverOptions opts, BrowserVersion browserVersion) tuple, int waitSecs)
{
SauceLabsFlowController.ControlFlow();
SauceLabsFlowController.ControlFlow(tuple.browserVersion.IsARealDevice());
try
{
Driver = OptionFactory!.IsApple()
? new IOSDriver(new Uri(SauceryConstants.SAUCELABS_HUB), opts, TimeSpan.FromSeconds(waitSecs),
? new IOSDriver(new Uri(SauceryConstants.SAUCELABS_HUB), tuple.opts, TimeSpan.FromSeconds(waitSecs),
AppiumClientConfig)
: OptionFactory!.IsAndroid()
? new AndroidDriver(new Uri(SauceryConstants.SAUCELABS_HUB), opts, TimeSpan.FromSeconds(waitSecs),
? new AndroidDriver(new Uri(SauceryConstants.SAUCELABS_HUB), tuple.opts, TimeSpan.FromSeconds(waitSecs),
AppiumClientConfig)
: new SauceryRemoteWebDriver(new Uri(SauceryConstants.SAUCELABS_HUB), opts, waitSecs);
: new SauceryRemoteWebDriver(new Uri(SauceryConstants.SAUCELABS_HUB), tuple.opts, waitSecs);

return true;
}
Expand Down
6 changes: 3 additions & 3 deletions Saucery.XUnit/SauceryXBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ protected bool InitialiseDriver(BrowserVersion browserVersion)
//DebugMessages.PrintPlatformDetails(platform);
// set up the desired options
BaseFixture.OptionFactory = new OptionFactory(_browserVersion);
var opts = BaseFixture.OptionFactory.CreateOptions(_testName!);
var tuple = BaseFixture.OptionFactory.CreateOptions(_testName!);

var driverInitialised = BaseFixture.InitialiseDriver(opts!, SauceryConstants.SELENIUM_COMMAND_TIMEOUT);
var driverInitialised = BaseFixture.InitialiseDriver(tuple, SauceryConstants.SELENIUM_COMMAND_TIMEOUT);

while (!driverInitialised)
{
Console.WriteLine($"Driver failed to initialise: {_testName}.");
driverInitialised = BaseFixture.InitialiseDriver(opts!, SauceryConstants.SELENIUM_COMMAND_TIMEOUT);
driverInitialised = BaseFixture.InitialiseDriver(tuple, SauceryConstants.SELENIUM_COMMAND_TIMEOUT);
}
Console.WriteLine($"Driver successfully initialised: {_testName}.");

Expand Down
Loading

0 comments on commit f33c919

Please sign in to comment.