{
  "doc": {
    "id": "api/commands/screenshot",
    "title": "screenshot | Cypress Documentation",
    "description": "Take a screenshot of the application under test and, optionally, the Cypress Command Log.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/screenshot.md",
    "version": "48b03b5502f7aea1d0454750cce208f775403542",
    "updated_at": "2026-05-20T19:00:20.270Z",
    "headings": [
      {
        "id": "api/commands/screenshot#screenshot",
        "text": "screenshot",
        "level": 1
      },
      {
        "id": "api/commands/screenshot#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/screenshot#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/screenshot#no-args",
        "text": "No Args",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#take-a-screenshot",
        "text": "Take a screenshot",
        "level": 4
      },
      {
        "id": "api/commands/screenshot#filename",
        "text": "Filename",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#take-a-screenshot-and-save-as-a-specific-filename",
        "text": "Take a screenshot and save as a specific filename",
        "level": 4
      },
      {
        "id": "api/commands/screenshot#take-a-screenshot-and-save-in-a-specific-directory",
        "text": "Take a screenshot and save in a specific directory",
        "level": 4
      },
      {
        "id": "api/commands/screenshot#clip",
        "text": "Clip",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#crop-a-screenshot-to-a-specific-position-and-size",
        "text": "Crop a screenshot to a specific position and size",
        "level": 4
      },
      {
        "id": "api/commands/screenshot#screenshot-an-element",
        "text": "Screenshot an element",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#take-a-screenshot-of-the-first-post-element",
        "text": "Take a screenshot of the first .post element",
        "level": 4
      },
      {
        "id": "api/commands/screenshot#take-a-screenshot-of-the-first-post-element-with-10px-of-padding-around-it",
        "text": "Take a screenshot of the first .post element with 10px of padding around it",
        "level": 4
      },
      {
        "id": "api/commands/screenshot#chain-off-the-screenshot-to-click-the-element-captured",
        "text": "Chain off the screenshot to click the element captured",
        "level": 4
      },
      {
        "id": "api/commands/screenshot#get-screenshot-info-from-the-onafterscreenshot-callback",
        "text": "Get screenshot info from the onAfterScreenshot callback",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#notes",
        "text": "Notes",
        "level": 2
      },
      {
        "id": "api/commands/screenshot#naming-conventions",
        "text": "Naming conventions",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#after-screenshot-plugin-event",
        "text": "after:screenshot plugin event",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#test-failures",
        "text": "Test Failures",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#automatic-screenshots-on-test-failure",
        "text": "Automatic screenshots on test failure",
        "level": 4
      },
      {
        "id": "api/commands/screenshot#viewing-screenshots",
        "text": "Viewing Screenshots",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#screenshots-in-ci",
        "text": "Screenshots in CI",
        "level": 4
      },
      {
        "id": "api/commands/screenshot#asynchronous",
        "text": "Asynchronous",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#understanding-when-the-screenshot-is-taken",
        "text": "Understanding when the screenshot is taken",
        "level": 4
      },
      {
        "id": "api/commands/screenshot#full-page-captures-and-fixed-sticky-elements",
        "text": "Full page captures and fixed/sticky elements",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#chromium-specific-behavior-with-regard-to-tabs",
        "text": "Chromium-specific behavior with regard to tabs",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/screenshot#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/screenshot#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/screenshot#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/commands/screenshot#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/screenshot#syntax",
      "doc_id": "api/commands/screenshot",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\n.screenshot().screenshot(fileName).screenshot(options).screenshot(fileName, options)// ---or---cy.screenshot()cy.screenshot(fileName)cy.screenshot(options)cy.screenshot(fileName, options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.screenshot()cy.get('.post').screenshot()\n```\n\n### Arguments\n\n**fileName _(String)_**\n\nA name for the image file. Will be relative to the [screenshots folder](/llm/markdown/app/references/configuration.md#Folders--Files) and the path to the spec file. When passed a path, the folder structure will be created. See the [Naming conventions](/llm/markdown/api/commands/screenshot.md#Naming-conventions) below for more.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.screenshot()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `blackout` | `[]` | Array of string selectors used to match elements that should be blacked out when the screenshot is taken. Does not apply to `runner` captures. |\n| `capture` | `'fullPage'` | Which parts of the Cypress Test Runner to capture. This value is ignored for element screenshot captures. Valid values are `viewport`, `fullPage`, or `runner`. When `viewport`, the application under test is captured in the current viewport. When `fullPage`, the application under test is captured in its entirety from top to bottom. When `runner`, the entire browser viewport, including the Cypress Command Log, is captured. For screenshots automatically taken on test failure, capture is always coerced to `runner`. When [Test Replay](/llm/markdown/cloud/features/test-replay.md) is enabled and the Runner UI is hidden, a `runner` screenshot will not include the Runner UI and will instead capture the application under test only in the current viewport. |\n| `clip` | `null` | Position and dimensions (in pixels) used to crop the final screenshot image. Should have the following shape: `{ x: 0, y: 0, width: 100, height: 100 }` |\n| `disableTimersAndAnimations` | `true` | When true, prevents JavaScript timers (`setTimeout`, `setInterval`, etc) and CSS animations from running while the screenshot is taken. |\n| `padding` | `null` | Padding used to alter the dimensions of a screenshot of an element. It can either be a number, or an array of up to four numbers [using CSS shorthand notation](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties). This property is only applied for element screenshots and is ignored for all other types. |\n| `scale` | `false` | Whether to scale the app to fit into the browser viewport. This is always coerced to `true` when `capture` is `runner`. |\n| `timeout` | [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `.screenshot()` to resolve before [timing out](#Timeouts) |\n| `overwrite` | `false` | Whether to overwrite duplicate screenshot files with the same file name when saving. |\n| `onBeforeScreenshot` | `null` | A callback before a non-failure screenshot is taken. When capturing screenshots of an element, the argument is the element being captured. For other screenshots, the argument is the `document`. |\n| `onAfterScreenshot` | `null` | A callback after a non-failure screenshot is taken. When capturing screenshots of an element, the first argument is the element being captured. For other screenshots, the first argument is the `document`. The second argument is properties concerning the screenshot, including the `path` it was saved to and the `dimensions` of the saved screenshot. |\n\nFor more details on these options and to set some as defaults across all uses of `.screenshot()`, see the [Cypress.Screenshot API doc](/llm/markdown/api/cypress-api/screenshot-api.md).\n\n### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n*   `.screenshot()` yields the same subject it was given.\n*   It is [unsafe](/llm/markdown/app/core-concepts/retry-ability.md#Only-queries-are-retried) to chain further commands that rely on the subject after `.screenshot()`.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 745
    },
    {
      "id": "api/commands/screenshot#arguments",
      "doc_id": "api/commands/screenshot",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**fileName _(String)_**\n\nA name for the image file. Will be relative to the [screenshots folder](/llm/markdown/app/references/configuration.md#Folders--Files) and the path to the spec file. When passed a path, the folder structure will be created. See the [Naming conventions](/llm/markdown/api/commands/screenshot.md#Naming-conventions) below for more.\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.screenshot()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `blackout` | `[]` | Array of string selectors used to match elements that should be blacked out when the screenshot is taken. Does not apply to `runner` captures. |\n| `capture` | `'fullPage'` | Which parts of the Cypress Test Runner to capture. This value is ignored for element screenshot captures. Valid values are `viewport`, `fullPage`, or `runner`. When `viewport`, the application under test is captured in the current viewport. When `fullPage`, the application under test is captured in its entirety from top to bottom. When `runner`, the entire browser viewport, including the Cypress Command Log, is captured. For screenshots automatically taken on test failure, capture is always coerced to `runner`. When [Test Replay](/llm/markdown/cloud/features/test-replay.md) is enabled and the Runner UI is hidden, a `runner` screenshot will not include the Runner UI and will instead capture the application under test only in the current viewport. |\n| `clip` | `null` | Position and dimensions (in pixels) used to crop the final screenshot image. Should have the following shape: `{ x: 0, y: 0, width: 100, height: 100 }` |\n| `disableTimersAndAnimations` | `true` | When true, prevents JavaScript timers (`setTimeout`, `setInterval`, etc) and CSS animations from running while the screenshot is taken. |\n| `padding` | `null` | Padding used to alter the dimensions of a screenshot of an element. It can either be a number, or an array of up to four numbers [using CSS shorthand notation](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties). This property is only applied for element screenshots and is ignored for all other types. |\n| `scale` | `false` | Whether to scale the app to fit into the browser viewport. This is always coerced to `true` when `capture` is `runner`. |\n| `timeout` | [`responseTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `.screenshot()` to resolve before [timing out](#Timeouts) |\n| `overwrite` | `false` | Whether to overwrite duplicate screenshot files with the same file name when saving. |\n| `onBeforeScreenshot` | `null` | A callback before a non-failure screenshot is taken. When capturing screenshots of an element, the argument is the element being captured. For other screenshots, the argument is the `document`. |\n| `onAfterScreenshot` | `null` | A callback after a non-failure screenshot is taken. When capturing screenshots of an element, the first argument is the element being captured. For other screenshots, the first argument is the `document`. The second argument is properties concerning the screenshot, including the `path` it was saved to and the `dimensions` of the saved screenshot. |\n\nFor more details on these options and to set some as defaults across all uses of `.screenshot()`, see the [Cypress.Screenshot API doc](/llm/markdown/api/cypress-api/screenshot-api.md).\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 685
    },
    {
      "id": "api/commands/screenshot#yields-learn-about-subject-management",
      "doc_id": "api/commands/screenshot",
      "heading": "Yields Learn about subject management",
      "heading_level": 3,
      "content_markdown": "### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n*   `.screenshot()` yields the same subject it was given.\n*   It is [unsafe](/llm/markdown/app/core-concepts/retry-ability.md#Only-queries-are-retried) to chain further commands that rely on the subject after `.screenshot()`.\n",
      "section": "api",
      "anchors": [
        "yields-learn-about-subject-management"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 40
    },
    {
      "id": "api/commands/screenshot#examples",
      "doc_id": "api/commands/screenshot",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\nThe screenshot will be stored in the `cypress/screenshots` folder by default. You can change the directory where screenshots are saved in the [Cypress configuration](/llm/markdown/app/references/configuration.md#Folders--Files).\n\n### No Args\n\n#### Take a screenshot\n\n```\n// cypress/e2e/users.cy.jsdescribe('my tests', () => {  it('takes a screenshot', () => {    // screenshot will be saved as    // cypress/screenshots/users.cy.js/my tests -- takes a screenshot.png    cy.screenshot()  })})\n```\n\n### Filename\n\n#### Take a screenshot and save as a specific filename\n\n```\n// screenshot will be saved as// cypress/screenshots/spec.cy.js/clicking-on-nav.pngcy.screenshot('clicking-on-nav')\n```\n\n#### Take a screenshot and save in a specific directory\n\n```\n// screenshot will be saved as// cypress/screenshots/spec.cy.js/actions/login/clicking-login.pngcy.screenshot('actions/login/clicking-login')\n```\n\n### Clip\n\n#### Crop a screenshot to a specific position and size\n\n```\n// screenshot will be clipped 20px from the top and left// to the dimensions 400px x 300pxcy.screenshot({ clip: { x: 20, y: 20, width: 400, height: 300 } })\n```\n\n### Screenshot an element\n\n#### Take a screenshot of the first `.post` element\n\n```\ncy.get('.post').first().screenshot()\n```\n\n#### Take a screenshot of the first `.post` element with 10px of padding around it\n\n```\ncy.get('.post').first().screenshot({ padding: 10 })\n```\n\n#### Chain off the screenshot to click the element captured\n\n```\ncy.get('button').first().screenshot().click()\n```\n\n### Get screenshot info from the `onAfterScreenshot` callback\n\n```\ncy.screenshot('my-screenshot', {  onAfterScreenshot($el, props) {    // props has information about the screenshot,    // including but not limited to the following:    // {    //   name: 'my-screenshot',    //   path: '/Users/janelane/project/screenshots/spec.cy.js/my-screenshot.png',    //   size: '15 kb',    //   dimensions: {    //     width: 1000,    //     height: 660,    //   },    //   scaled: true,    //   blackout: [],    //   duration: 2300,    // }  },})\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 347
    },
    {
      "id": "api/commands/screenshot#no-args",
      "doc_id": "api/commands/screenshot",
      "heading": "No Args",
      "heading_level": 3,
      "content_markdown": "### No Args\n\n#### Take a screenshot\n\n```\n// cypress/e2e/users.cy.jsdescribe('my tests', () => {  it('takes a screenshot', () => {    // screenshot will be saved as    // cypress/screenshots/users.cy.js/my tests -- takes a screenshot.png    cy.screenshot()  })})\n```\n",
      "section": "api",
      "anchors": [
        "no-args"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 48
    },
    {
      "id": "api/commands/screenshot#take-a-screenshot",
      "doc_id": "api/commands/screenshot",
      "heading": "Take a screenshot",
      "heading_level": 4,
      "content_markdown": "#### Take a screenshot\n\n```\n// cypress/e2e/users.cy.jsdescribe('my tests', () => {  it('takes a screenshot', () => {    // screenshot will be saved as    // cypress/screenshots/users.cy.js/my tests -- takes a screenshot.png    cy.screenshot()  })})\n```\n",
      "section": "api",
      "anchors": [
        "take-a-screenshot"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 44
    },
    {
      "id": "api/commands/screenshot#filename",
      "doc_id": "api/commands/screenshot",
      "heading": "Filename",
      "heading_level": 3,
      "content_markdown": "### Filename\n\n#### Take a screenshot and save as a specific filename\n\n```\n// screenshot will be saved as// cypress/screenshots/spec.cy.js/clicking-on-nav.pngcy.screenshot('clicking-on-nav')\n```\n\n#### Take a screenshot and save in a specific directory\n\n```\n// screenshot will be saved as// cypress/screenshots/spec.cy.js/actions/login/clicking-login.pngcy.screenshot('actions/login/clicking-login')\n```\n",
      "section": "api",
      "anchors": [
        "filename"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 53
    },
    {
      "id": "api/commands/screenshot#clip",
      "doc_id": "api/commands/screenshot",
      "heading": "Clip",
      "heading_level": 3,
      "content_markdown": "### Clip\n\n#### Crop a screenshot to a specific position and size\n\n```\n// screenshot will be clipped 20px from the top and left// to the dimensions 400px x 300pxcy.screenshot({ clip: { x: 20, y: 20, width: 400, height: 300 } })\n```\n",
      "section": "api",
      "anchors": [
        "clip"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 57
    },
    {
      "id": "api/commands/screenshot#crop-a-screenshot-to-a-specific-position-and-size",
      "doc_id": "api/commands/screenshot",
      "heading": "Crop a screenshot to a specific position and size",
      "heading_level": 4,
      "content_markdown": "#### Crop a screenshot to a specific position and size\n\n```\n// screenshot will be clipped 20px from the top and left// to the dimensions 400px x 300pxcy.screenshot({ clip: { x: 20, y: 20, width: 400, height: 300 } })\n```\n",
      "section": "api",
      "anchors": [
        "crop-a-screenshot-to-a-specific-position-and-size"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 55
    },
    {
      "id": "api/commands/screenshot#screenshot-an-element",
      "doc_id": "api/commands/screenshot",
      "heading": "Screenshot an element",
      "heading_level": 3,
      "content_markdown": "### Screenshot an element\n\n#### Take a screenshot of the first `.post` element\n\n```\ncy.get('.post').first().screenshot()\n```\n\n#### Take a screenshot of the first `.post` element with 10px of padding around it\n\n```\ncy.get('.post').first().screenshot({ padding: 10 })\n```\n\n#### Chain off the screenshot to click the element captured\n\n```\ncy.get('button').first().screenshot().click()\n```\n",
      "section": "api",
      "anchors": [
        "screenshot-an-element"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 67
    },
    {
      "id": "api/commands/screenshot#get-screenshot-info-from-the-onafterscreenshot-callback",
      "doc_id": "api/commands/screenshot",
      "heading": "Get screenshot info from the onAfterScreenshot callback",
      "heading_level": 3,
      "content_markdown": "### Get screenshot info from the `onAfterScreenshot` callback\n\n```\ncy.screenshot('my-screenshot', {  onAfterScreenshot($el, props) {    // props has information about the screenshot,    // including but not limited to the following:    // {    //   name: 'my-screenshot',    //   path: '/Users/janelane/project/screenshots/spec.cy.js/my-screenshot.png',    //   size: '15 kb',    //   dimensions: {    //     width: 1000,    //     height: 660,    //   },    //   scaled: true,    //   blackout: [],    //   duration: 2300,    // }  },})\n```\n",
      "section": "api",
      "anchors": [
        "get-screenshot-info-from-the-onafterscreenshot-callback"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 87
    },
    {
      "id": "api/commands/screenshot#notes",
      "doc_id": "api/commands/screenshot",
      "heading": "Notes",
      "heading_level": 2,
      "content_markdown": "## Notes\n\n### Naming conventions\n\nScreenshot naming follows these rules:\n\n*   Screenshots are saved inside the [screenshots folder](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Asset-File-Paths). Inside that folder, the screenshot is saved inside a folder structure relative to the path of the spec file, which is adjusted to remove any common ancestor paths shared with all other spec files. Inside this folder, the screenshot will be saved with the test name: `{screenshotsFolder}/{adjustedSpecPath}/{testName}.png`\n*   For a named screenshot, the name is used instead of the suites and test name: `{screenshotsFolder}/{adjustedSpecPath}/{name}.png`\n*   For any duplicate screenshots (named or not), they will be appended with a number: `{screenshotsFolder}/{adjustedSpecPath}/{testName} (1).png`.\n\nThis behavior can be changed by passing the `{overwrite: true}` option to `cy.screenshot()` to explicitly overwrite duplicate screenshots.\n\n*   For a failure screenshot, the default naming scheme is used and the name is appended with `(failed)`:\n    \n    ```\n    {screenshotsFolder}/{adjustedSpecPath}/{testName} (failed).png\n    ```\n    \n\nFor example, given a spec file located at `cypress/e2e/users/login.cy.js`:\n\n```\ndescribe('my tests', () => {  it('takes a screenshot', () => {    // NOTE: This file has multiple screenshots    // each screenshot has a common ancestor path of `/users/`.    // In this scenario `/users/` is stripped from the path.    // cypress/screenshots/login.cy.js/my tests -- takes a screenshot.png    cy.screenshot()    // cypress/screenshots/login.cy.js/my tests -- takes a screenshot (1).png    cy.screenshot()    // cypress/screenshots/login.cy.js/my tests -- takes a screenshot (2).png    cy.screenshot()    // cypress/screenshots/login.cy.js/my-screenshot.png    cy.screenshot('my-screenshot')    // cypress/screenshots/login.cy.js/my-screenshot (1).png    cy.screenshot('my-screenshot')    // cypress/screenshots/login.cy.js/my/nested/screenshot.png    cy.screenshot('my/nested/screenshot')    // if this test fails, the screenshot will be saved to    // cypress/screenshots/login.cy.js/my tests -- takes a screenshot (failed).png  })})\n```\n\nTo learn more about how to write and organize tests and how assets are saved, see [Writing And Organizing Tests](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Asset-Files)\n\n### `after:screenshot` plugin event\n\nYou can get details about any given screenshot and manipulate it after it has been written to disk with the [`after:screenshot` plugin event](/llm/markdown/api/node-events/after-screenshot-api.md).\n\n### Test Failures\n\n#### Automatic screenshots on test failure\n\nWhen running through `cypress run` or in [Continuous Integration](/llm/markdown/app/continuous-integration/overview.md), Cypress automatically takes a screenshot when a test fails. You can optionally turn this off by setting `screenshotOnRunFailure` to `false` within your [`screenshotOnRunFailure`](/llm/markdown/app/references/configuration.md#Screenshots) or [Cypress.Screenshot.defaults()](/llm/markdown/api/cypress-api/screenshot-api.md).\n\n### Viewing Screenshots\n\n#### Screenshots in CI\n\nYou can see screenshots taken during a CI run in [Cypress Cloud](https://on.cypress.io/cloud) without any extra work.\n\nAlternatively, to see screenshots in your Continuous Integration UI, most CI providers document a way to export the screenshots as artifacts and to make them available. Please see their appropriate documentation.\n\n### Asynchronous\n\n#### Understanding when the screenshot is taken\n\nTaking a screenshot is an asynchronous action that takes around `100ms` to complete. By the time the screenshot is taken, _it is possible something in your application may have changed_. It is important to realize that the screenshot may not reflect what your application looked like 100% when the command was issued.\n\nFor example - say a command we wrote timed out: [`cy.get('#element')`](/llm/markdown/api/commands/get.md). This causes your test to fail. Cypress then automatically takes a screenshot when the test fails, but it is possible something in your application changed within this `100ms` timeframe. Hypothetically, your app could render the element you were originally expecting to be present. When this happens, the screenshot may provide confusing results. It is unlikely, but theoretically possible.\n\nAnother potential problem to be aware of is that our own Command Log is using React under the hood and only rendering asynchronously during an animation frame. It is possible you will see screenshots taken before our Command Log is done rendering. This means you may not see the **error displayed** in the screenshot. But this is also why we allow taking a video - to show you the complete failure.\n\nWe make our best effort to synchronize taking a screenshot with our renderer, but the current state of your application under test could have changed in the meantime and not be an accurate representation of what you want to capture.\n\n### Full page captures and fixed/sticky elements\n\nWhen passing `fullPage` to the `capture` option, Cypress scrolls the application under test from top to bottom, takes screenshots at each point and stitches them together. Due to this, elements that are `position: fixed` or `position: sticky` will appear multiple times in the final screenshot. To prevent this, in most cases you can programmatically change the element to be `position: absolute` before the screenshot and change it back afterwards like shown below:\n\n```\ncy.get('.sticky-header').invoke('css', 'position', 'absolute')cy.screenshot()cy.get('.sticky-header').invoke('css', 'position', null)\n```\n\n### Chromium-specific behavior with regard to tabs\n\nChromium will not capture screenshots when the renderer process for the Cypress tab is paused. This most often happens if a new tab was opened by clicking on an anchor with `target=\"_blank\"`. To accommodate capturing screenshots in this situation, Cypress will attempt to activate the Cypress tab when a screenshot is captured. We make our best effort to activate the tab via our Chromium extension. If the extension is disabled, Cypress will force the main tab to the front. This will cause the browser to steal focus in open mode. To prevent Cypress from stealing focus, [ensure that the extension is enabled](/llm/markdown/app/references/troubleshooting.md#Allow-the-Cypress-Chrome-extension).\n",
      "section": "api",
      "anchors": [
        "notes"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 1099
    },
    {
      "id": "api/commands/screenshot#naming-conventions",
      "doc_id": "api/commands/screenshot",
      "heading": "Naming conventions",
      "heading_level": 3,
      "content_markdown": "### Naming conventions\n\nScreenshot naming follows these rules:\n\n*   Screenshots are saved inside the [screenshots folder](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Asset-File-Paths). Inside that folder, the screenshot is saved inside a folder structure relative to the path of the spec file, which is adjusted to remove any common ancestor paths shared with all other spec files. Inside this folder, the screenshot will be saved with the test name: `{screenshotsFolder}/{adjustedSpecPath}/{testName}.png`\n*   For a named screenshot, the name is used instead of the suites and test name: `{screenshotsFolder}/{adjustedSpecPath}/{name}.png`\n*   For any duplicate screenshots (named or not), they will be appended with a number: `{screenshotsFolder}/{adjustedSpecPath}/{testName} (1).png`.\n\nThis behavior can be changed by passing the `{overwrite: true}` option to `cy.screenshot()` to explicitly overwrite duplicate screenshots.\n\n*   For a failure screenshot, the default naming scheme is used and the name is appended with `(failed)`:\n    \n    ```\n    {screenshotsFolder}/{adjustedSpecPath}/{testName} (failed).png\n    ```\n    \n\nFor example, given a spec file located at `cypress/e2e/users/login.cy.js`:\n\n```\ndescribe('my tests', () => {  it('takes a screenshot', () => {    // NOTE: This file has multiple screenshots    // each screenshot has a common ancestor path of `/users/`.    // In this scenario `/users/` is stripped from the path.    // cypress/screenshots/login.cy.js/my tests -- takes a screenshot.png    cy.screenshot()    // cypress/screenshots/login.cy.js/my tests -- takes a screenshot (1).png    cy.screenshot()    // cypress/screenshots/login.cy.js/my tests -- takes a screenshot (2).png    cy.screenshot()    // cypress/screenshots/login.cy.js/my-screenshot.png    cy.screenshot('my-screenshot')    // cypress/screenshots/login.cy.js/my-screenshot (1).png    cy.screenshot('my-screenshot')    // cypress/screenshots/login.cy.js/my/nested/screenshot.png    cy.screenshot('my/nested/screenshot')    // if this test fails, the screenshot will be saved to    // cypress/screenshots/login.cy.js/my tests -- takes a screenshot (failed).png  })})\n```\n\nTo learn more about how to write and organize tests and how assets are saved, see [Writing And Organizing Tests](/llm/markdown/app/core-concepts/writing-and-organizing-tests.md#Asset-Files)\n",
      "section": "api",
      "anchors": [
        "naming-conventions"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 349
    },
    {
      "id": "api/commands/screenshot#test-failures",
      "doc_id": "api/commands/screenshot",
      "heading": "Test Failures",
      "heading_level": 3,
      "content_markdown": "### Test Failures\n\n#### Automatic screenshots on test failure\n\nWhen running through `cypress run` or in [Continuous Integration](/llm/markdown/app/continuous-integration/overview.md), Cypress automatically takes a screenshot when a test fails. You can optionally turn this off by setting `screenshotOnRunFailure` to `false` within your [`screenshotOnRunFailure`](/llm/markdown/app/references/configuration.md#Screenshots) or [Cypress.Screenshot.defaults()](/llm/markdown/api/cypress-api/screenshot-api.md).\n",
      "section": "api",
      "anchors": [
        "test-failures"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 57
    },
    {
      "id": "api/commands/screenshot#automatic-screenshots-on-test-failure",
      "doc_id": "api/commands/screenshot",
      "heading": "Automatic screenshots on test failure",
      "heading_level": 4,
      "content_markdown": "#### Automatic screenshots on test failure\n\nWhen running through `cypress run` or in [Continuous Integration](/llm/markdown/app/continuous-integration/overview.md), Cypress automatically takes a screenshot when a test fails. You can optionally turn this off by setting `screenshotOnRunFailure` to `false` within your [`screenshotOnRunFailure`](/llm/markdown/app/references/configuration.md#Screenshots) or [Cypress.Screenshot.defaults()](/llm/markdown/api/cypress-api/screenshot-api.md).\n",
      "section": "api",
      "anchors": [
        "automatic-screenshots-on-test-failure"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 53
    },
    {
      "id": "api/commands/screenshot#viewing-screenshots",
      "doc_id": "api/commands/screenshot",
      "heading": "Viewing Screenshots",
      "heading_level": 3,
      "content_markdown": "### Viewing Screenshots\n\n#### Screenshots in CI\n\nYou can see screenshots taken during a CI run in [Cypress Cloud](https://on.cypress.io/cloud) without any extra work.\n\nAlternatively, to see screenshots in your Continuous Integration UI, most CI providers document a way to export the screenshots as artifacts and to make them available. Please see their appropriate documentation.\n",
      "section": "api",
      "anchors": [
        "viewing-screenshots"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 72
    },
    {
      "id": "api/commands/screenshot#screenshots-in-ci",
      "doc_id": "api/commands/screenshot",
      "heading": "Screenshots in CI",
      "heading_level": 4,
      "content_markdown": "#### Screenshots in CI\n\nYou can see screenshots taken during a CI run in [Cypress Cloud](https://on.cypress.io/cloud) without any extra work.\n\nAlternatively, to see screenshots in your Continuous Integration UI, most CI providers document a way to export the screenshots as artifacts and to make them available. Please see their appropriate documentation.\n",
      "section": "api",
      "anchors": [
        "screenshots-in-ci"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 68
    },
    {
      "id": "api/commands/screenshot#asynchronous",
      "doc_id": "api/commands/screenshot",
      "heading": "Asynchronous",
      "heading_level": 3,
      "content_markdown": "### Asynchronous\n\n#### Understanding when the screenshot is taken\n\nTaking a screenshot is an asynchronous action that takes around `100ms` to complete. By the time the screenshot is taken, _it is possible something in your application may have changed_. It is important to realize that the screenshot may not reflect what your application looked like 100% when the command was issued.\n\nFor example - say a command we wrote timed out: [`cy.get('#element')`](/llm/markdown/api/commands/get.md). This causes your test to fail. Cypress then automatically takes a screenshot when the test fails, but it is possible something in your application changed within this `100ms` timeframe. Hypothetically, your app could render the element you were originally expecting to be present. When this happens, the screenshot may provide confusing results. It is unlikely, but theoretically possible.\n\nAnother potential problem to be aware of is that our own Command Log is using React under the hood and only rendering asynchronously during an animation frame. It is possible you will see screenshots taken before our Command Log is done rendering. This means you may not see the **error displayed** in the screenshot. But this is also why we allow taking a video - to show you the complete failure.\n\nWe make our best effort to synchronize taking a screenshot with our renderer, but the current state of your application under test could have changed in the meantime and not be an accurate representation of what you want to capture.\n",
      "section": "api",
      "anchors": [
        "asynchronous"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 321
    },
    {
      "id": "api/commands/screenshot#understanding-when-the-screenshot-is-taken",
      "doc_id": "api/commands/screenshot",
      "heading": "Understanding when the screenshot is taken",
      "heading_level": 4,
      "content_markdown": "#### Understanding when the screenshot is taken\n\nTaking a screenshot is an asynchronous action that takes around `100ms` to complete. By the time the screenshot is taken, _it is possible something in your application may have changed_. It is important to realize that the screenshot may not reflect what your application looked like 100% when the command was issued.\n\nFor example - say a command we wrote timed out: [`cy.get('#element')`](/llm/markdown/api/commands/get.md). This causes your test to fail. Cypress then automatically takes a screenshot when the test fails, but it is possible something in your application changed within this `100ms` timeframe. Hypothetically, your app could render the element you were originally expecting to be present. When this happens, the screenshot may provide confusing results. It is unlikely, but theoretically possible.\n\nAnother potential problem to be aware of is that our own Command Log is using React under the hood and only rendering asynchronously during an animation frame. It is possible you will see screenshots taken before our Command Log is done rendering. This means you may not see the **error displayed** in the screenshot. But this is also why we allow taking a video - to show you the complete failure.\n\nWe make our best effort to synchronize taking a screenshot with our renderer, but the current state of your application under test could have changed in the meantime and not be an accurate representation of what you want to capture.\n",
      "section": "api",
      "anchors": [
        "understanding-when-the-screenshot-is-taken"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 319
    },
    {
      "id": "api/commands/screenshot#full-page-captures-and-fixed-sticky-elements",
      "doc_id": "api/commands/screenshot",
      "heading": "Full page captures and fixed/sticky elements",
      "heading_level": 3,
      "content_markdown": "### Full page captures and fixed/sticky elements\n\nWhen passing `fullPage` to the `capture` option, Cypress scrolls the application under test from top to bottom, takes screenshots at each point and stitches them together. Due to this, elements that are `position: fixed` or `position: sticky` will appear multiple times in the final screenshot. To prevent this, in most cases you can programmatically change the element to be `position: absolute` before the screenshot and change it back afterwards like shown below:\n\n```\ncy.get('.sticky-header').invoke('css', 'position', 'absolute')cy.screenshot()cy.get('.sticky-header').invoke('css', 'position', null)\n```\n",
      "section": "api",
      "anchors": [
        "full-page-captures-and-fixed-sticky-elements"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 115
    },
    {
      "id": "api/commands/screenshot#chromium-specific-behavior-with-regard-to-tabs",
      "doc_id": "api/commands/screenshot",
      "heading": "Chromium-specific behavior with regard to tabs",
      "heading_level": 3,
      "content_markdown": "### Chromium-specific behavior with regard to tabs\n\nChromium will not capture screenshots when the renderer process for the Cypress tab is paused. This most often happens if a new tab was opened by clicking on an anchor with `target=\"_blank\"`. To accommodate capturing screenshots in this situation, Cypress will attempt to activate the Cypress tab when a screenshot is captured. We make our best effort to activate the tab via our Chromium extension. If the extension is disabled, Cypress will force the main tab to the front. This will cause the browser to steal focus in open mode. To prevent Cypress from stealing focus, [ensure that the extension is enabled](/llm/markdown/app/references/troubleshooting.md#Allow-the-Cypress-Chrome-extension).\n",
      "section": "api",
      "anchors": [
        "chromium-specific-behavior-with-regard-to-tabs"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 145
    },
    {
      "id": "api/commands/screenshot#rules",
      "doc_id": "api/commands/screenshot",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `cy.screenshot()` can be chained off of `cy` or off a command that yields a single DOM element.\n\n### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)\n\n*   `cy.screenshot()` will only run assertions you have chained once, and will not [retry](/llm/markdown/app/core-concepts/retry-ability.md).\n\n### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `cy.screenshot()` should never time out.\n\nBecause `cy.screenshot()` is asynchronous it is technically possible for there to be a timeout while talking to the internal Cypress automation APIs. But for practical purposes it should never happen.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 115
    },
    {
      "id": "api/commands/screenshot#timeouts-learn-about-timeouts",
      "doc_id": "api/commands/screenshot",
      "heading": "Timeouts Learn about timeouts",
      "heading_level": 3,
      "content_markdown": "### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `cy.screenshot()` should never time out.\n\nBecause `cy.screenshot()` is asynchronous it is technically possible for there to be a timeout while talking to the internal Cypress automation APIs. But for practical purposes it should never happen.\n",
      "section": "api",
      "anchors": [
        "timeouts-learn-about-timeouts"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 55
    },
    {
      "id": "api/commands/screenshot#command-log",
      "doc_id": "api/commands/screenshot",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Take a screenshot with a specific filename_**\n\n```\ncy.screenshot('my-image')\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on `screenshot` within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/screenshot.json",
      "token_estimate": 48
    }
  ]
}