-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestStartup.cs
82 lines (72 loc) · 2.68 KB
/
TestStartup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using Autofac;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Microsoft.Playwright;
using Reqnroll.Autofac;
using ReqnrollTestProject.Pages;
using ReqnrollTestProject.Services;
using ReqnrollTestProject.Settings;
namespace ReqnrollTestProject;
public static class TestStartup
{
[ScenarioDependencies]
public static void CreateServices(ContainerBuilder builder)
{
builder.RegisterConfiguration();
builder.RegisterPlaywright();
builder.RegisterAppSettings();
builder.RegisterPages();
builder.RegisterPagesHandler();
builder.RegisterPageDependencyService();
builder.RegisterSteps();
}
private static void RegisterSteps(this ContainerBuilder builder)
{
builder.RegisterType<StepDefinitions>().InstancePerDependency();
}
private static void RegisterConfiguration(this ContainerBuilder builder)
{
var configuration = new ConfigurationBuilder()
.AddJsonFile("Settings/appsettings.json", false, true)
.Build();
builder.RegisterInstance(configuration)
.As<IConfiguration>()
.SingleInstance();
}
private static void RegisterAppSettings(this ContainerBuilder builder)
{
builder.Register(c =>
{
var configuration = c.Resolve<IConfiguration>();
var appSettings = new AppSettings();
configuration.Bind(appSettings);
return Options.Create(appSettings);
}).As<IOptions<AppSettings>>();
}
private static void RegisterPlaywright(this ContainerBuilder builder)
{
builder.Register(async _ =>
{
var playwright = await Playwright.CreateAsync().ConfigureAwait(false);
var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
SlowMo = 200
}).ConfigureAwait(false);
return await browser.NewPageAsync().ConfigureAwait(false);
}).As<Task<IPage>>().InstancePerDependency();
}
private static void RegisterPages(this ContainerBuilder builder)
{
builder.RegisterType<HomePage>().AsSelf().InstancePerDependency();
builder.RegisterType<SupportPage>().AsSelf().InstancePerDependency();
}
private static void RegisterPagesHandler(this ContainerBuilder builder)
{
builder.RegisterType<PagesService>().As<IPageService>().InstancePerLifetimeScope();
}
private static void RegisterPageDependencyService(this ContainerBuilder builder)
{
builder.RegisterType<PageDependencyService>().As<IPageDependencyService>().InstancePerLifetimeScope();
}
}