Skip to content

Commit

Permalink
Added HTML tag assertion template
Browse files Browse the repository at this point in the history
  • Loading branch information
andreym committed Sep 27, 2013
1 parent 9dce75a commit 8693346
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
Binary file added ReferenceAssemblies/HtmlAgilityPack.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<xsd:schema elementFormDefault="qualified" targetNamespace="StringAssert" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="StringAssert" xmlns:tcmi="http://www.tridion.com/ContentManager/5.0/Instance">
<xsd:import namespace="http://www.tridion.com/ContentManager/5.0/Instance" schemaLocation="cm_xml_inst.xsd"></xsd:import>
<xsd:annotation>
<xsd:appinfo>
<tcm:Labels xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
<tcm:Label ElementName="xpath" Metadata="false">xpath</tcm:Label>
<tcm:Label ElementName="expectedValue" Metadata="false">expectedValue</tcm:Label>
<tcm:Label ElementName="outputName" Metadata="false">outputName</tcm:Label>
</tcm:Labels>
</xsd:appinfo>
</xsd:annotation>
<xsd:element name="Parameters">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="xpath" minOccurs="1" maxOccurs="1" type="xsd:normalizedString">
<xsd:annotation>
<xsd:appinfo>
<ExtensionXml xmlns="http://www.tridion.com/ContentManager/5.0"></ExtensionXml>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="expectedValue" minOccurs="1" maxOccurs="1" type="xsd:normalizedString">
<xsd:annotation>
<xsd:appinfo>
<ExtensionXml xmlns="http://www.tridion.com/ContentManager/5.0"></ExtensionXml>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="outputName" minOccurs="0" maxOccurs="1" type="xsd:normalizedString">
<xsd:annotation>
<xsd:appinfo>
<ExtensionXml xmlns="http://www.tridion.com/ContentManager/5.0"></ExtensionXml>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HtmlAgilityPack;
using Tridion.ContentManager.Templating;
using Tridion.ContentManager.Templating.Assembly;

namespace Tridion.Extensions.Testing.Templates
{
[TcmTemplateParameterSchema(ParameterSchema = "resource:Tridion.Extensions.Testing.Resources.AssertHtmlTag.xsd")]
[TcmTemplateTitle("Assert html element has correct value")]
public class AssertHtmlElement : BaseTest
{
public override void Test()
{
if (Package.GetByName("xpath") == null)
{
throw new Exception("xpath parameter is not set");
}
if (Package.GetByName("expectedValue") == null)
{
throw new Exception("expectedValue parameter is not set");
}


var outputName = "Output";
if (Package.GetByName("outputName") != null) { outputName = Package.GetByName("outputName").GetAsString(); }

if (Package.GetByName(outputName) == null)
{
throw new Exception(string.Format("Output variable {0} not found in the package", outputName));
}

var html = new HtmlDocument();
html.LoadHtml(Package.GetByName(outputName).GetAsString());

var tag = html.DocumentNode.SelectSingleNode(Package.GetByName("xpath").GetAsString());
if (tag == null)
{
Fail(string.Format("No element matching {0}", Package.GetByName("xpath").GetAsString()));
}

AreEqual(Package.GetByName("expectedValue").GetAsString(), tag.InnerHtml);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="HtmlAgilityPack, Version=1.4.6.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\ReferenceAssemblies\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -59,6 +63,7 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Setup\AddItemToPackage.cs" />
<Compile Include="Test\AssertHtmlElement.cs" />
<Compile Include="Test\AssertString.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -77,6 +82,11 @@
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Resources\AssertHtmlTag.xsd">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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.
Expand Down

0 comments on commit 8693346

Please sign in to comment.