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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With