Skip to content

Commit

Permalink
Add browser touchscreen tap
Browse files Browse the repository at this point in the history
Moves the example from page to the touchscreen.tap to prevent redundancy
and improve maintainability of the docs
  • Loading branch information
inancgumus committed May 6, 2024
1 parent b03eb4d commit 2320e94
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,3 @@ Returns the [Touchscreen](https://grafana.com/docs/k6/<K6_VERSION>/javascript-ap
| Type | Description |
| ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| [Touchscreen](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/touchscreen/) | The `Touchscreen` instance associated with the page. |

### Example

{{< code >}}

```javascript
import { browser } from 'k6/experimental/browser';

export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};

export default async function () {
const page = browser.newPage();

await page.goto('https://test.k6.io/browser.php');
page.touchScreen.tap(50, 50);
}
```

{{< /code >}}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,38 @@ weight: 13

# Touchscreen

{{< docs/shared source="k6" lookup="browser-module-wip.md" version="<K6_VERSION>" >}}
The `Touchscreen` class allows to interact with a virtual touchscreen. It can only be used in
[BrowserContext](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/newcontext)s that have been initialized with the `hasTouch` option set to `true`. A `Touchscreen` instance can be obtained by calling the [`page.touchscreen`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/touchscreen/) method.

## Supported APIs
| Method | Description |
| ----------------------- | ----------- |
| Touchscreen.tap(x, y) | Simulates a tap (dispatches a `touchstart` and `touchend` events) at the specified coordinates. The `x` and `y` arguments are the coordinates of the tap relative to the top-left corner of the main frame. |

| Method | Playwright Relevant Distinctions |
| ---------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
| <a href="https://playwright.dev/docs/api/class-touchscreen#touchscreen-tap" target="_blank" >touchscreen.tap(x, y)</a> | - |
### Example

{{< code >}}

```javascript
import { browser } from 'k6/experimental/browser';

export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};

export default async function () {
const page = browser.newPage();
const touchScreen = page.touchScreen;
await touchscreen.tap(50, 50);
}
```

{{< /code >}}

0 comments on commit 2320e94

Please sign in to comment.