Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b97a4fd

Browse files
Added Extent reporting with complete code changes in Hooks using featurecontext, ScenarioContext and ScenarioStepContext
1 parent 2b578ea commit b97a4fd

File tree

9 files changed

+636
-16
lines changed

9 files changed

+636
-16
lines changed

‎SpecflowParallelTest/ExtentReport.html‎

Lines changed: 452 additions & 0 deletions
Large diffs are not rendered by default.

‎SpecflowParallelTest/Hooks.cs‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
using System.Reflection;
66
using OpenQA.Selenium.Remote;
77
using TechTalk.SpecFlow;
8+
using AventStack.ExtentReports;
9+
using AventStack.ExtentReports.Reporter;
10+
using AventStack.ExtentReports.Gherkin.Model;
811

912
namespace SpecflowParallelTest
1013
{
1114
[Binding]
1215
public class Hooks
1316
{
17+
//Global Variable for Extend report
18+
private static ExtentTest featureName;
19+
private static ExtentTest scenario;
20+
private static ExtentReports extent;
1421

1522
private readonly IObjectContainer _objectContainer;
1623

@@ -21,10 +28,83 @@ public Hooks(IObjectContainer objectContainer)
2128
_objectContainer = objectContainer;
2229
}
2330

31+
[BeforeTestRun]
32+
public static void InitializeReport()
33+
{
34+
//Initialize Extent report before test starts
35+
var htmlReporter = new ExtentHtmlReporter(@"C:\extentreport\SeleniumWithSpecflow\SpecflowParallelTest\ExtentReport.html");
36+
htmlReporter.Configuration().Theme = AventStack.ExtentReports.Reporter.Configuration.Theme.Dark;
37+
//Attach report to reporter
38+
extent = new ExtentReports();
39+
extent.AttachReporter(htmlReporter);
40+
}
41+
42+
[AfterTestRun]
43+
public static void TearDownReport()
44+
{
45+
//Flush report once test completes
46+
extent.Flush();
47+
}
48+
49+
[BeforeFeature]
50+
public static void BeforeFeature()
51+
{
52+
//Create dynamic feature name
53+
featureName = extent.CreateTest<Feature>(FeatureContext.Current.FeatureInfo.Title);
54+
}
55+
56+
[AfterStep]
57+
public void InsertReportingSteps()
58+
{
59+
60+
var stepType = ScenarioStepContext.Current.StepInfo.StepDefinitionType.ToString();
61+
62+
PropertyInfo pInfo = typeof(ScenarioContext).GetProperty("TestStatus", BindingFlags.Instance | BindingFlags.NonPublic);
63+
MethodInfo getter = pInfo.GetGetMethod(nonPublic: true);
64+
object TestResult = getter.Invoke(ScenarioContext.Current, null);
65+
66+
if (ScenarioContext.Current.TestError == null)
67+
{
68+
if (stepType == "Given")
69+
scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text);
70+
else if (stepType == "When")
71+
scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text);
72+
else if (stepType == "Then")
73+
scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text);
74+
else if (stepType == "And")
75+
scenario.CreateNode<And>(ScenarioStepContext.Current.StepInfo.Text);
76+
}
77+
else if (ScenarioContext.Current.TestError != null)
78+
{
79+
if (stepType == "Given")
80+
scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.InnerException);
81+
else if (stepType == "When")
82+
scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.InnerException);
83+
else if (stepType == "Then")
84+
scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.Message);
85+
}
86+
87+
//Pending Status
88+
if (TestResult.ToString() == "StepDefinitionPending")
89+
{
90+
if (stepType == "Given")
91+
scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
92+
else if (stepType == "When")
93+
scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
94+
else if (stepType == "Then")
95+
scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
96+
97+
}
98+
99+
}
100+
101+
24102
[BeforeScenario]
25103
public void Initialize()
26104
{
27105
SelectBrowser(BrowserType.Firefox);
106+
//Create dynamic scenario name
107+
scenario = featureName.CreateNode<Scenario>(ScenarioContext.Current.ScenarioInfo.Title);
28108
}
29109

