> For the complete documentation index, see [llms.txt](https://docs.puppetry.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.puppetry.app/test-step/commands.md).

# Page Commands

## page.emulate

Emulates given device metrics and user agent

![page.emulate](/files/-Lu8fFnw4GUu5cTsWWGu)

## page.setViewport

Defines browser viewport, where the viewport is the user's visible area of a web page

![page.setViewport ](/files/-Lu8fPgzEpu6CSDgo9wn)

![page.setViewport predefined resolution list](/files/-Lu8f_DZsmrk8QfgewFZ)

![page.setViewport advanced options](/files/-Lu8fjBZbmRRPoGh_6ZH)

## page.goto

Navigates to a given URL and waits until the page loaded

![page.goto](/files/-Lu8fs7Ybf29GhI2WqjO)

## page.screenshot

Makes a screenshot of the page

![page.screenshot](/files/-Lu8g8Jj8tOCq-ObBPcr)

![We can select targets to be highlighted on the screenshot](/files/-Lu8gE98NizazsQ9v6er)

![page.screenshot advanced options](/files/-Lu8gQC_UOCmAwMAiv1v)

## page.click

Emulates mouse click according to given options

![page.click](/files/-LuCC6wwEsIahnyZ45EW)

## page.moveMouse

Moves mouse to given position

![page.moveMouse](/files/-LuCCOoBPNhP_QkevffY)

## page.tap

Emulates tap according to given options

![page.tap](/files/-LuCCWfQ0swFDH8-lxZl)

## page.press

Emulates pressing on a key, optionally with modifiers such as ⇧, ⌥, alt, control, ⌘

![page.press](/files/-LuCCc-EY2Rmwlv2_ujA)

![page.press advanced options](/files/-LuCChdqq_YineGW4_h6)

## page.scroll

Scrolls the document in the window by the given amount

![page.scroll](/files/-LuCCnztEj6w04nNveJF)

## page.reload

Refreshes the page

![page.reload](/files/-LuCCuCcbtHBpjlIGvoc)

## page.setUserAgent

Sets custom user agent

![page.setUserAgent](/files/-LuCDAYIjOaMpcP5BxLF)

{% hint style="info" %}
While running test on < 3.0.1 this method requires adding "--no-sandbox --disable-setuid-sandbox" Chromium arguments in Browser options
{% endhint %}

## page.setCookie

Sets cookies on the page

![page.setCookie](/files/-LuCDGxoAtV7rYvTzCdv)

![page.setCookie advanced options](/files/-LuCDioSXax-hG7-WnnY)

## page.mockRequest

Intercepts to a given URL and replaces it according to provided data

{% hint style="info" %}
As soon as a matching request intercepted the session gets detached, meaning Puppetry stop listening for mocking. You have to set `page.mockRequest` before every request that you want to mock.
{% endhint %}

![page.mockRequest](/files/-LvtyJHoKFtqBJVjnPy5)

## page.waitFor

Waits for a given time before proceeding to the next command

![page.waitFor](/files/-LuCDd1lTcqk9fkmc6pe)

## page.waitForSelector

Waits for an element matching a provided [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors)

![page.waitForSelector](/files/-LuCDs1fv7-zegrBi3DS)

## page.waitForNavigation

Waits until a given event before proceeding to the next command

![page.waitForNavigation](/files/-LuCE1J9Ym4DZzx86lL2)

## page.waitForResponse

Waits for HTTP(S) response

![page.waitForResponse](/files/-LuCER0JxgMiT3lbpaE3)

## page.waitForRequest

Waits for HTTP(S) request

![page.waitForRequest](/files/-LuCEYonVGMtm6B0U-8h)

## page.authenticate

Provide credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).

![page.authenticate](/files/-M8Kor_IRzIPL3erZ5IG)

## page.evaluate

Evaluates JavaScript code in the page context

![page.evaluate](/files/-LuCEfY6r8qhpV_y2HC_)

## page.runjs

Runs custom JavaScript code in the test suite with use of [Puppeteer API](https://pptr.dev) and [Puppetry API](https://docs.puppetry.app/command-api). You can access [dynamic environment variables](https://docs.puppetry.app/template) via `ENV` map (e.g. `ENV[VAR_NAME]`)

![page.runjs](/files/-LuCEmdN5f8jOPzemzvG)

## page.debug

Stops execution of JavaScript, and calls (if available) the [debugging function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger). During test scenarios may happen many things - DOM changes, pages load. It makes hard to figure out why some test assertions fail in some particular moment. You can use this tool to set a breakpoint. Test flow will stop as soon as it reaches this point. So you will be able to examine the page state with DevTools.

![page.debug](/files/-LuCEraz5HGj7Bm8OpG6)

## page.closeDialog

Listen to dialog events and dismiss or accept dialogs (alert, beforeunload, confirm or prompt) as they are called

> The step must be defined before the expected dialog event

![page.closeDialog](/files/-LuCFFm_t_PoM_rdoQD1)

## page.assignVar

Assigns template variable dynamically

![page.assignVar](/files/-LuCFPpPXb2sl8iy1ePK)

## page.assignVarRemotely

Polls `URL` with a given intervals until a response satisfying `parserFn` function received or a specified timeout exceeded. It can be used, for example, to retrieve a value from an [email sent by the application under test](https://docs.puppetry.app/testing-emails)

![page.assignVarRemotely](/files/-LuCFUKgHJAQBs1BcZvQ)
