private static string GetContextContent(AxeResult results) { var contextContent = new StringBuilder() .AppendLine($"Url: {results.Url}<br>") .AppendLine($"Orientation: {results.TestEnvironment.OrientationType}<br>") .AppendLine($"Size: {results.TestEnvironment.WindowWidth} x {results.TestEnvironment.WindowHeight}<br>") .AppendLine($"Time: {results.Timestamp}<br>") .AppendLine($"User agent: {results.TestEnvironment.UserAgent}<br>") .AppendLine($"Using: {results.TestEngineName} ({results.TestEngineVersion})") .ToString(); return(contextContent); }
public static void CreateAxeHtmlReport(this ISearchContext context, AxeResult results, string destination) { HashSet <string> selectors = new HashSet <string>(); int violationCount = GetCount(results.Violations, ref selectors); int incompleteCount = GetCount(results.Incomplete, ref selectors); int passCount = GetCount(results.Passes, ref selectors); int inapplicableCount = GetCount(results.Inapplicable, ref selectors); var doc = new HtmlDocument(); var node = HtmlNode.CreateNode("<html lang=\"en\"><head><meta charset=\"utf-8\"><title>Accessiblity Check</title><style></style></head><body></body></html>"); doc.DocumentNode.AppendChild(node); HtmlCommentNode hcn = doc.CreateComment("<!DOCTYPE html>\r\n"); HtmlNode htmlNode = doc.DocumentNode.SelectSingleNode("/html"); doc.DocumentNode.InsertBefore(hcn, htmlNode); StringBuilder content = new StringBuilder(); content.AppendLine(@".fullImage{"); content.AppendLine($"content: url('{GetDataImageString(context)};border: 1px solid black;margin-left:1em;"); content.AppendLine(@"} .fullImage:hover {transform:scale(2.75);transform-origin: top left;} p {} .wrap .wrapTwo .wrapThree{margin:2px;max-width:70vw;} .wrapOne {margin-left:1em;overflow-wrap:anywhere;} .wrapTwo {margin-left:2em;overflow-wrap:anywhere;} .wrapThree {margin-left:3em;overflow-wrap:anywhere;} .emOne {margin-left:1em;overflow-wrap:anywhere;} .emTwo {margin-left:2em;overflow-wrap:anywhere;} .emThree {margin-left:3em;overflow-wrap:anywhere;} .majorSection{border: 1px solid black;} .findings{border-top:1px solid black;} .htmlTable{border-top:double lightgray;width:100%;display:table;}"); HtmlNode body = doc.DocumentNode.SelectSingleNode("//body"); doc.DocumentNode.SelectSingleNode("//style").InnerHtml = content.ToString(); var element = doc.CreateElement("h1"); element.InnerHtml = "Accessiblity Check"; body.AppendChild(element); element = doc.CreateElement("h3"); element.InnerHtml = "Context:"; body.AppendChild(element); content = new StringBuilder(); content.AppendLine($"Url: {results.Url}<br>"); content.AppendLine($"Orientation: {results.TestEnvironment.OrientationType}<br>"); content.AppendLine($"Size: {results.TestEnvironment.WindowWidth} x {results.TestEnvironment.WindowHeight}<br>"); content.AppendLine($"Time: {results.Timestamp}<br>"); content.AppendLine($"User agent: {results.TestEnvironment.UserAgent}<br>"); content.AppendLine($"Using: {results.TestEngineName} ({results.TestEngineVersion})"); element = doc.CreateElement("div"); element.SetAttributeValue("class", "emOne"); element.SetAttributeValue("id", "reportContext"); element.InnerHtml = content.ToString(); body.AppendChild(element); element = doc.CreateElement("h3"); element.InnerHtml = "Counts:"; body.AppendChild(element); element = doc.CreateElement("div"); element.SetAttributeValue("class", "emOne"); content = new StringBuilder(); content.AppendLine($" Violation: {violationCount}<br>"); content.AppendLine($" Incomplete: {incompleteCount}<br>"); content.AppendLine($" Pass: {passCount}<br>"); content.AppendLine($" Inapplicable: {inapplicableCount}"); element.InnerHtml = content.ToString(); body.AppendChild(element); element = doc.CreateElement("h3"); element.InnerHtml = "Image:"; body.AppendChild(element); element = doc.CreateElement("img"); element.SetAttributeValue("class", "fullImage"); element.SetAttributeValue("width", "33%"); element.SetAttributeValue("height", "auto"); body.AppendChild(element); if (!string.IsNullOrEmpty(results.Error)) { element = doc.CreateElement("h2"); element.InnerHtml = "SCAN ERRORS:"; body.AppendChild(element); var error = doc.CreateElement("div"); error.SetAttributeValue("id", "ErrorMessage"); error.InnerHtml = HttpUtility.HtmlEncode(results.Error); body.AppendChild(error); } element = doc.CreateElement("br"); body.AppendChild(element); element = doc.CreateElement("br"); body.AppendChild(element); var area = doc.CreateElement("div"); body.AppendChild(area); if (violationCount > 0) { area.AppendChild(doc.CreateElement("br")); GetReadableAxeResults(results.Violations, "Violations", doc, area); } if (incompleteCount > 0) { area.AppendChild(doc.CreateElement("br")); GetReadableAxeResults(results.Incomplete, "Incomplete", doc, area); } if (passCount > 0) { area.AppendChild(doc.CreateElement("br")); GetReadableAxeResults(results.Passes, "Passes", doc, area); } if (inapplicableCount > 0) { area.AppendChild(doc.CreateElement("br")); GetReadableAxeResults(results.Inapplicable, "Inapplicable", doc, area); } doc.Save(destination, Encoding.UTF8); }
public static void CreateAxeHtmlReport(this ISearchContext context, AxeResult results, string destination, ReportTypes requestedResults) { // Get the unwrapped element if we are using a wrapped element context = context is IWrapsElement ? (context as IWrapsElement).WrappedElement : context; var selectors = new HashSet <string>(); var violationCount = GetCount(results.Violations, ref selectors); var incompleteCount = GetCount(results.Incomplete, ref selectors); var passCount = GetCount(results.Passes, ref selectors); var inapplicableCount = GetCount(results.Inapplicable, ref selectors); var doc = new HtmlDocument(); doc.CreateComment("<!DOCTYPE html>\r\n"); var htmlStructure = HtmlNode.CreateNode("<html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Accessibility Check</title><style></style></head><body><content></content><script></script></body></html>"); doc.DocumentNode.AppendChild(htmlStructure); doc.DocumentNode.SelectSingleNode("//style").InnerHtml = GetCss(context); var contentArea = doc.DocumentNode.SelectSingleNode("//content"); var reportTitle = doc.CreateElement("h1"); reportTitle.InnerHtml = "Accessibility Check"; contentArea.AppendChild(reportTitle); var metaFlex = doc.CreateElement("div"); metaFlex.SetAttributeValue("id", "metadata"); contentArea.AppendChild(metaFlex); var contextGroup = doc.CreateElement("div"); contextGroup.SetAttributeValue("id", "context"); metaFlex.AppendChild(contextGroup); var contextHeader = doc.CreateElement("h3"); contextHeader.InnerHtml = "Context:"; contextGroup.AppendChild(contextHeader); var contextContent = doc.CreateElement("div"); contextContent.SetAttributeValue("class", "emOne"); contextContent.SetAttributeValue("id", "reportContext"); contextContent.InnerHtml = GetContextContent(results); contextGroup.AppendChild(contextContent); var imgGroup = doc.CreateElement("div"); imgGroup.SetAttributeValue("id", "image"); metaFlex.AppendChild(imgGroup); var imageHeader = doc.CreateElement("h3"); imageHeader.InnerHtml = "Image:"; imgGroup.AppendChild(imageHeader); var imageContent = doc.CreateElement("img"); imageContent.SetAttributeValue("class", "thumbnail"); imageContent.SetAttributeValue("id", "screenshotThumbnail"); imageContent.SetAttributeValue("alt", "A Screenshot of the page"); imageContent.SetAttributeValue("width", "33%"); imageContent.SetAttributeValue("height", "auto"); imgGroup.AppendChild(imageContent); var countsGroup = doc.CreateElement("div"); countsGroup.SetAttributeValue("id", "counts"); metaFlex.AppendChild(countsGroup); var countsHeader = doc.CreateElement("h3"); countsHeader.InnerHtml = "Counts:"; countsGroup.AppendChild(countsHeader); var countsContent = doc.CreateElement("div"); countsContent.SetAttributeValue("class", "emOne"); var countsString = GetCountContent(violationCount, incompleteCount, passCount, inapplicableCount, requestedResults); countsContent.InnerHtml = countsString.ToString(); countsGroup.AppendChild(countsContent); var resultsFlex = doc.CreateElement("div"); resultsFlex.SetAttributeValue("id", "results"); contentArea.AppendChild(resultsFlex); if (!string.IsNullOrEmpty(results.Error)) { var errorHeader = doc.CreateElement("h2"); errorHeader.InnerHtml = "SCAN ERRORS:"; contentArea.AppendChild(errorHeader); var errorContent = doc.CreateElement("div"); errorContent.SetAttributeValue("id", "ErrorMessage"); errorContent.InnerHtml = HttpUtility.HtmlEncode(results.Error); contentArea.AppendChild(errorContent); } if (violationCount > 0 && requestedResults.HasFlag(ReportTypes.Violations)) { GetReadableAxeResults(results.Violations, ResultType.Violations.ToString(), doc, resultsFlex); } if (incompleteCount > 0 && requestedResults.HasFlag(ReportTypes.Incomplete)) { GetReadableAxeResults(results.Incomplete, ResultType.Incomplete.ToString(), doc, resultsFlex); } if (passCount > 0 && requestedResults.HasFlag(ReportTypes.Passes)) { GetReadableAxeResults(results.Passes, ResultType.Passes.ToString(), doc, resultsFlex); } if (inapplicableCount > 0 && requestedResults.HasFlag(ReportTypes.Inapplicable)) { GetReadableAxeResults(results.Inapplicable, ResultType.Inapplicable.ToString(), doc, resultsFlex); } var modal = doc.CreateElement("div"); modal.SetAttributeValue("id", "modal"); contentArea.AppendChild(modal); var modalClose = doc.CreateElement("div"); modalClose.InnerHtml = "X"; modalClose.SetAttributeValue("id", "modalclose"); modal.AppendChild(modalClose); var modalImage = doc.CreateElement("img"); modalImage.SetAttributeValue("id", "modalimage"); modal.AppendChild(modalImage); doc.DocumentNode.SelectSingleNode("//script").InnerHtml = js; doc.Save(destination, Encoding.UTF8); }
public static void CreateAxeHtmlReport(this ISearchContext context, AxeResult results, string destination) { context.CreateAxeHtmlReport(results, destination, ReportTypes.All); }