30110
[AfterScenario]

‎SpecflowParallelTest/Properties/AssemblyInfo.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[assembly: AssemblyCopyright("Copyright © 2016")]
1515
[assembly: AssemblyTrademark("")]
1616
[assembly: AssemblyCulture("")]
17-
[assembly: Parallelizable(ParallelScope.Fixtures)]
17+
//[assembly: Parallelizable(ParallelScope.Fixtures)]
1818

1919
// Setting ComVisible to false makes the types in this assembly not visible
2020
// to COM components. If you need to access a type in this assembly from

‎SpecflowParallelTest/SpecflowParallelTest.csproj‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,55 @@
3737
<WarningLevel>4</WarningLevel>
3838
</PropertyGroup>
3939
<ItemGroup>
40+
<Reference Include="ExtentReports, Version=3.1.3.0, Culture=neutral, processorArchitecture=MSIL">
41+
<HintPath>..\packages\ExtentReports.3.1.3\lib\ExtentReports.dll</HintPath>
42+
</Reference>
43+
<Reference Include="HtmlAgilityPack, Version=1.4.9.5, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
44+
<HintPath>..\packages\HtmlAgilityPack.1.4.9.5\lib\Net45\HtmlAgilityPack.dll</HintPath>
45+
</Reference>
4046
<Reference Include="ImpromptuInterface, Version=6.2.2.0, Culture=neutral, PublicKeyToken=0b1781c923b2975b, processorArchitecture=MSIL">
4147
<HintPath>..\packages\ImpromptuInterface.6.2.2\lib\net40\ImpromptuInterface.dll</HintPath>
4248
<Private>True</Private>
4349
</Reference>
4450
<Reference Include="Microsoft.CSharp" />
51+
<Reference Include="MongoDB.Bson, Version=2.4.0.70, Culture=neutral, processorArchitecture=MSIL">
52+
<HintPath>..\packages\MongoDB.Bson.2.4.0\lib\net45\MongoDB.Bson.dll</HintPath>
53+
</Reference>
54+
<Reference Include="MongoDB.Driver, Version=2.4.0.70, Culture=neutral, processorArchitecture=MSIL">
55+
<HintPath>..\packages\MongoDB.Driver.2.4.0\lib\net45\MongoDB.Driver.dll</HintPath>
56+
</Reference>
57+
<Reference Include="MongoDB.Driver.Core, Version=2.4.0.70, Culture=neutral, processorArchitecture=MSIL">
58+
<HintPath>..\packages\MongoDB.Driver.Core.2.4.0\lib\net45\MongoDB.Driver.Core.dll</HintPath>
59+
</Reference>
4560
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
4661
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
4762
</Reference>
4863
<Reference Include="nunit.framework, Version=3.7.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
4964
<HintPath>..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath>
5065
</Reference>
66+
<Reference Include="RazorEngine, Version=3.9.0.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a, processorArchitecture=MSIL">
67+
<HintPath>..\packages\RazorEngine.3.9.0\lib\net45\RazorEngine.dll</HintPath>
68+
</Reference>
5169
<Reference Include="SpecFlow.Assist.Dynamic, Version=1.3.1.0, Culture=neutral, processorArchitecture=MSIL">
5270
<HintPath>..\packages\SpecFlow.Assist.Dynamic.1.3.1\lib45円\SpecFlow.Assist.Dynamic.dll</HintPath>
5371
</Reference>
5472
<Reference Include="System" />
5573
<Reference Include="System.Drawing" />
74+
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
75+
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
76+
<Private>True</Private>
77+
</Reference>
78+
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
79+
<HintPath>..\packages\Microsoft.AspNet.Razor.3.0.0\lib\net45\System.Web.Razor.dll</HintPath>
80+
</Reference>
5681
<Reference Include="TechTalk.SpecFlow, Version=2.2.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41, processorArchitecture=MSIL">
5782
<HintPath>..\packages\SpecFlow.2.2.0\lib\net45\TechTalk.SpecFlow.dll</HintPath>
5883
</Reference>
59-
<Reference Include="WebDriver, Version=3.11.0.0, Culture=neutral, processorArchitecture=MSIL">
60-
<HintPath>..\packages\Selenium.WebDriver.3.11.0\lib\net45\WebDriver.dll</HintPath>
84+
<Reference Include="WebDriver, Version=3.11.2.0, Culture=neutral, processorArchitecture=MSIL">
85+
<HintPath>..\packages\Selenium.WebDriver.3.11.2\lib\net45\WebDriver.dll</HintPath>
6186
</Reference>
62-
<Reference Include="WebDriver.Support, Version=3.11.0.0, Culture=neutral, processorArchitecture=MSIL">
63-
<HintPath>..\packages\Selenium.Support.3.11.0\lib\net45\WebDriver.Support.dll</HintPath>
87+
<Reference Include="WebDriver.Support, Version=3.11.2.0, Culture=neutral, processorArchitecture=MSIL">
88+
<HintPath>..\packages\Selenium.Support.3.11.2\lib\net45\WebDriver.Support.dll</HintPath>
6489
</Reference>
6590
</ItemGroup>
6691
<Choose>
@@ -107,13 +132,15 @@
107132
<Generator>SpecFlowSingleFileGenerator</Generator>
108133
<LastGenOutput>UserForm.feature.cs</LastGenOutput>
109134
</None>
135+
<None Include="license" />
110136
<None Include="packages.config" />
111137
</ItemGroup>
112138
<ItemGroup>
113-
<Content Include="..\packages\WebDriver.GeckoDriver.0.16.1\content\geckodriver.exe">
139+
<Content Include="..\packages\WebDriver.GeckoDriver.0.20.1\content\geckodriver.exe">
114140
<Link>geckodriver.exe</Link>
115141
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
116142
</Content>
143+
<Content Include="extent-config.xml" />
117144
</ItemGroup>
118145
<Choose>
119146
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
@@ -135,12 +162,12 @@
135162
</Choose>
136163
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
137164
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
138-
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.31.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.31.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
165+
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.38.0.1\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.38.0.1\build\Selenium.WebDriver.ChromeDriver.targets')" />
139166
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
140167
<PropertyGroup>
141168
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
142169
</PropertyGroup>
143-
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.31.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.31.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
170+
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.38.0.1\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.38.0.1\build\Selenium.WebDriver.ChromeDriver.targets'))" />
144171
</Target>
145172
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
146173
Other similar extension points exist, see Microsoft.Common.targets.

