[TechSpeak] Sitecore Test Image Previews Not Displaying: What to Do

Updated Apr 8, 2024

When you try to create a new Sitecore content test and preview by opening a test dialog window, you may see a screen in which previews are not displaying. But why?

Sitecore-test-image-previews-absent-photo

I asked myself this question when I faced such an issue while working on one of our client projects.

In this article, I would like to explain the root cause of this bug and tell you which Sitecore tool I utilized to generate screenshots for test previews. For this purpose, I simulated the problem on my local Sitecore Habitat instance. The following is my step-by-step instruction.

Step 1

First of all, I opened the Chrome DevTool Console panel and checked that no errors had been detected.

Sitecore-test-Chrome-dev-tool-console-photo

Step 2

Then, I had to check Sitecore logs that are critical for diagnosing issues with Sitecore solutions. On my local Habitat instance, the log files are located in:

Sitecore-habitat-local-photo

In a while, I found the following output messages:

ManagedPoolThread #2 22:14:53 INFO Job started: Generate screenshots

22:14:53 ERROR [Content Testing]: Cannot find PhantomJS executable at 'C:\inetpub\wwwroot\habitat.dev.local\App_Data/tools/phantomjs/phantomjs.exe'. Aborting screenshot generation.

...

ManagedPoolThread #2 22:14:53 INFO Job ended: Generate screenshots (units processed: 6)

Hmmm… Just thinking out loud: there is a Sitecore job that tries to handle executable PhantomJS tool that generates screenshots, and this tool was not found at

~/App_Data/tools/phantomjs/phantomjs.exe

What kind of monster is PhantomJS that plays the main role there? I started googling and was navigated to the official doc.sitecore.com portal. There, I discovered the following information:

Sitecore uses PhantomJS to generate screenshots of pages for use in the Sitecore clients. It is an external executable (.exe) file that ships with Sitecore in the $(dataFolder)\tools\phantomjs folder. Sitecore references this file through the ContentTesting.PhantomJS.ExecutablePath setting in the \App_Config\Sitecore\ContentTesting\Sitecore.ContentTesting.config patch file.

Ok. Now we know what a PhantomJS is. Let’s jump back to our issue.

Step 3

The following thing that I checked was the data folder (C:\inetpub\wwwroot\habitat.dev.local\App_Data). I figured out that there had indeed been no tools folder inside:

Sitecore-test-data-folder-photo

Step 4

So, where can I take the PhantomJS tool to put it into my Habitat instance? Of course, I can download the appropriate Sitecore package from the official download portal, where this tool should be located. Let’s check this guess!

My local Sitecore instance is based on Sitecore 9.1. Update-1. Therefore, I can download the appropriate package (XP0, XP1, XM1, etc. — depending on the Sitecore role deployed).

Sitecore-download-options-image

In my case, I downloaded the On-Premises XP Single (XP0) package.

Sitecore 9.1.1 rev. 002459 (WDP XP0 packages).zip

Sitecore-package-downloaded-image

Inside the archive, I found the target tools folder that contains PhantomJS files:

Tools-folder-PhantomJS-photo

The full archive path is:

Sitecore 9.1.1 rev. 002459 (WDP XP0 packages).zip\Sitecore 9.1.1 rev. 002459 (OnPrem)_single.scwdp.zip\Content\Website\App_Data\tools\phantomjs

Then, I copied tools folder into C:\inetpub\wwwroot\habitat.dev.local\App_Data\

PhantomJS-tools-folder-photo

Step 5

It seemed I could test my fix. I did the following:

  • Navigated to local Habitat Content Editor
  • Selected a Home item to create a content test
Sitecore-habitat-content-editor-photo
  • I clicked “Create a test” link. I chose preview, and the start test modal window appeared with all the displayed previews! Wow, this is a real victory!
Sitecore-preview-test-photo
Sitecore-content-test-image

Some Facts I Have Learned about the PhantomJS Tool

  • By default, generated screenshots are stored into the temp/screenshots folder. You should check this folder if you have similar problems.
Sitecore-test-screenshots-photo
  • PhantomJS settings are configured in the \App_Config\Sitecore\ContentTesting\Sitecore.ContentTesting.config patch file, e.g. you can set up a folder where this tool will be located.
PhantomJS-settings-photo

Important Note from Sitecore

If you want to put restrictions on access to the PhantomJS executable file, you should place a data folder outside the root folder, creating a patch for the tempFolder variable.

Example:

<sitecore database=“SqlServer” xmlns:patch=“http://www.sitecore.net/xmlconfig/
xmlns:role=“http://www.sitecore.net/xmlconfig/role/”
xmlns:security=“http://www.sitecore.net/xmlconfig/security/”>  
<sc.variable name=“tempFolder” value=“/data” /></sitecore>

What Concerns Security

Generated screenshots are used in the UI and emails, thus this functionality is not required on content delivery servers. To disable this functionality, you should do the following:

  • Remove the $(dataFolder)\tools\phantomjs folder, including the phantomjs.exe executable file.
  • Disable the getScreenshotForUrl pipeline that launches thePhantomJS process. To disable thegetScreenshotForUrl pipeline, create a patch file that disables it in the Sitecore.ContentTesting.config configuration file.

Hope this blog post helps you! That is all for today — happy coding, dear Sitecorians!

14 Comments
Leave a comment
  • Way cool! Some extremely valid points! I appreciate you writing this article and also the rest of the site is very good.

  • Hi, I check your blog on a regular basis. Your story-telling style is witty, keep it up!

  • Everything is very open with a precise description of the challenges.
    It was truly informative. Your website is very useful.
    Thanks for sharing!

  • Way cool! Some extremely valid points! I appreciate you writing this article and the rest of the website is very good.

  • I was suggested this website by my cousin. Nobody else know such detailed about my problem. You are incredible!
    Thanks!

  • Hiya very cool site!! Man .. Excellent .. Superb .. I’ll bookmark your blog and take the feeds additionally?
    I’m satisfied to seek out a lot of helpful info here in the publish, we need work out extra techniques on this regard, thank you for sharing.

  • Nice! This has been a really wonderful article. Many thanks for providing these details.

  • Perfect work you have done, this website is really cool with excellent information.

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>