Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screenshot taken at Exception via Selenium PhantomJS

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.

like image 637
Arya Avatar asked Oct 20 '22 02:10

Arya


1 Answers

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);                          
   }
like image 51
ekostadinov Avatar answered Oct 22 '22 21:10

ekostadinov