1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["3227"],{17044(e,t,n){n.r(t),n.d(t,{metadata:()=>s,default:()=>h,frontMatter:()=>r,contentTitle:()=>o,toc:()=>c,assets:()=>d});var s=JSON.parse('{"id":"test-use-options","title":"Configuration (use)","description":"Introduction","source":"@site/docs/test-use-options.mdx","sourceDirName":".","slug":"/test-use-options","permalink":"/docs/next/test-use-options","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"id":"test-use-options","title":"Configuration (use)"},"sidebar":"docs","previous":{"title":"Configuration","permalink":"/docs/next/test-configuration"},"next":{"title":"Emulation","permalink":"/docs/next/emulation"}}'),i=n(74848),l=n(28453);n(13554),n(41647),n(83137);let r={id:"test-use-options",title:"Configuration (use)"},o,d={},c=[{value:"Introduction",id:"introduction",level:2},{value:"Basic Options",id:"basic-options",level:3},{value:"Emulation Options",id:"emulation-options",level:3},{value:"Network Options",id:"network-options",level:3},{value:"Recording Options",id:"recording-options",level:3},{value:"Trace modes",id:"trace-modes",level:4},{value:"Video modes",id:"video-modes",level:4},{value:"Other Options",id:"other-options",level:3},{value:"More browser and context options",id:"more-browser-and-context-options",level:3},{value:"Explicit Context Creation and Option Inheritance",id:"explicit-context-creation-and-option-inheritance",level:3},{value:"Configuration Scopes",id:"configuration-scopes",level:3},{value:"Reset an option",id:"reset-an-option",level:3}];function a(e){let t={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",h4:"h4",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,l.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h2,{id:"introduction",children:"Introduction"}),"\n",(0,i.jsxs)(t.p,{children:["In addition to configuring the test runner you can also configure ",(0,i.jsx)(t.a,{href:"#emulation-options",children:"Emulation"}),", ",(0,i.jsx)(t.a,{href:"#network-options",children:"Network"})," and ",(0,i.jsx)(t.a,{href:"#recording-options",children:"Recording"})," for the ",(0,i.jsx)(t.a,{href:"/docs/next/api/class-browser",title:"Browser",children:"Browser"})," or ",(0,i.jsx)(t.a,{href:"/docs/next/api/class-browsercontext",title:"BrowserContext",children:"BrowserContext"}),". These options are passed to the ",(0,i.jsx)(t.code,{children:"use: {}"})," object in the Playwright config."]}),"\n",(0,i.jsx)(t.h3,{id:"basic-options",children:"Basic Options"}),"\n",(0,i.jsx)(t.p,{children:"Set the base URL and storage state for all tests:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="playwright.config.ts"',children:"import { defineConfig } from '@playwright/test';\n\nexport default defineConfig({\n use: {\n // Base URL to use in actions like `await page.goto('/')`.\n baseURL: 'http://localhost:3000',\n\n // Populates context with given storage state.\n storageState: 'state.json',\n },\n});\n"})}),"\n",(0,i.jsxs)(t.table,{children:[(0,i.jsx)(t.thead,{children:(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Option"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Description"})]})}),(0,i.jsxs)(t.tbody,{children:[(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-base-url",children:"testOptions.baseURL"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Base URL used for all pages in the context. Allows navigating by using just the path, for example ",(0,i.jsx)(t.code,{children:"page.goto('/settings')"}),"."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-storage-state",children:"testOptions.storageState"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Populates context with given storage state. Useful for easy authentication, ",(0,i.jsx)(t.a,{href:"/docs/next/auth",children:"learn more"}),"."]})]})]})]}),"\n",(0,i.jsx)(t.h3,{id:"emulation-options",children:"Emulation Options"}),"\n",(0,i.jsxs)(t.p,{children:["With Playwright you can emulate a real device such as a mobile phone or tablet. See our ",(0,i.jsx)(t.a,{href:"/docs/next/test-projects",children:"guide on projects"})," for more info on emulating devices. You can also emulate the ",(0,i.jsx)(t.code,{children:'"geolocation"'}),", ",(0,i.jsx)(t.code,{children:'"locale"'})," and ",(0,i.jsx)(t.code,{children:'"timezone"'})," for all tests or for a specific test as well as set the ",(0,i.jsx)(t.code,{children:'"permissions"'})," to show notifications or change the ",(0,i.jsx)(t.code,{children:'"colorScheme"'}),". See our ",(0,i.jsx)(t.a,{href:"/docs/next/emulation",children:"Emulation"})," guide to learn more."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="playwright.config.ts"',children:"import { defineConfig } from '@playwright/test';
1\n\nexport default defineConfig({\n use: {\n // Emulates `'prefers-colors-scheme'` media feature.\n colorScheme: 'dark',\n\n // Context geolocation.\n geolocation: { longitude: 12.492507, latitude: 41.889938 },\n\n // Emulates the user locale.\n locale: 'en-GB',\n\n // Grants specified permissions to the browser context.\n permissions: ['geolocation'],\n\n // Emulates the user timezone.\n timezoneId: 'Europe/Paris',\n\n // Viewport used for all pages in the context.\n viewport: { width: 1280, height: 720 },\n },\n});\n"})}),"\n",(0,i.jsxs)(t.table,{children:[(0,i.jsx)(t.thead,{children:(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Option"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Description"})]})}),(0,i.jsxs)(t.tbody,{children:[(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-color-scheme",children:"testOptions.colorScheme"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:[(0,i.jsx)(t.a,{href:"/docs/next/emulation#color-scheme-and-media",children:"Emulates"})," ",(0,i.jsx)(t.code,{children:"'prefers-colors-scheme'"})," media feature, supported values are ",(0,i.jsx)(t.code,{children:"'light'"})," and ",(0,i.jsx)(t.code,{children:"'dark'"})]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-geolocation",children:"testOptions.geolocation"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Context ",(0,i.jsx)(t.a,{href:"/docs/next/emulation#geolocation",children:"geolocation"}),"."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-locale",children:"testOptions.locale"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:[(0,i.jsx)(t.a,{href:"/docs/next/emulation#locale--timezone",children:"Emulates"})," the user locale, for example ",(0,i.jsx)(t.code,{children:"en-GB"}),", ",(0,i.jsx)(t.code,{children:"de-DE"}),", etc."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-permissions",children:"testOptions.permissions"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["A list of ",(0,i.jsx)(t.a,{href:"/docs/next/emulation#permissions",children:"permissions"})," to grant to all pages in the context."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-timezone-id",children:"testOptions.timezoneId"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Changes the ",(0,i.jsx)(t.a,{href:"/docs/next/emulation#locale--timezone",children:"timezone"})," of the context."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-viewport",children:"testOptions.viewport"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:[(0,i.jsx)(t.a,{href:"/docs/next/emulation#viewport",children:"Viewport"})," used for all pages in the context."]})]})]})]}),"\n",(0,i.jsx)(t.h3,{id:"network-options",children:"Network Options"}),"\n",(0,i.jsx)(t.p,{children:"Available options to configure networking:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="playwright.config.ts"',children:"import { defineConfig } from '@playwright/test';\n\nexport default defineConfig({\n use: {\n // Whether to automatically download all the attachments.\n acceptDownloads: false,\n\n // An object containing additional HTTP headers to be sent with every request.\n extraHTTPHeaders: {\n 'X-My-Header': 'value',\n },\n\n // Credentials for HTTP authentication.\n httpCredentials: {\n username: 'user',\n password: 'pass',\n },\n\n // Whether to ignore HTTPS errors during navigation.\n ignoreHTTPSErrors: true,\n\n // Whether to emulate network being offline.\n offline: true,\n\n // Proxy settings used for all pages in the test.\n proxy: {\n server: 'http://myproxy.com:3128',\n bypass: 'localhost',\n },\n },\n});\n"})}),"\n",(0,i.jsxs)(t.table,{children:[(0,i.jsx)(t.thead,{children:(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Option"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Description"})]})}),(0,i.jsxs)(t.tbody,{children:[(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-accept-downloads",children:"testOptions.acceptDownloads"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Whether to automatically download all the attachments, defaults to ",(0,i.jsx)(t.code,{children:"true"}),". ",(0,i.jsx)(t.a,{href:"/docs/next/downloads",children:"Learn more"})," about working with downloads."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-extra-http-headers",children:"testOptions.extraHTTPHeaders"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"}
1,children:"An object containing additional HTTP headers to be sent with every request. All header values must be strings."})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-http-credentials",children:"testOptions.httpCredentials"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Credentials for ",(0,i.jsx)(t.a,{href:"/docs/next/network#http-authentication",children:"HTTP authentication"}),"."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-ignore-https-errors",children:"testOptions.ignoreHTTPSErrors"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"Whether to ignore HTTPS errors during navigation."})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-offline",children:"testOptions.offline"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"Whether to emulate network being offline."})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-proxy",children:"testOptions.proxy"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:[(0,i.jsx)(t.a,{href:"/docs/next/network#http-proxy",children:"Proxy settings"})," used for all pages in the test."]})]})]})]}),"\n",(0,i.jsx)(t.admonition,{type:"note",children:(0,i.jsxs)(t.p,{children:["You don't have to configure anything to mock network requests. Just define a custom ",(0,i.jsx)(t.a,{href:"/docs/next/api/class-route",title:"Route",children:"Route"})," that mocks the network for a browser context. See our ",(0,i.jsx)(t.a,{href:"/docs/next/network",children:"network mocking guide"})," to learn more."]})}),"\n",(0,i.jsx)(t.h3,{id:"recording-options",children:"Recording Options"}),"\n",(0,i.jsxs)(t.p,{children:["With Playwright you can capture screenshots, record videos as well as traces of your test. By default these are turned off but you can enable them by setting the ",(0,i.jsx)(t.code,{children:"screenshot"}),", ",(0,i.jsx)(t.code,{children:"video"})," and ",(0,i.jsx)(t.code,{children:"trace"})," options in your ",(0,i.jsx)(t.code,{children:"playwright.config.js"})," file."]}),"\n",(0,i.jsxs)(t.p,{children:["Trace files, screenshots and videos will appear in the test output directory, typically ",(0,i.jsx)(t.code,{children:"test-results"}),"."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="playwright.config.ts"',children:"import { defineConfig } from '@playwright/test';\n\nexport default defineConfig({\n use: {\n // Capture screenshot after each test failure.\n screenshot: 'only-on-failure',\n\n // Record trace only when retrying a test for the first time.\n trace: 'on-first-retry',\n\n // Record video only when retrying a test for the first time.\n video: 'on-first-retry'\n },\n});\n"})}),"\n",(0,i.jsxs)(t.table,{children:[(0,i.jsx)(t.thead,{children:(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Option"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Description"})]})}),(0,i.jsxs)(t.tbody,{children:[(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-screenshot",children:"testOptions.screenshot"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Capture ",(0,i.jsx)(t.a,{href:"/docs/next/screenshots",children:"screenshots"})," of your test. Options include ",(0,i.jsx)(t.code,{children:"'off'"}),", ",(0,i.jsx)(t.code,{children:"'on'"})," and ",(0,i.jsx)(t.code,{children:"'only-on-failure'"})]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-trace",children:"testOptions.trace"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Playwright can produce test traces while running the tests. Later on, you can view the trace and get detailed information about Playwright execution by opening ",(0,i.jsx)(t.a,{href:"/docs/next/trace-viewer",children:"Trace Viewer"}),". Options include: ",(0,i.jsx)(t.code,{children:"'off'"}),", ",(0,i.jsx)(t.code,{children:"'on'"}),", ",(0,i.jsx)(t.code,{children:"'retain-on-failure'"})," and ",(0,i.jsx)(t.code,{children:"'on-first-retry'"})]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-video",children:"testOptions.video"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Playwright can record ",(0,i.jsx)(t.a,{href:"/docs/next/videos",children:"videos"})," for your tests. Options include: ",(0,i.jsx)(t.code,{children:"'off'"}),", ",(0,i.jsx)(t.code,{children:"'on'"}),", ",(0,i.jsx)(t.code,{children:"'retain-on-failure'"})," and ",(0,i.jsx)(t.code,{children:"'on-first-retry'"})]})]})]})]}),"\n",(0,i.jsx)(t.h4,{id:"trace-modes",children:"Trace modes"}),"\n",(0,i.jsxs)(t.p,{children:["The ",(0,i.jsx)(t.code,{children:"trace"})," option supports several modes that differ in ",(0,i.jsx)(t.strong,{children:"which runs are recorded"})," and ",(0,i.jsx)(t.strong,{children:"which recordings are kept"}),' after the test finishes. The initial run of a test is the "first run"; subsequent runs caused by ',(0,i.jsx)(t.a,{href:"/docs/next/test-retries",children:"retries"}),' are "retries".']}),"\n",(0,i.jsxs)(t.table,{children:[(0,i.jsx)(t.thead,{children:(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Mode"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Records a trace on"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Keeps the trace when"})]})}),(0,i.jsxs)(t.tbody,{children:[(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'off'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"never"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"every run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"always"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-failure'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"every run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"that run failed"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-first-failure'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run only"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"the first run failed"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-failure-and-retries'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"every run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"that run failed, or it is a retry"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on-first-retry'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first retry only"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"always"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on-all-retries'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"every retry"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"always"})]})]})]}),"\n",(0,i.jsxs)(t.p,{children:["The following table shows which traces are kept in a few common sce
1narios, assuming ",(0,i.jsx)(t.code,{children:"retries: 2"})," is configured:"]}),"\n",(0,i.jsxs)(t.table,{children:[(0,i.jsx)(t.thead,{children:(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Mode"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Passes on first run"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Fails, then passes on retry"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Fails on every run"})]})}),(0,i.jsxs)(t.tbody,{children:[(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'off'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run + retry"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"all three runs"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-failure'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"all three runs"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-first-failure'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-failure-and-retries'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run + retry"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"all three runs"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on-first-retry'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first retry"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first retry"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on-all-retries'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first retry"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"both retries"})]})]})]}),"\n",(0,i.jsx)(t.h4,{id:"video-modes",children:"Video modes"}),"\n",(0,i.jsxs)(t.p,{children:["The ",(0,i.jsx)(t.code,{children:"video"})," option supports the same set of modes as ",(0,i.jsx)(t.code,{children:"trace"}),", and they record and keep recordings using the same rules."]}),"\n",(0,i.jsxs)(t.table,{children:[(0,i.jsx)(t.thead,{children:(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Mode"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Records a video on"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Keeps the video when"})]})}),(0,i.jsxs)(t.tbody,{children:[(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'off'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"never"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"every run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"always"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-failure'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"every run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"that run failed"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-first-failure'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run only"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"the first run failed"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-failure-and-retries'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"every run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"that run failed, or it is a retry"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on-first-retry'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first retry only"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"always"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on-all-retries'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"every retry"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"always"})]})]})]}),"\n",(0,i.jsxs)(t.p,{children:["The following table shows which videos are kept in a few common sce
1narios, assuming ",(0,i.jsx)(t.code,{children:"retries: 2"})," is configured:"]}),"\n",(0,i.jsxs)(t.table,{children:[(0,i.jsx)(t.thead,{children:(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Mode"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Passes on first run"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Fails, then passes on retry"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Fails on every run"})]})}),(0,i.jsxs)(t.tbody,{children:[(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'off'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run + retry"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"all three runs"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-failure'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"all three runs"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-first-failure'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'retain-on-failure-and-retries'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first run + retry"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"all three runs"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on-first-retry'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first retry"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first retry"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.code,{children:"'on-all-retries'"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"\u2014"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"first retry"}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"both retries"})]})]})]}),"\n",(0,i.jsx)(t.h3,{id:"other-options",children:"Other Options"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="playwright.config.ts"',children:"import { defineConfig } from '@playwright/test';\n\nexport default defineConfig({\n use: {\n // Maximum time each action such as `click()` can take. Defaults to 0 (no limit).\n actionTimeout: 0,\n\n // Name of the browser that runs tests. For example `chromium`, `firefox`, `webkit`.\n browserName: 'chromium',\n\n // Toggles bypassing Content-Security-Policy.\n bypassCSP: true,\n\n // Channel to use, for example \"chrome\", \"chrome-beta\", \"msedge\", \"msedge-beta\".\n channel: 'chrome',\n\n // Run browser in headless mode.\n headless: false,\n\n // Change the default data-testid attribute.\n testIdAttribute: 'pw-test-id',\n },\n});\n"})}),"\n",(0,i.jsxs)(t.table,{children:[(0,i.jsx)(t.thead,{children:(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Option"}),(0,i.jsx)(t.th,{style:{textAlign:"left"},children:"Description"})]})}),(0,i.jsxs)(t.tbody,{children:[(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-action-timeout",children:"testOptions.actionTimeout"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Timeout for each Playwright action in milliseconds. Defaults to ",(0,i.jsx)(t.code,{children:"0"})," (no timeout). Learn more about ",(0,i.jsx)(t.a,{href:"/docs/next/test-timeouts",children:"timeouts"})," and how to set them for a single test."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-browser-name",children:"testOptions.browserName"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Name of the browser that runs tests. Defaults to 'chromium'. Options include ",(0,i.jsx)(t.code,{children:"chromium"}),", ",(0,i.jsx)(t.code,{children:"firefox"}),", or ",(0,i.jsx)(t.code,{children:"webkit"}),"."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-bypass-csp",children:"testOptions.bypassCSP"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Toggles bypassing Content-Security-Policy. Useful when CSP includes the production origin. Defaults to ",(0,i.jsx)(t.code,{children:"false"}),"."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-channel",children:"testOptions.channel"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Browser channel to use. ",(0,i.jsx)(t.a,{href:"/docs/next/browsers",children:"Learn more"})," about different browsers and channels."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-headless",children:"testOptions.headless"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Whether to run the browser in headless mode meaning no browser is shown when running tests. Defaults to ",(0,i.jsx)(t.code,{children:"true"}),"."]})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"left"},children:(0,i.jsx)(t.a,{href:"/docs/next/api/class-testoptions#test-options-test-id-attribute",children:"testOptions.testIdAttribute"})}),(0,i.jsxs)(t.td,{style:{textAlign:"left"},children:["Changes the default ",(0,i.jsxs)(t.a,{href:"/docs/next/locators#locate-by-test-id",children:[(0,i.jsx)(t.code,{children:"data-testid"})," attribute"]})," used by Playwright locators."]})]})]})]}),"\n",(0,i.jsx)(t.h3,{id:"more-browser-and-context-options",children:"More browser and context options"}),"\n",(0,i.jsxs)(t.p,{children:["Any options accepted by ",(0,i.jsx)(t.a,{href:"/docs/next/api/class-browsertype#browser-type-launch",children:"browserType.launch()"}),", ",(0,i.jsx)(t.a,{href:"/docs/next/api/class-browser#browser-new-context",children:"browser.newContext()"})," or ",(0,i.jsx)(t.a,{href:"/docs/next/api/class-browsertype#browser-type-connect",children:"browserType.connect()"})," can be put into ",(0,i.jsx)(t.code,{children:"launchOptions"}),", ",(0,i.jsx)(t.code,{children:"contextOptions"})," or ",(0,i.jsx)(t.code,{children:"connectOptions"})," respectively in the ",(0,i.jsx)(t.code,{children:"use"})," section."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="playwright.config.ts"',children:"import { defineConfig } from '@playwright/test';
1\n\nexport default defineConfig({\n use: {\n launchOptions: {\n slowMo: 50,\n },\n },\n});\n"})}),"\n",(0,i.jsxs)(t.p,{children:["However, most common ones like ",(0,i.jsx)(t.code,{children:"headless"})," or ",(0,i.jsx)(t.code,{children:"viewport"})," are available directly in the ",(0,i.jsx)(t.code,{children:"use"})," section - see ",(0,i.jsx)(t.a,{href:"#basic-options",children:"basic options"}),", ",(0,i.jsx)(t.a,{href:"#emulation-options",children:"emulation"})," or ",(0,i.jsx)(t.a,{href:"#network-options",children:"network"}),"."]}),"\n",(0,i.jsx)(t.h3,{id:"explicit-context-creation-and-option-inheritance",children:"Explicit Context Creation and Option Inheritance"}),"\n",(0,i.jsxs)(t.p,{children:["While a test or hook runs, every browser context created through the Playwright instance used by the test runner inherits context options from the ",(0,i.jsx)(t.code,{children:"use"})," section. This includes contexts created with the built-in ",(0,i.jsx)(t.code,{children:"browser"})," fixture, a separately launched browser, ",(0,i.jsx)(t.a,{href:"/docs/next/api/class-browsertype#browser-type-launch-persistent-context",children:"browserType.launchPersistentContext()"}),", or a direct ",(0,i.jsx)(t.code,{children:"playwright-core"})," import that resolves to the same instance. Explicit context options take precedence:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="playwright.config.ts"',children:"import { defineConfig } from '@playwright/test';\n\nexport default defineConfig({\n use: {\n userAgent: 'some custom ua',\n viewport: { width: 100, height: 100 },\n },\n});\n"})}),"\n",(0,i.jsx)(t.p,{children:"An example test illustrating the initial context options are set:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"test('should inherit use options on context when using built-in browser fixture', async ({\n browser,\n}) => {\n const context = await browser.newContext();\n const page = await context.newPage();\n expect(await page.evaluate(() => navigator.userAgent)).toBe('some custom ua');\n expect(await page.evaluate(() => window.innerWidth)).toBe(100);\n await context.close();\n});\n"})}),"\n",(0,i.jsx)(t.h3,{id:"configuration-scopes",children:"Configuration Scopes"}),"\n",(0,i.jsxs)(t.p,{children:["You can configure Playwright globally, per project, or per test. For example, you can set the locale to be used globally by adding ",(0,i.jsx)(t.code,{children:"locale"})," to the ",(0,i.jsx)(t.code,{children:"use"})," option of the Playwright config, and then override it for a specific project using the ",(0,i.jsx)(t.code,{children:"project"})," option in the config. You can also override it for a specific test by adding ",(0,i.jsx)(t.code,{children:"test.use({})"})," in the test file and passing in the options."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="playwright.config.ts"',children:"import { defineConfig } from '@playwright/test';\n\nexport default defineConfig({\n use: {\n locale: 'en-GB'\n },\n});\n"})}),"\n",(0,i.jsxs)(t.p,{children:["You can override options for a specific project using the ",(0,i.jsx)(t.code,{children:"project"})," option in the Playwright config."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"import { defineConfig, devices } from '@playwright/test';\n\nexport default defineConfig({\n projects: [\n {\n name: 'chromium',\n use: {\n ...devices['Desktop Chrome'],\n locale: 'de-DE',\n },\n },\n ],\n});\n"})}),"\n",(0,i.jsxs)(t.p,{children:["You can override options for a specific test file by using the ",(0,i.jsx)(t.code,{children:"test.use()"})," method and passing in the options. For example to run tests with the French locale for a specific test:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"import { test, expect } from '@playwright/test';\n\ntest.use({ locale: 'fr-FR' });\n\ntest('example', async ({ page }) => {\n // ...\n});\n"})}),"\n",(0,i.jsx)(t.p,{children:"The same works inside a describe block. For example to run tests in a describe block with the French locale:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"import { test, expect } from '@playwright/test';
1\n\ntest.describe('french language block', () => {\n\n test.use({ locale: 'fr-FR' });\n\n test('example', async ({ page }) => {\n // ...\n });\n});\n"})}),"\n",(0,i.jsx)(t.h3,{id:"reset-an-option",children:"Reset an option"}),"\n",(0,i.jsxs)(t.p,{children:["You can reset an option to the value defined in the config file. Consider the following config that sets a ",(0,i.jsx)(t.code,{children:"baseURL"}),":"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="playwright.config.ts"',children:"import { defineConfig } from '@playwright/test';\n\nexport default defineConfig({\n use: {\n baseURL: 'https://playwright.dev',\n },\n});\n"})}),"\n",(0,i.jsxs)(t.p,{children:["You can now configure ",(0,i.jsx)(t.code,{children:"baseURL"})," for a file, and also opt-out for a single test."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="intro.spec.ts"',children:"import { test } from '@playwright/test';\n\n// Configure baseURL for this file.\ntest.use({ baseURL: 'https://playwright.dev/docs/intro' });\n\ntest('check intro contents', async ({ page }) => {\n // This test will use \"https://playwright.dev/docs/intro\" base url as defined above.\n});\n\ntest.describe(() => {\n // Reset the value to a config-defined one.\n test.use({ baseURL: undefined });\n\n test('can navigate to intro from the home page', async ({ page }) => {\n // This test will use \"https://playwright.dev\" base url as defined in the config.\n });\n});\n"})}),"\n",(0,i.jsxs)(t.p,{children:["If you would like to completely reset the value to ",(0,i.jsx)(t.code,{children:"undefined"}),", use a long-form fixture notation."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",metastring:'title="intro.spec.ts"',children:"import { test } from '@playwright/test';\n\n// Completely unset baseURL for this file.\ntest.use({\n baseURL: [async ({}, use) => use(undefined), { scope: 'test' }],\n});\n\ntest('no base url', async ({ page }) => {\n // This test will not have a base url.\n});\n"})})]})}function h(e={}){let{wrapper:t}={...(0,l.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(a,{...e})}):a(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.