Playwright Access
Reference for accessing Playwright’s Page
and BrowserContext
objects within Magnitude tests.
Magnitude tests execute using Playwright under the hood. For advanced use cases or when you need direct control over the browser beyond what the ai
object provides, Magnitude exposes the underlying Playwright Page
and BrowserContext
objects within the test function context.
Test Function Context
The testFn
passed to the test
function receives a context object:
The interface for Magnitude’s AI capabilities. See AI Steps and Checks and Low-Level AI Actions.
The standard Playwright Page
object corresponding to the current browser tab. You can call any methods available on the Playwright Page
API directly on this object.
The standard Playwright BrowserContext
object for the current browser session. Use this for context-level operations like managing cookies, permissions, or opening new pages.
While direct Playwright access offers maximum flexibility, prefer using the ai.step()
and ai.check()
methods for most interactions. This keeps tests more readable, maintainable, and leverages Magnitude’s AI capabilities for resilience. Use page
and context
when specific Playwright functionality is required that isn’t covered by the ai
object.
Refer to the official Playwright Documentation for the full API available on the page
and context
objects.