‎SpecflowParallelTest/Steps/LoginSteps.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
using SpecflowParallelTest.Pages;
77
using TechTalk.SpecFlow;
88
using TechTalk.SpecFlow.Assist;
9+
using AventStack.ExtentReports.Reporter;
10+
using AventStack.ExtentReports;
11+
using AventStack.ExtentReports.Gherkin.Model;
912

1013
namespace SpecflowParallelTest.Steps
1114
{
@@ -53,7 +56,7 @@ public void ThenIShouldSeeUserLoggedInToTheApplication()
5356
Assert.Multiple(() =>
5457
{
5558
//Assert.That(element.Text, Is.Null, "Header text not found !!!");
56-
Assert.That(element.Text, Is.Not.Null, "Header text not found !!!");
59+
Assert.That(element.Text, Is.Null, "Header text not found !!!");
5760
});
5861
}
5962

‎SpecflowParallelTest/Steps/UserFormSteps.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ public void GivenIVerifyTheEnteredUserFormDetailsInTheApplicationDatabase(Table
7373

7474
}
7575

76+
[Then(@"I logout of application")]
77+
public void ThenILogoutOfApplication()
78+
{
79+
ScenarioContext.Current.Pending();
80+
}
81+
7682

7783
}
7884

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<extentreports>
3+
<configuration>
4+
<!-- report theme -->
5+
<!-- standard, dark -->
6+
<theme>standard</theme>
7+
8+
<!-- document encoding -->
9+
<!-- defaults to UTF-8 -->
10+
<encoding>UTF-8</encoding>
11+
12+
<!-- protocol for script and stylesheets -->
13+
<!-- defaults to https -->
14+
<protocol>https</protocol>
15+
16+
<!-- title of the document -->
17+
<documentTitle>Extent</documentTitle>
18+
19+
<chartVisibilityOnOpen>true</chartVisibilityOnOpen>
20+
21+
<!-- report name - displayed at top-nav -->
22+
<reportName>Automation Report</reportName>
23+
24+
<!-- location of charts in the test view -->
25+
<!-- top, bottom -->
26+
<testViewChartLocation>bottom</testViewChartLocation>
27+
28+
<!-- custom javascript -->
29+
<scripts>
30+
<![CDATA[
31+
$(document).ready(function() {
32+
33+
});
34+
]]>
35+
</scripts>
36+
37+
<!-- custom styles -->
38+
<styles>
39+
<![CDATA[
40+
41+
]]>
42+
</styles>
43+
</configuration>
44+
</extentreports>

