Created
October 24, 2017 03:46
-
-
Save jraps20/ff3872110cac95cb29fb52a6644d1070 to your computer and use it in GitHub Desktop.
Gist to illustrate modifying the PhantomJS default timeout of zero to a new value
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 Sitecore.ContentTesting.Pipelines.GetScreenShotForURL; | |
namespace MyLibrary.GetScreenShotForURL | |
{ | |
public class AddTimeoutToScript : GenerateScreenShotProcessor | |
{ | |
public string Timeout { get; set; } | |
private const string StandardExit = "phantom.exit();\r\n});"; | |
private string TimeoutExit => "window.setTimeout(function () {\r\n page.render('%outfile%');\r\n phantom.exit();\r\n }, " + Timeout + ");\r\n});"; | |
public override void Process(GetScreenShotForURLArgs args) | |
{ | |
args.Script = args.Script.Replace(StandardExit, TimeoutExit); | |
var outputFilePath = Sitecore.ContentTesting.Helpers.PathHelper.MapPath(args.OutputFilename).Replace("\\", "\\\\"); | |
args.Script = args.Script.Replace($"page.render('{outputFilePath}');", ""); | |
args.Script = args.Script.Replace("%outfile%", outputFilePath); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment