# Page Commands

## page.emulate

Emulates given device metrics and user agent

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhUtpjNIWSayvjeV0GX%2F-LhUyMBtfJ0IfdmCp_4I%2Fpage.emulate.png?alt=media\&token=b2b3bb53-2ea5-456e-abd9-3fe6b033579b)

## page.setViewport

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

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhUtpjNIWSayvjeV0GX%2F-LhUyOY2S1qqLTgqyhXw%2Fpage.setViewport.png?alt=media\&token=cea6ba16-d4c8-4218-8aa1-6e04235cf3db)

## page.goto

Navigates to a given URL and waits until the page loaded

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhUtpjNIWSayvjeV0GX%2F-LhUyR23MNONHrVErv2j%2Fpage.goto.png?alt=media\&token=14aed3a8-82f6-4f2a-ab33-604f05f4f762)

## page.moveMouse

Moves mouse to given position

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhUtpjNIWSayvjeV0GX%2F-LhUyTWiooE47Q80O5vH%2Fpage.moveMouse.png?alt=media\&token=9d53c0d7-aff1-444c-90dd-1a273b0e7502)

## page.click

Emulates mouse click according to given options

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhUtpjNIWSayvjeV0GX%2F-LhUyVrzTKDMJfAeWt7l%2Fpage.click.png?alt=media\&token=8050b90b-45d0-4276-8d95-813feb5e14b4)

## page.tap

Emulates tap according to given options

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhUtpjNIWSayvjeV0GX%2F-LhUyZxS3TiF7KvXjgUo%2Fpage.tap.png?alt=media\&token=a144ec9b-2ce0-430a-92bc-bebc0bbe07c6)

## page.press

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

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhUtpjNIWSayvjeV0GX%2F-LhUybm0h_BJKNrMHcHi%2Fpage.press.png?alt=media\&token=d018bd96-9dde-48b2-adfd-e4e987f88870)

## page.scroll

Scrolls the document in the window by the given amount

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhVFLTInjx5kccr9rFj%2F-LhVFQdCoSeHpP9RX_ar%2Fpage.scroll.png?alt=media\&token=3b0b3b15-3f3d-48a5-a39f-b345ef05b5ab)

## page.reload

Refreshes the page

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhVFLTInjx5kccr9rFj%2F-LhVGqprGsB1DV3cw4AF%2Fpage.reload.png?alt=media\&token=8f2b660c-10f3-44b1-9da4-fc32952c893b)

## page.setCookie

Sets cookies on the page

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhZkHxVX-JJAkAsHchr%2F-LhZm5RauduHMsexhnC-%2Fpage.setCookie-1.png?alt=media\&token=8bec7e57-b0a7-4b48-aadb-8d4de8db1b62)

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhZkHxVX-JJAkAsHchr%2F-LhZm7FLwTvQBI4oqAhk%2Fpage.setCookie-2.png?alt=media\&token=1a38a1c4-60a4-47cf-9f32-47f6682fda55)

## page.waitFor

Waits for a given time before proceeding to the next command

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhVFLTInjx5kccr9rFj%2F-LhVGIp96ME32Yb-3Hlx%2Fpage.waitFor.png?alt=media\&token=014d6ed4-2e01-4019-a6ef-0f5f0485f7f0)

## page.waitForSelector

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

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhVFLTInjx5kccr9rFj%2F-LhVGMzXrOcsx8990krh%2Fpage.waitForSelector.png?alt=media\&token=13854885-2448-42d3-87fa-b2ba726c16ac)

## page.waitForNavigator

Waits until a given event before proceeding to the next command

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhVFLTInjx5kccr9rFj%2F-LhVGQ5Q52lBJ-fyMNDJ%2Fpage.waitForNavigator.png?alt=media\&token=bccc1ac2-3a8c-4468-8eef-3468a01e2c57)

## page.evaluate

Evaluates JavaScript code in the page context

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhVFLTInjx5kccr9rFj%2F-LhVGTC6jvVOzWXR0ZEz%2Fpage.evaluate.png?alt=media\&token=a51214a5-69dd-4a61-b03b-a7199af2e931)

## 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]`)

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhVFLTInjx5kccr9rFj%2F-LhVGV_ZO9UHydwZPnFb%2Fpage.runjs.png?alt=media\&token=cee401fc-7f1d-4807-9563-cd1343d2ceb4)

## 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.

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhVFLTInjx5kccr9rFj%2F-LhVGYBFl8xEhObFsGYA%2Fpage.debug.png?alt=media\&token=ff8a8983-fab1-4e2e-aa90-7046b75b932e)

## page.assignVar

Assigns template variable dynamically

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhVFLTInjx5kccr9rFj%2F-LhVGa5vNcopG4IZ3QuK%2Fpage.assignVar.png?alt=media\&token=d6b524c5-9e4f-4297-862f-45550de2564f)

## 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)

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhVFLTInjx5kccr9rFj%2F-LhVGkSPTzT11H032LVg%2Fpage.assignVarRemotely-2.png?alt=media\&token=f97ab15d-b5ac-4f9c-b832-ea5304e25f78)

![](https://2843146877-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdyKJ-zzeS2hB7DF04J%2F-LhVFLTInjx5kccr9rFj%2F-LhVGdAm_OoJXcqNQhyJ%2Fpage.assignVarRemotely-1.png?alt=media\&token=23802dce-2f14-470a-bc4a-35e104075f58)
