Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding result supplementer for Selenium WebDriver

  • Loading branch information...
commit 89359125062ba5f4754253c38e4d0eab334f8a4e 1 parent 3f4a961
@agross agross authored
View
37 Machine.Specifications.sln
@@ -86,6 +86,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{A3F866
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Machine.Specifications.WebDriverSupport", "Source\Machine.Specifications.WebDriverSupport\Machine.Specifications.WebDriverSupport.csproj", "{0029D44B-6E6C-4FD5-9071-EEA15A765D37}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -168,18 +170,6 @@ Global
{F78E1AB8-7F34-4C32-BC4D-558CAA94DB7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F78E1AB8-7F34-4C32-BC4D-558CAA94DB7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F78E1AB8-7F34-4C32-BC4D-558CAA94DB7C}.Release|Any CPU.Build.0 = Release|Any CPU
- {D1B0D26E-BEA9-45EF-87C2-0ED5FC9CAC3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {D1B0D26E-BEA9-45EF-87C2-0ED5FC9CAC3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {D1B0D26E-BEA9-45EF-87C2-0ED5FC9CAC3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {D1B0D26E-BEA9-45EF-87C2-0ED5FC9CAC3F}.Release|Any CPU.Build.0 = Release|Any CPU
- {263ABAC8-C6B2-497D-93E3-3773849CEDD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {263ABAC8-C6B2-497D-93E3-3773849CEDD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {263ABAC8-C6B2-497D-93E3-3773849CEDD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {263ABAC8-C6B2-497D-93E3-3773849CEDD3}.Release|Any CPU.Build.0 = Release|Any CPU
- {9C3D968A-AA2C-4612-94E8-C3FD16BFEEED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {9C3D968A-AA2C-4612-94E8-C3FD16BFEEED}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {9C3D968A-AA2C-4612-94E8-C3FD16BFEEED}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {9C3D968A-AA2C-4612-94E8-C3FD16BFEEED}.Release|Any CPU.Build.0 = Release|Any CPU
{0CE411DF-CFC3-45E3-96AD-2F872D99E1B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CE411DF-CFC3-45E3-96AD-2F872D99E1B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CE411DF-CFC3-45E3-96AD-2F872D99E1B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -208,6 +198,22 @@ Global
{79A3A8CA-CAEF-4DC6-83C9-E19A0C720B0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79A3A8CA-CAEF-4DC6-83C9-E19A0C720B0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{79A3A8CA-CAEF-4DC6-83C9-E19A0C720B0E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D1B0D26E-BEA9-45EF-87C2-0ED5FC9CAC3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D1B0D26E-BEA9-45EF-87C2-0ED5FC9CAC3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D1B0D26E-BEA9-45EF-87C2-0ED5FC9CAC3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D1B0D26E-BEA9-45EF-87C2-0ED5FC9CAC3F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {263ABAC8-C6B2-497D-93E3-3773849CEDD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {263ABAC8-C6B2-497D-93E3-3773849CEDD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {263ABAC8-C6B2-497D-93E3-3773849CEDD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {263ABAC8-C6B2-497D-93E3-3773849CEDD3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9C3D968A-AA2C-4612-94E8-C3FD16BFEEED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9C3D968A-AA2C-4612-94E8-C3FD16BFEEED}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9C3D968A-AA2C-4612-94E8-C3FD16BFEEED}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9C3D968A-AA2C-4612-94E8-C3FD16BFEEED}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0029D44B-6E6C-4FD5-9071-EEA15A765D37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0029D44B-6E6C-4FD5-9071-EEA15A765D37}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0029D44B-6E6C-4FD5-9071-EEA15A765D37}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0029D44B-6E6C-4FD5-9071-EEA15A765D37}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -228,16 +234,17 @@ Global
{EA52971B-2916-4A32-8F1E-57CDA9CE8EB3} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
{F06E1AB8-7F34-4C32-BC4D-558CAA94DB7C} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
{F78E1AB8-7F34-4C32-BC4D-558CAA94DB7C} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
- {D1B0D26E-BEA9-45EF-87C2-0ED5FC9CAC3F} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
- {263ABAC8-C6B2-497D-93E3-3773849CEDD3} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
- {9C3D968A-AA2C-4612-94E8-C3FD16BFEEED} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
{C47B3023-AC8D-4DFD-AAC2-006C4772B699} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
{5ED0B02E-7E2D-413D-ABE9-6DB07116E2CE} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
{AEF08081-3BB5-4654-9F21-C066647B370A} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
{79A3A8CA-CAEF-4DC6-83C9-E19A0C720B0E} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
+ {D1B0D26E-BEA9-45EF-87C2-0ED5FC9CAC3F} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
+ {263ABAC8-C6B2-497D-93E3-3773849CEDD3} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
+ {9C3D968A-AA2C-4612-94E8-C3FD16BFEEED} = {3D475ECE-C800-4087-8FC5-B9A13E76ABC4}
{490496AF-BEA5-4454-88B0-F73C62C22987} = {1F11BF5C-810C-4FC8-AFF4-7E416A867F39}
{97BD55A5-03CA-4E8E-8AE0-55722C39E0AF} = {1F11BF5C-810C-4FC8-AFF4-7E416A867F39}
{50E85B88-7E0C-4CE7-BD8D-BA9C618A6844} = {1F11BF5C-810C-4FC8-AFF4-7E416A867F39}
{9EF302BE-21F7-4443-B871-534DA3BEDD59} = {1F11BF5C-810C-4FC8-AFF4-7E416A867F39}
+ {0029D44B-6E6C-4FD5-9071-EEA15A765D37} = {1F11BF5C-810C-4FC8-AFF4-7E416A867F39}
EndGlobalSection
EndGlobal
View
80 ...ce/Machine.Specifications.WebDriverSupport/Machine.Specifications.WebDriverSupport.csproj
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{0029D44B-6E6C-4FD5-9071-EEA15A765D37}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Machine.Specifications.WebDriverSupport</RootNamespace>
+ <AssemblyName>Machine.Specifications.WebDriverSupport</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>..\..\Build\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>..\..\Build\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Ionic.Zip">
+ <HintPath>..\..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="Newtonsoft.Json">
+ <HintPath>..\..\packages\Newtonsoft.Json.4.0.4\lib\net35\Newtonsoft.Json.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="WebDriver">
+ <HintPath>..\..\packages\Selenium.WebDriver.2.17.0\lib\net35\WebDriver.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\SharedAssemblyInfo.cs">
+ <Link>Properties\SharedAssemblyInfo.cs</Link>
+ </Compile>
+ <Compile Include="..\VersionInfo.cs">
+ <Link>Properties\VersionInfo.cs</Link>
+ </Compile>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="WebDriverResultSupplementer.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Machine.Specifications\Machine.Specifications.csproj">
+ <Project>{CCD02629-1262-4F78-9E9F-AC97B942D0E7}</Project>
+ <Name>Machine.Specifications</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
21 Source/Machine.Specifications.WebDriverSupport/Properties/AssemblyInfo.cs
@@ -0,0 +1,21 @@
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+
+[assembly: AssemblyTitle("Machine.Specifications.WebDriverSupport")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+
+[assembly: Guid("5c63b079-75e4-438a-b46d-8fc399d0e779")]
View
73 Source/Machine.Specifications.WebDriverSupport/WebDriverResultSupplementer.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing.Imaging;
+using System.IO;
+
+using OpenQA.Selenium;
+
+namespace Machine.Specifications.WebDriverSupport
+{
+ public abstract class WebDriverResultSupplementer : ISupplementSpecificationResults
+ {
+ protected abstract string ImagesPath { get; }
+ protected abstract ITakesScreenshot Screenshotter { get; }
+ protected abstract IWebDriver WebDriver { get; }
+
+ public Result SupplementResult(Result result)
+ {
+ if (result.Status != Status.Failing)
+ {
+ return result;
+ }
+
+ var guid = Guid.NewGuid();
+ var pageScreenshotPath = Path.Combine(ImagesPath, guid + "-full-page-screenshot.png");
+ var htmlPath = Path.Combine(ImagesPath, guid + ".html");
+
+ var supplement = new Dictionary<string, string>();
+
+ CaptureScreenshot(supplement, pageScreenshotPath);
+ CaptureHtmlSource(supplement, htmlPath);
+
+ return Result.Supplement(result, "WebDriver", supplement);
+ }
+
+ void CaptureScreenshot(IDictionary<string, string> supplement, string screenshotPath)
+ {
+ try
+ {
+ Screenshotter.GetScreenshot().SaveAsFile(screenshotPath, ImageFormat.Png);
+ supplement["img-full-page-screenshot"] = screenshotPath;
+ }
+ catch (Exception error)
+ {
+ Report(error, "img-full-page-screenshot", supplement);
+ }
+ }
+
+ void CaptureHtmlSource(IDictionary<string, string> supplement, string htmlPath)
+ {
+ try
+ {
+ using (var writer = new StreamWriter(htmlPath))
+ {
+ writer.Write(WebDriver.PageSource);
+ }
+ supplement["html-source"] = htmlPath;
+ }
+ catch (Exception error)
+ {
+ Report(error, "html-source", supplement);
+ }
+ }
+
+ static void Report(Exception error, string type, IDictionary<string, string> supplement)
+ {
+ supplement[type] = error.ToString();
+
+ Console.Error.WriteLine();
+ Console.Error.WriteLine("Problem capturing WebDriver {0}", type);
+ Console.Error.WriteLine(error);
+ }
+ }
+}
View
6 Source/Machine.Specifications.WebDriverSupport/packages.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="DotNetZip" version="1.9.1.8" />
+ <package id="Newtonsoft.Json" version="4.0.4" />
+ <package id="Selenium.WebDriver" version="2.17.0" />
+</packages>
Please sign in to comment.
Something went wrong with that request. Please try again.