-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
39 changes: 39 additions & 0 deletions
39
TestingFramework/TestingFrameworkTemplates/Resources/AssertHtmlTag.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
49 changes: 49 additions & 0 deletions
49
TestingFramework/TestingFrameworkTemplates/Test/AssertHtmlElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters