diff --git a/src/AxaFrance.AxeExtended.HtmlReport/OverallReportBuilder.cs b/src/AxaFrance.AxeExtended.HtmlReport/OverallReportBuilder.cs index fd67865..c840982 100644 --- a/src/AxaFrance.AxeExtended.HtmlReport/OverallReportBuilder.cs +++ b/src/AxaFrance.AxeExtended.HtmlReport/OverallReportBuilder.cs @@ -71,16 +71,16 @@ public OverallReportBuilder Build() /// /// the filename of export report, default value "index.html" /// the complete path of report - /// public string Export(string fileName = null) { if (!hasBuilt) Build(); string path = Options.OutputFolder ?? Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); - //clean the folder - if (Directory.Exists(path)) + + // if the outpur format is Zip. we need to create a sub-folder and zip the content of that folder. + if(Options.OutputFormat == OutputFormat.Zip) { - Directory.Delete(path, true); + path = Path.Combine(path, Guid.NewGuid().ToString()); } Directory.CreateDirectory(path); int sequence = 1; diff --git a/src/AxaFrance.AxeExtended.HtmlReport/PageReportBuilder.cs b/src/AxaFrance.AxeExtended.HtmlReport/PageReportBuilder.cs index 2118733..248c62a 100644 --- a/src/AxaFrance.AxeExtended.HtmlReport/PageReportBuilder.cs +++ b/src/AxaFrance.AxeExtended.HtmlReport/PageReportBuilder.cs @@ -269,7 +269,7 @@ private string GenerateRuleSection(AxeResultEnhancedItem[] items, string path) if (node.Screenshot != null) { Guid id = Guid.NewGuid(); - filename = id.ToString() + ".png"; + filename = id.ToString() + ".webp"; File.WriteAllBytes(Path.Combine(path, filename), node.Screenshot); } diff --git a/src/AxaFrance.AxeExtended.Selenium/AxeSeleniumHelper.cs b/src/AxaFrance.AxeExtended.Selenium/AxeSeleniumHelper.cs index a94562b..dc6e5ea 100644 --- a/src/AxaFrance.AxeExtended.Selenium/AxeSeleniumHelper.cs +++ b/src/AxaFrance.AxeExtended.Selenium/AxeSeleniumHelper.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.IO; using System.Linq; using System.Xml.Linq; @@ -112,11 +113,11 @@ private static byte[] ScreenShot(WebDriver driver, AxeResultNode node, PageRepor { element = driver.FindElement(By.XPath(xPath)); } - }catch(Exception ex) + } + catch (Exception ex) { //sometimes the cssSelector provided by axe can not be used by selenium. //in this case can't make screenshot on the element. - Console.WriteLine("[A11y] Unable to get element from cssSelector or xPath"); } } @@ -125,7 +126,7 @@ private static byte[] ScreenShot(WebDriver driver, AxeResultNode node, PageRepor { try { - var screenshot = options.UseAdvancedScreenshot ? AdvancedScreenshot(driver, we, options) : we.GetScreenshot().AsByteArray; + var screenshot = options.UseAdvancedScreenshot ? AdvancedScreenshot(driver, we, options) : ToWebpByteArray(we.GetScreenshot()); driver.SwitchTo().DefaultContent(); //goes back to default context (leaving iframes) return screenshot; } @@ -140,16 +141,37 @@ private static byte[] ScreenShot(WebDriver driver, AxeResultNode node, PageRepor { driver.SwitchTo().DefaultContent(); Console.WriteLine("[A11y] The element can not be converted to type WebElement for screenshot."); - return Array.Empty(); + return Array.Empty(); } } + /// + /// Convert selenium screenshot in png format to webp format. + /// + /// Selenium screenshot object. + /// Byte array of an image in webp format + private static byte[] ToWebpByteArray(Screenshot screenshot) + { + //covert screenshot in png format to webp + using (SKBitmap bitmap = SKBitmap.Decode(screenshot.AsByteArray)) + { + using (SKImage img = SKImage.FromBitmap(bitmap)) + { + using (SKData data = img.Encode(SKEncodedImageFormat.Webp, 80)) + { + return data.ToArray(); + } + } + } + + } + private static byte[] AdvancedScreenshot(WebDriver driver, WebElement element, PageReportOptions options) { BringToView(element, driver); - var imageViewPort = driver.GetScreenshot(); + var imageViewPort = driver.GetScreenshot(); var locatable = (ILocatable)element; var location = locatable.Coordinates.LocationInViewport; //location and size are for 100% dpi @@ -189,7 +211,7 @@ private static byte[] MarkOnImage(Screenshot imageViewPort, Point location, Size Style = SKPaintStyle.Stroke, StrokeWidth = options.HighlightThickness }); - using (var data = bitmap.Encode(SKEncodedImageFormat.Png, 100)) + using (var data = bitmap.Encode(SKEncodedImageFormat.Webp, 80)) { return data.ToArray(); } diff --git a/src/WebEngine.Test/UnitTests/Accessibility.cs b/src/WebEngine.Test/UnitTests/Accessibility.cs index 5e7f6aa..3672826 100644 --- a/src/WebEngine.Test/UnitTests/Accessibility.cs +++ b/src/WebEngine.Test/UnitTests/Accessibility.cs @@ -109,6 +109,7 @@ public void AuditWithRGAAAndExportHtml() .WithRgaaExtension() .WithSelenium(driver).Build().Export(); Debug.WriteLine($"Report generated in {sw.Elapsed.TotalSeconds} seconds"); + Debug.WriteLine($"Report {filename}"); Assert.IsTrue(File.Exists(filename)); } @@ -167,6 +168,7 @@ public void UserJourneyTest() string report = builder.Build().Export(); Assert.IsTrue(File.Exists(report)); + Console.WriteLine(report); } }