5

Once in a while I get an exception in my Selenium PhantomJS tests that includes the text below

Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken

So has the screenshot really been taken like the message says? where would this screenshot be saved at? I checked the program directory and no image was saved.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Arya
  • 8,473
  • 27
  • 105
  • 175

1 Answers1

3

In my implementation the folder is specified in the App.config file, like so:

<add key="ScreenShot.FolderPath" value="..\\..\\..\\TestProject\\Screenshots\\" />

This is helpful when you have your CI server running the auto tests. So the XML poke will look like this:

<XmlPoke XmlInputPath="TestProject\App.config"
             Query="//appSettings/add[@key='ScreenShot.FolderPath']/@value"
             Value="$(ScreenShot.FolderPath)"/>

And finally in your code you point where the actual screenshots to be saved:

var screenshotDriver = IWebDriver as ITakesScreenshot;
if (screenshotDriver != null)
   {
     var screenshot = screenshotDriver.GetScreenshot();
     screenshot.SaveAsFile(ConfigurationManager.AppSettings["ScreenShot.FolderPath"] 
                           + screenShotName, ImageFormat.Jpeg);                          
   }
ekostadinov
  • 6,880
  • 3
  • 29
  • 47