Skip to content

Commit

Permalink
[#262] moved driver creation to a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry.bogatko committed Sep 17, 2024
1 parent 8bf996c commit 80f7744
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ private DriverContext GetDriver<T>(Func<DriverService> driverServiceProvider, Dr
var currentBrowserVersionRegex = new Regex(CurrentBrowserVersionPattern, RegexOptions.None, TimeoutConfiguration.Condition);
try
{
var driverService = driverServiceProvider.Invoke();
var driver = (T)Activator.CreateInstance(typeof(T), driverService, driverOptions, commandTimeout);
var context = new DriverContext(driver)
{
DriverService = driverService
};
var context = CreateWebDriverInstance<T>(driverServiceProvider, driverOptions, commandTimeout);
return context;
}
catch (TargetInvocationException exception)
Expand All @@ -107,14 +102,20 @@ private DriverContext GetDriver<T>(Func<DriverService> driverServiceProvider, Dr
Logger.Instance.Debug(exception.InnerException.Message, exception);
var currentVersion = currentBrowserVersionRegex.Match(exception.InnerException.Message).Groups[1].Value;
Environment.SetEnvironmentVariable(DriverVersionVariableName, currentVersion);
var driverService = driverServiceProvider.Invoke();
var driver = (T)Activator.CreateInstance(typeof(T), driverService, driverOptions, commandTimeout);
var context = new DriverContext(driver)
{
DriverService = driverService
};
var context = CreateWebDriverInstance<T>(driverServiceProvider, driverOptions, commandTimeout);
return context;
}
}

private DriverContext CreateWebDriverInstance<T>(Func<DriverService> driverServiceProvider, DriverOptions driverOptions, TimeSpan commandTimeout) where T : WebDriver
{
var driverService = driverServiceProvider.Invoke();
var driver = (T)Activator.CreateInstance(typeof(T), driverService, driverOptions, commandTimeout);
var context = new DriverContext(driver)
{
DriverService = driverService
};
return context;
}
}
}

0 comments on commit 80f7744

Please sign in to comment.