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 1b81abc
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Page provides methods to interact with a single tab in a running web browser. A
| [page.throttleNetwork(networkProfile)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/throttlenetwork) | Throttles the network in Chrome/Chromium to slow it down by the specified fields in the `networkProfile` object. |
| [page.title()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/title) | Returns the `page`'s title. |
| [page.type(selector, text[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/type/) | Types the `text` in the first element found that matches the `selector`. |
| [page.touchScreen](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/touchscreen) | Returns the [Touchscreen](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/touchscreen) instance to interact with a virtual touchscreen on the page. |
| [page.touchscreen](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/touchscreen) | Returns the [Touchscreen](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/touchscreen) instance to interact with a virtual touchscreen on the page. |
| [page.uncheck(selector[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/uncheck/) | Unselects an input `checkbox` element. |
| [page.url()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/url) | Returns the `page`'s URL. |
| [page.viewportSize()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/viewportsize) | Returns the `page`'s size (width and height). |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: 'touchScreen'
description: 'Browser module: page.touchScreen method'
title: 'touchscreen'
description: 'Browser module: page.touchscreen method'
---

# touchScreen
# touchscreen

Returns the [Touchscreen](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/touchscreen/) instance to interact with a virtual touchscreen on the page.

Expand All @@ -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 >}}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: 'Touchscreen'
description: 'Browser module: Touchscreen Class'
weight: 13
---

# Touchscreen

The `Touchscreen` class allows to interact with a virtual touchscreen. 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.

| Method | Description |
| -------------------------------------------------------------------------------------------------------------------------------------- | ---------------- |
| [Touchscreen.tap()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/touchscreen/tap) <BWIPT id="436"/> | Simulates a tap. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: 'tap()'
description: 'Browser module: Touchscreen.tap method'
---

# tap()

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.

<TableWithNestedRows>

| Parameter | Type | Default | Description |
| --------- | ------ | ------- | ----------------- |
| x | number | `0` | The x coordinate. |
| y | number | `0` | The y coordinate. |

</TableWithNestedRows>

### 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({
hasTouch: true,
});

const touchscreen = page.touchscreen;
await touchscreen.tap(50, 50);
}
```

{{< /code >}}

0 comments on commit 1b81abc

Please sign in to comment.