> For the complete documentation index, see [llms.txt](https://docs.testery.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.testery.io/get-to-know-testery/screenshots.md).

# Screenshots

Testery supports taking screenshots and having those screenshots attached to your test results. This works by placing screenshots in a `screenshots` folder in your current directory using the framework of your choice.

Testery highly recommends adding screenshots to your tests as this can often help you troubleshoot test failures that occur due to pages not loading quickly, elements changing, sites being down, etc.

{% tabs %}
{% tab title="SpecFlow" %}

```csharp
[AfterScenario("screenshot")]
public static void takeScreenshot()
{
    Screenshot s = ((ITakesScreenshot)((IWebDriver)FeatureContext.Current["driver"])).GetScreenshot();
    string fileName = ScenarioContext.Current.ScenarioInfo.Title.Replace(" ","") + DateTime.Now.ToString("_MMddyyyyHHmmss") + ".png";            
    try
    {
        string screenshotDir = ScenarioContext.Current.ScenarioContainer.Resolve<TestContext>().WorkDirectory.ToString() + @"\screenshots";
        if (!Directory.Exists(screenshotDir))
        {
            Directory.CreateDirectory(screenshotDir);
        }
        s.SaveAsFile(screenshotDir + @"\" + fileName, ScreenshotImageFormat.Png);
        TestContext.Out.WriteLine($"-> info: added screenshot ({fileName}) to dir ({screenshotDir})");;            } 
    catch(Exception e)
    {
        TestContext.Out.WriteLine($"-> error: ({e})");
    }        
}
```

{% endtab %}

{% tab title="webdriver.io" %}

```javascript
  let fs = require('fs');
  if (!fs.existsSync("./screenshots")){
    console.log("Screenshots dir being created.");
    fs.mkdirSync("./screenshots");
  } 
  browser.saveScreenshot("./screenshots/" + Math.random() + ".png");
```

{% endtab %}
{% endtabs %}

In the SpecFlow example above, the after scenario hook will be executed right after a test either passes or fails if when the @takeScreenshot tag is included on a feature file. The ("screenshot") can be removed from the \[AfterScenario] annotation and that will run the hook without having to specify the @screenshot tag.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.testery.io/get-to-know-testery/screenshots.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
