-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hooks.cs
47 lines (43 loc) · 1.91 KB
/
Hooks.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
using AutomationFramework.Configuration;
using AutomationFramework.POM.Swaglabs;
using AutomationFramework.Webdriver;
using Reqnroll;
namespace AutomationFramework
{
[Binding]
public sealed class Hooks
{
// For additional details on Reqnroll hooks see https://go.reqnroll.net/doc-hooks
private string configPath = "./testconf.json";
private Config config;
int stepNumber;
private string scenarioEvidencesFolder;
[BeforeScenario]
public void BeforeScenario(WebdriverManager webDriverManager, ConfigurationManager configManager, ScenarioContext scenarioContext)
{
config = configManager.LoadConfiguration(configPath);
scenarioEvidencesFolder = Path.Combine(config.EvidencePath, DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss") + " " + scenarioContext.ScenarioInfo.Title);
DirectoryInfo di = Directory.CreateDirectory(scenarioEvidencesFolder);
webDriverManager.SetupDriver(config.DriverPath);
var driver = webDriverManager.GetDriver();
driver.Navigate().GoToUrl(config.BaseURL);
stepNumber = 0;
}
[AfterScenario]
public void AfterScenario(WebdriverManager webDriverManager)
{
webDriverManager.DisposeDriver();
}
[AfterStep]
public void AfterStep(WebdriverManager webDriverManager, ScenarioContext scenarioContext)
{
var evidenceName = $"{stepNumber} - {scenarioContext.StepContext.StepInfo.StepDefinitionType} {scenarioContext.StepContext.StepInfo.Text}";
foreach (var c in Path.GetInvalidFileNameChars())
{
evidenceName = evidenceName.Replace(c.ToString(), string.Empty);
}
webDriverManager.CollectEvidence(scenarioEvidencesFolder, evidenceName);
stepNumber++;
}
}
}