‎SpecflowParallelTest/license‎

Whitespace-only changes.

‎SpecflowParallelTest/packages.config‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="ExtentReports" version="3.1.3" targetFramework="net452" />
4+
<package id="HtmlAgilityPack" version="1.4.9.5" targetFramework="net452" />
35
<package id="ImpromptuInterface" version="6.2.2" targetFramework="net452" />
6+
<package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net452" />
7+
<package id="MongoDB.Bson" version="2.4.0" targetFramework="net452" />
8+
<package id="MongoDB.Driver" version="2.4.0" targetFramework="net452" />
9+
<package id="MongoDB.Driver.Core" version="2.4.0" targetFramework="net452" />
410
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
511
<package id="NUnit" version="3.7.1" targetFramework="net452" />
612
<package id="NUnit.Console" version="3.7.0" targetFramework="net452" />
713
<package id="NUnit.ConsoleRunner" version="3.7.0" targetFramework="net452" />
814
<package id="NUnit.Extension.NUnitProjectLoader" version="3.5.0" targetFramework="net452" />
915
<package id="NUnit.Extension.NUnitV2Driver" version="3.6.0" targetFramework="net452" />
10-
<package id="NUnit.Extension.NUnitV2ResultWriter" version="3.5.0" targetFramework="net452" />
11-
<package id="NUnit.Extension.TeamCityEventListener" version="1.0.2" targetFramework="net452" />
12-
<package id="NUnit.Extension.VSProjectLoader" version="3.5.0" targetFramework="net452" />
13-
<package id="Selenium.Support" version="3.11.0" targetFramework="net452" />
14-
<package id="Selenium.WebDriver" version="3.11.0" targetFramework="net452" />
15-
<package id="Selenium.WebDriver.ChromeDriver" version="2.31.0" targetFramework="net452" />
16+
<package id="NUnit.Extension.NUnitV2ResultWriter" version="3.6.0" targetFramework="net452" />
17+
<package id="NUnit.Extension.TeamCityEventListener" version="1.0.3" targetFramework="net452" />
18+
<package id="NUnit.Extension.VSProjectLoader" version="3.7.0" targetFramework="net452" />
19+
<package id="RazorEngine" version="3.9.0" targetFramework="net452" />
20+
<package id="Selenium.Support" version="3.11.2" targetFramework="net452" />
21+
<package id="Selenium.WebDriver" version="3.11.2" targetFramework="net452" />
22+
<package id="Selenium.WebDriver.ChromeDriver" version="2.38.0.1" targetFramework="net452" />
1623
<package id="SpecFlow" version="2.2.0" targetFramework="net452" />
1724
<package id="SpecFlow.Assist.Dynamic" version="1.3.1" targetFramework="net452" />
18-
<package id="WebDriver.GeckoDriver" version="0.16.1" targetFramework="net452" />
25+
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.0.0" targetFramework="net452" />
26+
<package id="WebDriver.GeckoDriver" version="0.20.1" targetFramework="net452" />
1927
</packages>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /