New projct BrowserDriver infered to help with webscraping
This commit is contained in:
39
BrowserHelper/Extensions/WebDriverInitializerExtension.cs
Normal file
39
BrowserHelper/Extensions/WebDriverInitializerExtension.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using BrowserHelper.Driver;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using BrowserHelper.Settings;
|
||||
|
||||
namespace BrowserHelper.Extensions;
|
||||
public static class WebDriverInitializerExtension
|
||||
{
|
||||
public static IServiceCollection UseWebDriverInitializer(
|
||||
this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton(ReadConfig());
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
private static TestSettings ReadConfig()
|
||||
{
|
||||
var configFile = File
|
||||
.ReadAllText(Path.GetDirectoryName(
|
||||
Assembly.GetExecutingAssembly().Location)
|
||||
+ "/appsettings.json");
|
||||
|
||||
var jsonSerializeOptions = new JsonSerializerOptions()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
jsonSerializeOptions.Converters.Add(new JsonStringEnumConverter());
|
||||
|
||||
var testSettings = JsonSerializer.Deserialize<TestSettings>(configFile, jsonSerializeOptions);
|
||||
|
||||
return testSettings;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user