Created
March 16, 2023 18:50
-
-
Save benbrandt22/abe7b26eaf03bd9e30113fda9aeb77d2 to your computer and use it in GitHub Desktop.
Test Helper - Send HTML string to display in a browser
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
using System.Diagnostics; | |
public static class TestingHelpers | |
{ | |
/// <summary> | |
/// Opens a browser and displays the provided HTML, without needing to save it to disk | |
/// </summary> | |
public static void DisplayHtmlInBrowser(string html, string browserExe = "chrome.exe") | |
{ | |
var toEncodeAsBytes = System.Text.Encoding.ASCII.GetBytes(html); | |
var base64EncodedHtml = System.Convert.ToBase64String(toEncodeAsBytes); | |
var dataUri = $"data:text/html;base64,{base64EncodedHtml}"; | |
Process.Start(new ProcessStartInfo { FileName = browserExe, Arguments = dataUri, UseShellExecute = true }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment