PageSourceSearch

https://playwright.dev/assets/js/a0c59349.b232f77d.js

js playwright.dev collected 2026-09-24 06:54:31 UTC 15,886 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["2310"],{23232(e,t,s){s.r(t),s.d(t,{metadata:()=>n,default:()=>h,frontMatter:()=>r,contentTitle:()=>o,toc:()=>c,assets:()=>l});var n=JSON.parse('{"id":"api/class-teststepinfo","title":"TestStepInfo","description":"TestStepInfo contains information about currently running test step. It is passed as an argument to the step function. TestStepInfo provides utilities to control test step execution.","source":"@site/versioned_docs/version-stable/api/class-teststepinfo.mdx","sourceDirName":"api","slug":"/api/class-teststepinfo","permalink":"/docs/api/class-teststepinfo","draft":false,"unlisted":false,"tags":[],"version":"stable","frontMatter":{"id":"class-teststepinfo","title":"TestStepInfo"},"sidebar":"api","previous":{"title":"TestProject","permalink":"/docs/api/class-testproject"},"next":{"title":"WorkerInfo","permalink":"/docs/api/class-workerinfo"}}'),i=s(74848),a=s(28453);s(13554),s(41647),s(83137);let r={id:"class-teststepinfo",title:"TestStepInfo"},o,l={},c=[{value:"Methods",id:"methods",level:2},{value:"attach",id:"test-step-info-attach",level:3},{value:"skip()",id:"test-step-info-skip-1",level:3},{value:"skip(condition)",id:"test-step-info-skip-2",level:3},{value:"Properties",id:"properties",level:2},{value:"annotations",id:"test-step-info-annotations",level:3},{value:"titlePath",id:"test-step-info-title-path",level:3}];function p(e){let t={a:"a",admonition:"admonition",code:"code",em:"em",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"TestStepInfo"})," contains information about currently running test step. It is passed as an argument to the step function. ",(0,i.jsx)(t.code,{children:"TestStepInfo"})," provides utilities to control test step execution."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"import { test, expect } from '@playwright/test';\n\ntest('basic test', async ({ page, browserName }) => {\n  await test.step('check some behavior', async step => {\n    step.skip(browserName === 'webkit', 'The feature is not available in WebKit');\n    // ... rest of the step code\n  });\n});\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h2,{id:"methods",children:"Methods"}),"\n",(0,i.jsx)(t.h3,{id:"test-step-info-attach",children:"attach"}),"\n",(0,i.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.51"}),"\n",(0,i.jsx)("x-search",{children:"testStepInfo.attach"}),"\n",(0,i.jsxs)(t.p,{children:["Attach a value or a file from disk to the current test step. Some reporters show test step attachments. Either ",(0,i.jsx)(t.a,{href:"/docs/api/class-teststepinfo#test-step-info-attach-option-path",children:"path"})," or ",(0,i.jsx)(t.a,{href:"/docs/api/class-teststepinfo#test-step-info-attach-option-body",children:"body"})," must be specified, but not both. Calling this method will attribute the attachment to the step, as opposed to ",(0,i.jsx)(t.a,{href:"/docs/api/class-testinfo#test-info-attach",children:"testInfo.attach()"})," which stores all attachments at the test level."]}),"\n",(0,i.jsx)(t.p,{children:"For example, you can attach a screenshot to the test step:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"import { test, expect } from '@playwright/test';\n\ntest('basic test', async ({ page }) => {\n  await page.goto('https://playwright.dev');\n  await test.step('check page rendering', async step => {\n    const screenshot = await page.screenshot();\n    await step.attach('screenshot', { body: screenshot, contentType: 'image/png' });\n  });\n});\n"})}),"\n",(0,i.jsx)(t.p,{children:"Or you can attach files returned by your APIs:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"import { test, expect } from '@playwright/test';\nimport { download } from './my-custom-helpers';\n\ntest('basic test', async ({}) =>
1 {\n  await test.step('check download behavior', async step => {\n    const tmpPath = await download('a');\n    await step.attach('downloaded', { path: tmpPath });\n  });\n});\n"})}),"\n",(0,i.jsx)(t.admonition,{type:"note",children:(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.a,{href:"/docs/api/class-teststepinfo#test-step-info-attach",children:"testStepInfo.attach()"})," automatically takes care of copying attached files to a location that is accessible to reporters. You can safely remove the attachment after awaiting the attach call."]})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Usage"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"await testStepInfo.attach(name);\nawait testStepInfo.attach(name, options);\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Arguments"})}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"name"})," ",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,i.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"test-step-info-attach-option-name"}),(0,i.jsx)("a",{href:"#test-step-info-attach-option-name",class:"list-anchor",children:"#"})]}),"\n",(0,i.jsx)(t.p,{children:"Attachment name. The name will also be sanitized and used as the prefix of file name when saving to disk."}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"options"})," ",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"})," ",(0,i.jsx)(t.em,{children:"(optional)"})]}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"body"})," ",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," | ",(0,i.jsx)(t.a,{href:"https://nodejs.org/api/buffer.html#buffer_class_buffer",title:"Buffer",children:"Buffer"})," ",(0,i.jsx)(t.em,{children:"(optional)"}),(0,i.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"test-step-info-attach-option-body"}),(0,i.jsx)("a",{href:"#test-step-info-attach-option-body",class:"list-anchor",children:"#"})]}),"\n",(0,i.jsxs)(t.p,{children:["Attachment body. Mutually exclusive with ",(0,i.jsx)(t.a,{href:"/docs/api/class-teststepinfo#test-step-info-attach-option-path",children:"path"}),"."]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"contentType"})," ",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,i.jsx)(t.em,{children:"(optional)"}),(0,i.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"test-step-info-attach-option-content-type"}),(0,i.jsx)("a",{href:"#test-step-info-attach-option-content-type",class:"list-anchor",children:"#"})]}),"\n",(0,i.jsxs)(t.p,{children:["Content type of this attachment to properly present in the report, for example ",(0,i.jsx)(t.code,{children:"'application/json'"})," or ",(0,i.jsx)(t.code,{children:"'image/png'"}),". If omitted, content type is inferred based on the ",(0,i.jsx)(t.a,{href:"/docs/api/class-teststepinfo#test-step-info-attach-option-path",children:"path"}),", or defaults to ",(0,i.jsx)(t.code,{children:"text/plain"})," for ",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," attachments and ",(0,i.jsx)(t.code,{children:"application/octet-stream"})," for ",(0,i.jsx)(t.a,{href:"https://nodejs.org/api/buffer.html#buffer_class_buffer",title:"Buffer",children:"Buffer"})," attachments."]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"path"})," ",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,i.jsx)(t.em,{children:"(optional)"}),(0,i.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"test-step-info-attach-option-path"}),(0,i.jsx)("a",{href:"#test-step-info-attach-option-path",class:"list-anchor",children:"#"})]}),"\n",(0,i.jsxs)(t.p,{children:["Path on the filesystem to the attached file. Mutually exclusive with ",(0,i.jsx)(t.a,{href:"/docs/api/class-teststepinfo#test-step-info-attach-option-body",children:"body"}),"."]}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Returns"})}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,i.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"test-step-info-attach-return"}),(0,i.jsx)("a",{href:"#test-step-info-attach-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h3,{id:"test-step-info-skip-1",children:"skip()"}),"\n",(0,i.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.51"}),"\n",(0,i.jsx)("x-search",{children:"testStepInfo.skip()"}),"\n",(0,i.jsx)(t.p,{children:"Abort the currently running step and mark it as skipped. Useful for steps that are currently failing and planned for a near-term fix."}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Usage"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"import { test, expect } from '@playwright/test';\n\ntest('my test', async ({ page }) =>
1 {\n  await test.step('check expectations', async step => {\n    step.skip();\n    // step body below will not run\n    // ...\n  });\n});\n"})}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h3,{id:"test-step-info-skip-2",children:"skip(condition)"}),"\n",(0,i.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.51"}),"\n",(0,i.jsx)("x-search",{children:"testStepInfo.skip(condition)"}),"\n",(0,i.jsx)(t.p,{children:"Conditionally abort the currently running step and mark it as skipped with an optional description. Useful for steps that should not be executed in some cases."}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Usage"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"import { test, expect } from '@playwright/test';\n\ntest('my test', async ({ page, isMobile }) => {\n  await test.step('check desktop expectations', async step => {\n    step.skip(isMobile, 'not present in the mobile layout');\n    // step body below will not run\n    // ...\n  });\n});\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Arguments"})}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"condition"})," ",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type",title:"Boolean",children:"boolean"}),(0,i.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"test-step-info-skip-2-option-condition"}),(0,i.jsx)("a",{href:"#test-step-info-skip-2-option-condition",class:"list-anchor",children:"#"})]}),"\n",(0,i.jsxs)(t.p,{children:["A skip condition. Test step is skipped when the condition is ",(0,i.jsx)(t.code,{children:"true"}),"."]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"description"})," ",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,i.jsx)(t.em,{children:"(optional)"}),(0,i.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"test-step-info-skip-2-option-description"}),(0,i.jsx)("a",{href:"#test-step-info-skip-2-option-description",class:"list-anchor",children:"#"})]}),"\n",(0,i.jsx)(t.p,{children:"Optional description that will be reflected in a test report."}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h2,{id:"properties",children:"Properties"}),"\n",(0,i.jsx)(t.h3,{id:"test-step-info-annotations",children:"annotations"}),"\n",(0,i.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.58"}),"\n",(0,i.jsx)("x-search",{children:"testStepInfo.annotations"}),"\n",(0,i.jsx)(t.p,{children:"The list of annotations applicable to the current test step."}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Usage"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"testStepInfo.annotations\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Type"})}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array",title:"Array",children:"Array"}),"<",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"}),">","\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"type"})," ",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})]}),"\n",(0,i.jsxs)(t.p,{children:["Annotation type, for example ",(0,i.jsx)(t.code,{children:"'skip'"}),"."]}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"description"})," ",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})," ",(0,i.jsx)(t.em,{children:"(optional)"})]}),"\n",(0,i.jsx)(t.p,{children:"Optional description."}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.code,{children:"location"})," ",(0,i.jsx)(t.a,{href:"/docs/api/class-location",title:"Location",children:"Location"})," ",(0,i.jsx)(t.em,{children:"(optional)"})]}),"\n",(0,i.jsx)(t.p,{children:"Optional location in the source where the annotation is added."}),"\n"]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(t.hr,{}),"\n",(0,i.jsx)(t.h3,{id:"test-step-info-title-path",children:"titlePath"}),"\n",(0,i.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.55"}),"\n",(0,i.jsx)("x-search",{children:"testStepInfo.titlePath"}),"\n",(0,i.jsxs)(t.p,{children:["The full title path starting with the test file name, including the step titles. See also ",(0,i.jsx)(t.a,{href:"/docs/api/class-testinfo#test-info-title-path",children:"testInfo.titlePath"}),"."]}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Usage"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"testStepInfo.titlePath\n"})}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.strong,{children:"Type"})}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array",title:"Array",children:"Array"}),"<",(0,i.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),">"]}),"\n"]})]})}function h(e={}){let{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(p,{...e})}):p(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.