playwright-touch 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -2
- package/dist/chromium/gestures.js +19 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/playwright-test.d.ts +66 -0
- package/dist/playwright-test.js +64 -0
- package/dist/recipes.d.ts +57 -0
- package/dist/recipes.js +135 -0
- package/dist/synthetic.d.ts +17 -0
- package/dist/synthetic.js +117 -0
- package/package.json +17 -2
package/README.md
CHANGED
|
@@ -110,6 +110,39 @@ Content follows the finger, so a swipe up scrolls the page down.
|
|
|
110
110
|
A complete small project with Playwright Test is in [`examples/playwright-test`](examples/playwright-test):
|
|
111
111
|
the config with the switch for exact scroll distances, and four tests.
|
|
112
112
|
|
|
113
|
+
### As a Playwright Test fixture
|
|
114
|
+
|
|
115
|
+
With Playwright Test the gestures also come as a fixture. Import `test` from `playwright-touch/test`
|
|
116
|
+
and ask for `touch` next to `page`:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { test, expect } from 'playwright-touch/test';
|
|
120
|
+
|
|
121
|
+
test('the carousel moves under a finger', async ({ page, touch }) => {
|
|
122
|
+
await page.goto('https://example.com');
|
|
123
|
+
|
|
124
|
+
await touch.tap(page.locator('#menu'));
|
|
125
|
+
await touch.swipe(page.locator('#carousel'), { direction: 'left' });
|
|
126
|
+
await touch.fling({ direction: 'up' }); // no target: the whole page
|
|
127
|
+
await expect(page.locator('#footer')).toBeInViewport();
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Each gesture is a step of its own, so the report and the trace say `touch.swipe left on
|
|
132
|
+
locator('#carousel')` where the test touched the page. A bare point needs no `{ page }` here, the
|
|
133
|
+
fixture knows its page. To see the fingers in a video or a trace, switch the dots on for a file or
|
|
134
|
+
for the whole project:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import { test } from 'playwright-touch/test';
|
|
138
|
+
|
|
139
|
+
test.use({ touchOptions: { showFingers: true } });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`test` is Playwright's own, extended. If you have fixtures of your own, join the two with
|
|
143
|
+
`mergeTests` from `@playwright/test`. The functions from `playwright-touch` keep working next to
|
|
144
|
+
the fixture, and they are still the way to use the package without Playwright Test.
|
|
145
|
+
|
|
113
146
|
## Gestures
|
|
114
147
|
|
|
115
148
|
| Call | What the finger does |
|
|
@@ -145,6 +178,44 @@ await gesture(page, {
|
|
|
145
178
|
});
|
|
146
179
|
```
|
|
147
180
|
|
|
181
|
+
### What a person is doing
|
|
182
|
+
|
|
183
|
+
Four more gestures are named after the task and built from the ones above.
|
|
184
|
+
|
|
185
|
+
| Call | What it does |
|
|
186
|
+
| --- | --- |
|
|
187
|
+
| `swipeUntilVisible(locator, { direction, within, distance, max })` | Swipes until the middle of the element is in the viewport, the way a person scrolls a list to find a row. Resolves to the number of swipes. Fails when the content stops moving or after `max` swipes (10 by default), and says which. |
|
|
188
|
+
| `pullToRefresh(page, { distance, duration })` | Pulls the page down from near its top by half the screen and comes to rest before lifting. |
|
|
189
|
+
| `edgeSwipe(page, { edge, distance, duration, inset })` | Starts `inset` pixels (2 by default) from the `left`, `right`, `top` or `bottom` edge and comes inward, for a side drawer or a sheet. |
|
|
190
|
+
| `twoFingerSwipe(target, { direction, distance, gap, duration })` | Moves two fingers side by side, for maps and embeds that leave one finger to the page. |
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
const swipes = await swipeUntilVisible(page.locator('#order-42')); // down the page
|
|
194
|
+
await swipeUntilVisible(page.locator('#slide-6'), { // inside a carousel
|
|
195
|
+
direction: 'left',
|
|
196
|
+
within: page.locator('#carousel'),
|
|
197
|
+
});
|
|
198
|
+
await pullToRefresh(page);
|
|
199
|
+
await edgeSwipe(page, { edge: 'left' });
|
|
200
|
+
await twoFingerSwipe(page.locator('#map'), { direction: 'down' });
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
`pullToRefresh` reaches the handlers of the page, which is what a pull-to-refresh written in
|
|
204
|
+
JavaScript listens to. Chrome's own reload on a pull at the top did not fire in Chrome on an Android
|
|
205
|
+
phone: the page saw a pull of 405 px, and of 700 px, and was not reloaded. To test a reload, call
|
|
206
|
+
`page.reload()`.
|
|
207
|
+
|
|
208
|
+
On a real phone the outermost strip of the screen belongs to the system. In Safari on an iPhone a
|
|
209
|
+
stroke that starts 2 px from the left edge goes back in history and the page never sees it, as
|
|
210
|
+
under a real finger; one that starts 6 px in reached the page (iPhone 12 Pro, iOS 17.5). For a
|
|
211
|
+
drawer of your own page pass `inset: 20`. In Chrome on an Android phone the same stroke from 2 px reached the
|
|
212
|
+
page and did not trigger the system's back gesture.
|
|
213
|
+
|
|
214
|
+
`swipeUntilVisible` does not wait for an element that is not on the page yet, so it works with lists
|
|
215
|
+
that add rows while they scroll. All four are on the Playwright Test fixture as well, as
|
|
216
|
+
`touch.swipeUntilVisible(locator)`, `touch.pullToRefresh()`, `touch.edgeSwipe({ edge })` and
|
|
217
|
+
`touch.twoFingerSwipe(locator, { direction })`.
|
|
218
|
+
|
|
148
219
|
### Seeing the fingers
|
|
149
220
|
|
|
150
221
|
```ts
|
|
@@ -431,6 +502,51 @@ swipe moved the page 275 or 281 px in twelve runs out of twelve, a 300 px fling
|
|
|
431
502
|
1753 and 1872 px in twenty-eight runs, a pinch asked for 1.8 was read by the page as 1.80 and a
|
|
432
503
|
rotate by 90 degrees as 90.0.
|
|
433
504
|
|
|
505
|
+
## WebKit and Firefox
|
|
506
|
+
|
|
507
|
+
Playwright can send touch input only to Chromium. A project that also runs its tests in WebKit and
|
|
508
|
+
Firefox can keep the same test: there the package sends each gesture to the page as pointer events,
|
|
509
|
+
touch events and, after a tap, a click, all made by script.
|
|
510
|
+
|
|
511
|
+
| | Chromium | WebKit, Firefox |
|
|
512
|
+
| --- | --- | --- |
|
|
513
|
+
| Handlers on the page (carousels, maps, drag and drop, gesture recognisers) | run | run |
|
|
514
|
+
| A tap clicks, a double tap gives `dblclick` | yes | yes |
|
|
515
|
+
| The page scrolls under the finger | yes | no |
|
|
516
|
+
| A fling coasts on | yes | no |
|
|
517
|
+
| A pinch zooms the page | yes | no, and `pinch(page, …)` says so |
|
|
518
|
+
| Events are trusted (`isTrusted`) | yes | no |
|
|
519
|
+
|
|
520
|
+
So in WebKit and Firefox a test can check what your own code does with a gesture, and cannot check
|
|
521
|
+
what the browser does. The first gesture in each of them prints a line saying this;
|
|
522
|
+
`PLAYWRIGHT_TOUCH_QUIET=1` hides it. `isSynthetic(page)` tells a test which kind of page it has, for
|
|
523
|
+
an assertion that only holds with real input:
|
|
524
|
+
|
|
525
|
+
```ts
|
|
526
|
+
await swipe(page, { direction: 'up', distance: 300 });
|
|
527
|
+
if (!isSynthetic(page)) expect(await page.evaluate(() => scrollY)).toBe(285);
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
This is WebKit as Playwright runs it on a desktop. Safari on an iPhone or in the simulator gets real
|
|
531
|
+
fingers, as described above.
|
|
532
|
+
|
|
533
|
+
## Works with
|
|
534
|
+
|
|
535
|
+
The gestures are tested against the libraries people ask about first. Each test loads the library's
|
|
536
|
+
own build into an emulated phone and checks what the library made of the touch.
|
|
537
|
+
|
|
538
|
+
| Library | Version | What is checked |
|
|
539
|
+
| --- | --- | --- |
|
|
540
|
+
| [Swiper](https://swiperjs.com) | 14.5 | `swipe` and `fling` move one slide, a swipe back returns |
|
|
541
|
+
| [Embla Carousel](https://www.embla-carousel.com) | 8.6 | `swipe` selects the next slide, `fling` the previous |
|
|
542
|
+
| [Leaflet](https://leafletjs.com) | 1.9 | `swipe` pans the map, `pinch` to twice the distance zooms one level |
|
|
543
|
+
| [Hammer.js](https://hammerjs.github.io) | 2.0 | `swipeleft`, `pinch` with its scale, `rotate` with its angle, `press` and `doubletap` are recognised |
|
|
544
|
+
|
|
545
|
+
These run in emulated Chrome with every `npm test`. Swiper, Embla and Hammer.js are also run in
|
|
546
|
+
WebKit and Firefox, with events made by script. A carousel reacts only when the finger lands on
|
|
547
|
+
it: a stroke across a container that is taller than its slides can start on empty space, and Swiper
|
|
548
|
+
ignores that, under a real finger too. Aim at the slides.
|
|
549
|
+
|
|
434
550
|
## Checked on
|
|
435
551
|
|
|
436
552
|
- An emulated phone in desktop Chrome and in the Chromium that Playwright downloads (`npm test`).
|
|
@@ -450,8 +566,9 @@ rotate by 90 degrees as 90.0.
|
|
|
450
566
|
- A tab in the background of Safari on a phone does not answer; the tab has to stay in front.
|
|
451
567
|
- On a phone whose default browser is not Safari the tab is still opened in Safari. A phone with
|
|
452
568
|
iOS before 16 was not tried.
|
|
453
|
-
- Through Playwright only Chromium
|
|
454
|
-
|
|
569
|
+
- Through Playwright, real touch input exists only in Chromium. In WebKit and Firefox the gestures
|
|
570
|
+
are events made by script, which reach the page's handlers and nothing else. See
|
|
571
|
+
[WebKit and Firefox](#webkit-and-firefox).
|
|
455
572
|
- Chrome on a phone zooms on a double tap unless the page is laid out for phones, and in a tab no
|
|
456
573
|
finger has scrolled yet it does not know that the page is. The first `doubleTap` there is taken
|
|
457
574
|
for a zoom. `doubleTap` notices, undoes the zoom and taps twice again, so the page gets its two
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// The gestures in Chromium, through the browser's own touch input.
|
|
2
|
+
import { isSynthetic, performSynthetic } from '../synthetic.js';
|
|
2
3
|
import { sessionOf } from '../session.js';
|
|
3
4
|
import { along, arc } from '../polyline.js';
|
|
4
5
|
import { clockAheadOf } from './clock.js';
|
|
@@ -224,12 +225,23 @@ const pageOf = (target, fallback) => {
|
|
|
224
225
|
* touch input. Every event carries its own timestamp on an even 60 Hz clock: the browser works out
|
|
225
226
|
* the speed of the finger from those, so the momentum does not depend on how busy this process is.
|
|
226
227
|
*/
|
|
227
|
-
async function perform(page, { fingers, duration, ease, holdBefore = 0, holdAfter = 0 }) {
|
|
228
|
+
async function perform(page, { fingers, duration, ease, holdBefore = 0, holdAfter = 0, then }) {
|
|
228
229
|
// A page that is not on screen (a locked phone, a tab behind another) draws no frames, and the
|
|
229
230
|
// browser never answers the first touch: say so instead of waiting for ever.
|
|
230
231
|
if ((await page.evaluate(() => document.visibilityState)) !== 'visible') {
|
|
231
232
|
throw new Error('playwright-touch: the page is not on screen, so it cannot be touched. Unlock the phone, or bring the tab to the front.');
|
|
232
233
|
}
|
|
234
|
+
if (isSynthetic(page)) {
|
|
235
|
+
// The same path on the same 60 Hz grid, as a list the page plays on its own clock.
|
|
236
|
+
const steps = duration > 0 ? Math.max(2, Math.round(duration / FRAME_MS)) : 0;
|
|
237
|
+
const at = (k) => fingers.map((path) => round(path(k)));
|
|
238
|
+
const frames = [{ at: 0, points: at(0) }];
|
|
239
|
+
for (let i = 1; i <= steps; i++)
|
|
240
|
+
frames.push({ at: holdBefore + i * FRAME_MS, points: at(ease(i / steps)) });
|
|
241
|
+
// The last frame only marks when the fingers lift.
|
|
242
|
+
frames.push({ at: holdBefore + steps * FRAME_MS + holdAfter, points: at(steps ? 1 : 0) });
|
|
243
|
+
return performSynthetic(page, frames, then);
|
|
244
|
+
}
|
|
233
245
|
const cdp = await sessionOf(page);
|
|
234
246
|
const points = (k) => fingers.map((path, id) => ({ ...round(path(k)), id, radiusX: 8, radiusY: 8, force: 1 }));
|
|
235
247
|
// Every event is stamped on an even 60 Hz clock, and sent when that clock says, as far as the
|
|
@@ -320,7 +332,7 @@ export async function tap(target, options = {}) {
|
|
|
320
332
|
aimed('tap', target, options);
|
|
321
333
|
const page = pageOf(target, options.page);
|
|
322
334
|
const at = await landingOn(page, target);
|
|
323
|
-
await perform(page, { fingers: [() => at], duration: 0, ease: linear, holdBefore: 60 });
|
|
335
|
+
await perform(page, { fingers: [() => at], duration: 0, ease: linear, holdBefore: 60, then: 'click' });
|
|
324
336
|
}
|
|
325
337
|
/** The browsers of real phones, which `connectAndroid` adds its own to. */
|
|
326
338
|
export const realPhones = new WeakSet();
|
|
@@ -333,9 +345,9 @@ export async function doubleTap(target, options = {}) {
|
|
|
333
345
|
const page = pageOf(target, options.page);
|
|
334
346
|
const at = await landingOn(page, target);
|
|
335
347
|
const twice = async () => {
|
|
336
|
-
await perform(page, { fingers: [() => at], duration: 0, ease: linear, holdBefore: 50 });
|
|
348
|
+
await perform(page, { fingers: [() => at], duration: 0, ease: linear, holdBefore: 50, then: 'click' });
|
|
337
349
|
await sleep(90);
|
|
338
|
-
await perform(page, { fingers: [() => at], duration: 0, ease: linear, holdBefore: 50 });
|
|
350
|
+
await perform(page, { fingers: [() => at], duration: 0, ease: linear, holdBefore: 50, then: 'dblclick' });
|
|
339
351
|
};
|
|
340
352
|
if (!realPhones.has(page.context()))
|
|
341
353
|
return twice();
|
|
@@ -419,6 +431,9 @@ export async function pinch(target, options) {
|
|
|
419
431
|
x: (window.visualViewport?.width ?? innerWidth) / 2,
|
|
420
432
|
y: (window.visualViewport?.height ?? innerHeight) / 2,
|
|
421
433
|
}));
|
|
434
|
+
if (isSynthetic(page)) {
|
|
435
|
+
throw new Error("playwright-touch: zooming the page with a pinch needs the browser's own touch input, which only Chromium offers. Pinch an element instead, or run this test in Chromium.");
|
|
436
|
+
}
|
|
422
437
|
const cdp = await sessionOf(page);
|
|
423
438
|
const duration = options.duration ?? 400;
|
|
424
439
|
const travel = Math.abs(Math.log2(options.scale)) * 400;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ import type { DirectedOptions, DragOptions, GestureOptions, PinchOptions, Rotate
|
|
|
6
6
|
export type { Direction, DirectedOptions, DragOptions, GestureOptions, PinchOptions, Point, RotateOptions, StrokeOptions, } from './types.js';
|
|
7
7
|
export type { Target } from './chromium/gestures.js';
|
|
8
8
|
export { steadyScrollArgs } from './chromium/steady.js';
|
|
9
|
+
export { isSynthetic } from './synthetic.js';
|
|
10
|
+
export { edgeSwipe, pullToRefresh, swipeUntilVisible, twoFingerSwipe } from './recipes.js';
|
|
11
|
+
export type { SwipeUntilOptions } from './recipes.js';
|
|
9
12
|
/**
|
|
10
13
|
* What Chrome's and Safari's pages have in common. A script whose page is typed like this runs on
|
|
11
14
|
* both: an emulated or real Android phone through Playwright, and Safari in an iPhone simulator.
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@ import * as chrome from './chromium/gestures.js';
|
|
|
2
2
|
import * as measuring from './measure.js';
|
|
3
3
|
import * as showing from './show.js';
|
|
4
4
|
export { steadyScrollArgs } from './chromium/steady.js';
|
|
5
|
+
export { isSynthetic } from './synthetic.js';
|
|
6
|
+
export { edgeSwipe, pullToRefresh, swipeUntilVisible, twoFingerSwipe } from './recipes.js';
|
|
5
7
|
// Safari on iOS has no Playwright page. Its page and locators are told apart here, so the same
|
|
6
8
|
// calls work on both.
|
|
7
9
|
const isSafari = (target) => !!target && target.ios === true && typeof target.goto === 'function';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { expect } from '@playwright/test';
|
|
2
|
+
import type { Locator } from '@playwright/test';
|
|
3
|
+
import type { SwipeUntilOptions } from './recipes.js';
|
|
4
|
+
import type { DirectedOptions, Direction, DragOptions, GestureOptions, PinchOptions, Point, RotateOptions, StrokeOptions } from './types.js';
|
|
5
|
+
type Stroke = StrokeOptions | DirectedOptions;
|
|
6
|
+
type Spot = Locator | Point;
|
|
7
|
+
type TwoFingerOptions = {
|
|
8
|
+
direction: Direction;
|
|
9
|
+
distance?: number;
|
|
10
|
+
gap?: number;
|
|
11
|
+
duration?: number;
|
|
12
|
+
};
|
|
13
|
+
/** The gestures, already aimed at the test's page. */
|
|
14
|
+
export interface Touch {
|
|
15
|
+
/** A quick touch that the browser turns into a click. */
|
|
16
|
+
tap(target: Spot): Promise<void>;
|
|
17
|
+
/** Two quick taps on the same place. */
|
|
18
|
+
doubleTap(target: Spot): Promise<void>;
|
|
19
|
+
/** Rests one finger on the target without moving. */
|
|
20
|
+
longPress(target: Spot, options?: {
|
|
21
|
+
duration?: number;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
/** A stroke that stops before the finger lifts. Across the page, or across an element. */
|
|
24
|
+
swipe(options: Stroke): Promise<void>;
|
|
25
|
+
swipe(target: Locator, options: Stroke): Promise<void>;
|
|
26
|
+
/** A flick that leaves the content scrolling on its momentum. Across the page, or across an element. */
|
|
27
|
+
fling(options: Stroke): Promise<void>;
|
|
28
|
+
fling(target: Locator, options: Stroke): Promise<void>;
|
|
29
|
+
/** Carries the source to the destination under one finger. */
|
|
30
|
+
drag(source: Spot, destination: Spot, options?: DragOptions): Promise<void>;
|
|
31
|
+
/** Two fingers spreading or closing, on the page or on an element. */
|
|
32
|
+
pinch(options: PinchOptions): Promise<void>;
|
|
33
|
+
pinch(target: Locator, options: PinchOptions): Promise<void>;
|
|
34
|
+
/** Two fingers turning around the middle of an element. */
|
|
35
|
+
rotate(target: Locator, options: RotateOptions): Promise<void>;
|
|
36
|
+
/** Any gesture, given as the path of each finger. */
|
|
37
|
+
gesture(options: GestureOptions): Promise<void>;
|
|
38
|
+
/** Swipes until the middle of the target is in view. Resolves to the number of swipes it took. */
|
|
39
|
+
swipeUntilVisible(target: Locator, options?: SwipeUntilOptions): Promise<number>;
|
|
40
|
+
/** Pulls the page down from near its top. */
|
|
41
|
+
pullToRefresh(options?: {
|
|
42
|
+
distance?: number;
|
|
43
|
+
duration?: number;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
/** A stroke that starts on an edge of the screen and comes inward. */
|
|
46
|
+
edgeSwipe(options: {
|
|
47
|
+
edge: 'left' | 'right' | 'top' | 'bottom';
|
|
48
|
+
distance?: number;
|
|
49
|
+
duration?: number;
|
|
50
|
+
inset?: number;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
/** Two fingers moving side by side, on the page or on an element. */
|
|
53
|
+
twoFingerSwipe(options: TwoFingerOptions): Promise<void>;
|
|
54
|
+
twoFingerSwipe(target: Locator, options: TwoFingerOptions): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
/** Settings of the `touch` fixture, set with `test.use({ touchOptions: { ... } })` or in the config. */
|
|
57
|
+
export interface TouchOptions {
|
|
58
|
+
/** Draws a dot under every finger, so a video or a trace shows where the page was touched. */
|
|
59
|
+
showFingers: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** Playwright's `test` with a `touch` fixture. Combine it with your own fixtures through `mergeTests`. */
|
|
62
|
+
export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
|
|
63
|
+
touch: Touch;
|
|
64
|
+
touchOptions: TouchOptions;
|
|
65
|
+
}, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
|
|
66
|
+
export { expect };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// The gestures as a Playwright Test fixture. A test asks for `touch` next to `page` and each gesture
|
|
2
|
+
// shows up as its own step in the report and in the trace:
|
|
3
|
+
//
|
|
4
|
+
// import { test, expect } from 'playwright-touch/test';
|
|
5
|
+
//
|
|
6
|
+
// test('the carousel moves', async ({ page, touch }) => {
|
|
7
|
+
// await page.goto('/');
|
|
8
|
+
// await touch.swipe(page.locator('#carousel'), { direction: 'left' });
|
|
9
|
+
// });
|
|
10
|
+
//
|
|
11
|
+
// This is the one file of the package that imports Playwright Test, so a project that uses only
|
|
12
|
+
// `playwright-core` never loads it.
|
|
13
|
+
import { test as base, expect } from '@playwright/test';
|
|
14
|
+
import * as gestures from './index.js';
|
|
15
|
+
const isLocator = (value) => !!value && typeof value.boundingBox === 'function';
|
|
16
|
+
const nameOf = (target) => isLocator(target) ? String(target) : `(${Math.round(target.x)}, ${Math.round(target.y)})`;
|
|
17
|
+
const strokeOf = (options) => 'direction' in options
|
|
18
|
+
? `${options.direction}${options.distance === undefined ? '' : ` ${options.distance} px`}`
|
|
19
|
+
: `${nameOf(options.from)} to ${nameOf(options.to)}`;
|
|
20
|
+
function touchOn(page) {
|
|
21
|
+
// Boxed, so a gesture that fails is reported on the line of the test that made it.
|
|
22
|
+
const step = (title, body) => base.step(`touch.${title}`, body, { box: true });
|
|
23
|
+
// A bare point does not say which page it is on; the fixture knows.
|
|
24
|
+
const pointed = (...targets) => (targets.every(isLocator) ? {} : { page });
|
|
25
|
+
// The optional first argument: an element to act on, or the options alone for the whole page.
|
|
26
|
+
const split = (first, second) => second === undefined ? [page, first, 'page'] : [first, second, String(first)];
|
|
27
|
+
return {
|
|
28
|
+
tap: (target) => step(`tap ${nameOf(target)}`, () => gestures.tap(target, pointed(target))),
|
|
29
|
+
doubleTap: (target) => step(`doubleTap ${nameOf(target)}`, () => gestures.doubleTap(target, pointed(target))),
|
|
30
|
+
longPress: (target, options = {}) => step(`longPress ${nameOf(target)}`, () => gestures.longPress(target, { ...options, ...pointed(target) })),
|
|
31
|
+
swipe: (first, second) => {
|
|
32
|
+
const [target, options, where] = split(first, second);
|
|
33
|
+
return step(`swipe ${strokeOf(options)} on ${where}`, () => gestures.swipe(target, options));
|
|
34
|
+
},
|
|
35
|
+
fling: (first, second) => {
|
|
36
|
+
const [target, options, where] = split(first, second);
|
|
37
|
+
return step(`fling ${strokeOf(options)} on ${where}`, () => gestures.fling(target, options));
|
|
38
|
+
},
|
|
39
|
+
drag: (source, destination, options = {}) => step(`drag ${nameOf(source)} to ${nameOf(destination)}`, () => gestures.drag(source, destination, { ...options, ...pointed(source, destination) })),
|
|
40
|
+
pinch: (first, second) => {
|
|
41
|
+
const [target, options, where] = split(first, second);
|
|
42
|
+
return step(`pinch ×${options.scale} on ${where}`, () => gestures.pinch(target, options));
|
|
43
|
+
},
|
|
44
|
+
rotate: (target, options) => step(`rotate ${options.degrees}° on ${String(target)}`, () => gestures.rotate(target, options)),
|
|
45
|
+
gesture: (options) => step(`gesture with ${options.fingers.length} finger${options.fingers.length === 1 ? '' : 's'}`, () => gestures.gesture(page, options)),
|
|
46
|
+
swipeUntilVisible: (target, options = {}) => step(`swipeUntilVisible ${String(target)}`, () => gestures.swipeUntilVisible(target, options)),
|
|
47
|
+
pullToRefresh: (options = {}) => step('pullToRefresh', () => gestures.pullToRefresh(page, options)),
|
|
48
|
+
edgeSwipe: (options) => step(`edgeSwipe from the ${options.edge}`, () => gestures.edgeSwipe(page, options)),
|
|
49
|
+
twoFingerSwipe: (first, second) => {
|
|
50
|
+
const [target, options, where] = split(first, second);
|
|
51
|
+
return step(`twoFingerSwipe ${options.direction} on ${where}`, () => gestures.twoFingerSwipe(target, options));
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Playwright's `test` with a `touch` fixture. Combine it with your own fixtures through `mergeTests`. */
|
|
56
|
+
export const test = base.extend({
|
|
57
|
+
touchOptions: [{ showFingers: false }, { option: true }],
|
|
58
|
+
touch: async ({ page, touchOptions }, use) => {
|
|
59
|
+
if (touchOptions.showFingers)
|
|
60
|
+
await gestures.showTouches(page);
|
|
61
|
+
await use(touchOn(page));
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
export { expect };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { SharedPage } from './index.js';
|
|
2
|
+
import type { IosLocator, IosPage } from './ios/simulator.js';
|
|
3
|
+
import type { Locator, Page } from './session.js';
|
|
4
|
+
import type { Direction } from './types.js';
|
|
5
|
+
type AnyPage = Page | IosPage | SharedPage;
|
|
6
|
+
type AnyLocator = Locator | IosLocator;
|
|
7
|
+
export interface SwipeUntilOptions {
|
|
8
|
+
/** The way the finger travels. Content follows the finger, so `up` brings up what is below. Default `up`. */
|
|
9
|
+
direction?: Direction;
|
|
10
|
+
/** The scrolling element to swipe on. Default: the page. */
|
|
11
|
+
within?: AnyLocator;
|
|
12
|
+
/** The length of each stroke in pixels. Default: 60 % of the page or the element. */
|
|
13
|
+
distance?: number;
|
|
14
|
+
/** How many swipes to try before giving up. Default 10. */
|
|
15
|
+
max?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Swipes until the middle of the target is inside the viewport, the way a person scrolls a list to
|
|
19
|
+
* find a row. Returns the number of swipes it took, 0 when the target was in view already. Fails
|
|
20
|
+
* when the content stops moving or the tries run out, and says which.
|
|
21
|
+
*/
|
|
22
|
+
export declare function swipeUntilVisible(target: AnyLocator, options?: SwipeUntilOptions): Promise<number>;
|
|
23
|
+
/**
|
|
24
|
+
* Pulls the page down from near its top, the gesture behind "pull to refresh". The finger comes to
|
|
25
|
+
* rest before it lifts, as a thumb does. The page should be scrolled to its top first.
|
|
26
|
+
*/
|
|
27
|
+
export declare function pullToRefresh(page: AnyPage, options?: {
|
|
28
|
+
distance?: number;
|
|
29
|
+
duration?: number;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* A stroke that starts on an edge of the screen and comes inward, as for a side drawer or a sheet
|
|
33
|
+
* that is pulled up from the bottom. It starts `inset` pixels from the edge, 2 by default.
|
|
34
|
+
*
|
|
35
|
+
* On a real phone the outermost strip of the screen belongs to the system: in Safari on an iPhone a
|
|
36
|
+
* stroke from the left or right edge goes back or forward in history and the page never sees it,
|
|
37
|
+
* as under a real finger. To reach a drawer of the page there, start further in. On an iPhone 12
|
|
38
|
+
* Pro with iOS 17.5 a start 2 px from the left edge went back and one 6 px from it reached the
|
|
39
|
+
* page; `inset: 20` leaves room.
|
|
40
|
+
*/
|
|
41
|
+
export declare function edgeSwipe(page: AnyPage, options: {
|
|
42
|
+
edge: 'left' | 'right' | 'top' | 'bottom';
|
|
43
|
+
distance?: number;
|
|
44
|
+
duration?: number;
|
|
45
|
+
inset?: number;
|
|
46
|
+
}): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Two fingers moving side by side, for maps and embeds that keep one finger for the page and ask
|
|
49
|
+
* for two to move themselves.
|
|
50
|
+
*/
|
|
51
|
+
export declare function twoFingerSwipe(target: AnyPage | AnyLocator, options: {
|
|
52
|
+
direction: Direction;
|
|
53
|
+
distance?: number;
|
|
54
|
+
gap?: number;
|
|
55
|
+
duration?: number;
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
export {};
|
package/dist/recipes.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Gestures named after what a person is doing, built from the plain ones: swipe until something is
|
|
2
|
+
// in view, pull down to refresh, come in from an edge, move with two fingers. Each works on a
|
|
3
|
+
// Playwright page in Chromium and on Safari, because each is made of `swipe` and `gesture`.
|
|
4
|
+
import { gesture, swipe } from './index.js';
|
|
5
|
+
const isSafariLocator = (target) => !!target && target.ios === true && typeof target.selector === 'string';
|
|
6
|
+
const pageOf = (target) => (isSafariLocator(target) ? target.page : target.page());
|
|
7
|
+
/** Runs a script given as text, which is the one form every kind of page takes. */
|
|
8
|
+
const run = (page, script) => page.evaluate(script);
|
|
9
|
+
const UNIT = {
|
|
10
|
+
up: { x: 0, y: -1 },
|
|
11
|
+
down: { x: 0, y: 1 },
|
|
12
|
+
left: { x: -1, y: 0 },
|
|
13
|
+
right: { x: 1, y: 0 },
|
|
14
|
+
};
|
|
15
|
+
const RECT = '((r) => r && ({ x: r.x, y: r.y, width: r.width, height: r.height }))';
|
|
16
|
+
const viewOf = async (page) => ({
|
|
17
|
+
x: 0,
|
|
18
|
+
y: 0,
|
|
19
|
+
...(await run(page, '({ width: innerWidth, height: innerHeight })')),
|
|
20
|
+
});
|
|
21
|
+
/** Where an element is in the viewport, or null while it is not on the page. */
|
|
22
|
+
async function boxOf(target) {
|
|
23
|
+
if (isSafariLocator(target)) {
|
|
24
|
+
const selector = JSON.stringify(target.selector);
|
|
25
|
+
return run(target.page, `${RECT}(document.querySelector(${selector}) && document.querySelector(${selector}).getBoundingClientRect())`);
|
|
26
|
+
}
|
|
27
|
+
// An element that is not there yet must not hold the loop up: lists often add it while scrolling.
|
|
28
|
+
const counted = target;
|
|
29
|
+
if (typeof counted.count === 'function' && (await counted.count()) === 0)
|
|
30
|
+
return null;
|
|
31
|
+
return target.evaluate((element) => {
|
|
32
|
+
const r = element.getBoundingClientRect();
|
|
33
|
+
return { x: r.x, y: r.y, width: r.width, height: r.height };
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** How far a page or a scrolling element has moved, as text that changes when it moves. */
|
|
37
|
+
async function positionOf(page, within) {
|
|
38
|
+
if (!within)
|
|
39
|
+
return run(page, '`${scrollX},${scrollY}`');
|
|
40
|
+
if (isSafariLocator(within)) {
|
|
41
|
+
return run(page, `((e) => e ? e.scrollLeft + ',' + e.scrollTop : '')(document.querySelector(${JSON.stringify(within.selector)}))`);
|
|
42
|
+
}
|
|
43
|
+
return within.evaluate((element) => `${element.scrollLeft},${element.scrollTop}`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Swipes until the middle of the target is inside the viewport, the way a person scrolls a list to
|
|
47
|
+
* find a row. Returns the number of swipes it took, 0 when the target was in view already. Fails
|
|
48
|
+
* when the content stops moving or the tries run out, and says which.
|
|
49
|
+
*/
|
|
50
|
+
export async function swipeUntilVisible(target, options = {}) {
|
|
51
|
+
const page = pageOf(target);
|
|
52
|
+
const { direction = 'up', within, distance, max = 10 } = options;
|
|
53
|
+
const inView = async () => {
|
|
54
|
+
const [box, view] = [await boxOf(target), await viewOf(page)];
|
|
55
|
+
if (!box || box.width === 0 || box.height === 0)
|
|
56
|
+
return false;
|
|
57
|
+
const middle = { x: box.x + box.width / 2, y: box.y + box.height / 2 };
|
|
58
|
+
return middle.x >= 0 && middle.x <= view.width && middle.y >= 0 && middle.y <= view.height;
|
|
59
|
+
};
|
|
60
|
+
const settled = () => new Promise((resolve) => setTimeout(resolve, 250));
|
|
61
|
+
for (let swipes = 0;; swipes++) {
|
|
62
|
+
if (await inView())
|
|
63
|
+
return swipes;
|
|
64
|
+
if (swipes === max) {
|
|
65
|
+
throw new Error(`playwright-touch: the target was not in view after ${max} swipe${max === 1 ? '' : 's'} ${direction}. Raise \`max\`, or check the direction.`);
|
|
66
|
+
}
|
|
67
|
+
const before = await positionOf(page, within);
|
|
68
|
+
await swipe(within ?? page, { direction, ...(distance === undefined ? {} : { distance }) });
|
|
69
|
+
await settled();
|
|
70
|
+
if ((await positionOf(page, within)) === before && !(await inView())) {
|
|
71
|
+
throw new Error(`playwright-touch: the content stopped moving after ${swipes + 1} swipe${swipes ? 's' : ''} ${direction} and the target is not in view. It may be the other way, or in another scrolling element (\`within\`).`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Pulls the page down from near its top, the gesture behind "pull to refresh". The finger comes to
|
|
77
|
+
* rest before it lifts, as a thumb does. The page should be scrolled to its top first.
|
|
78
|
+
*/
|
|
79
|
+
export async function pullToRefresh(page, options = {}) {
|
|
80
|
+
const view = await viewOf(page);
|
|
81
|
+
const from = { x: view.width / 2, y: view.height * 0.2 };
|
|
82
|
+
const distance = options.distance ?? view.height * 0.5;
|
|
83
|
+
await swipe(page, { from, to: { x: from.x, y: from.y + distance }, duration: options.duration ?? 600 });
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A stroke that starts on an edge of the screen and comes inward, as for a side drawer or a sheet
|
|
87
|
+
* that is pulled up from the bottom. It starts `inset` pixels from the edge, 2 by default.
|
|
88
|
+
*
|
|
89
|
+
* On a real phone the outermost strip of the screen belongs to the system: in Safari on an iPhone a
|
|
90
|
+
* stroke from the left or right edge goes back or forward in history and the page never sees it,
|
|
91
|
+
* as under a real finger. To reach a drawer of the page there, start further in. On an iPhone 12
|
|
92
|
+
* Pro with iOS 17.5 a start 2 px from the left edge went back and one 6 px from it reached the
|
|
93
|
+
* page; `inset: 20` leaves room.
|
|
94
|
+
*/
|
|
95
|
+
export async function edgeSwipe(page, options) {
|
|
96
|
+
const view = await viewOf(page);
|
|
97
|
+
const inset = options.inset ?? 2;
|
|
98
|
+
const inward = { left: 'right', right: 'left', top: 'down', bottom: 'up' };
|
|
99
|
+
const unit = UNIT[inward[options.edge]];
|
|
100
|
+
const from = {
|
|
101
|
+
x: options.edge === 'left' ? inset : options.edge === 'right' ? view.width - inset : view.width / 2,
|
|
102
|
+
y: options.edge === 'top' ? inset : options.edge === 'bottom' ? view.height - inset : view.height / 2,
|
|
103
|
+
};
|
|
104
|
+
const distance = options.distance ?? (unit.x !== 0 ? view.width : view.height) * 0.6;
|
|
105
|
+
await swipe(page, {
|
|
106
|
+
from,
|
|
107
|
+
to: { x: from.x + unit.x * distance, y: from.y + unit.y * distance },
|
|
108
|
+
...(options.duration === undefined ? {} : { duration: options.duration }),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Two fingers moving side by side, for maps and embeds that keep one finger for the page and ask
|
|
113
|
+
* for two to move themselves.
|
|
114
|
+
*/
|
|
115
|
+
export async function twoFingerSwipe(target, options) {
|
|
116
|
+
const onElement = isSafariLocator(target) || typeof target.boundingBox === 'function';
|
|
117
|
+
const page = onElement ? pageOf(target) : target;
|
|
118
|
+
const box = onElement ? await boxOf(target) : await viewOf(page);
|
|
119
|
+
if (!box)
|
|
120
|
+
throw new Error('playwright-touch: the element for a two-finger swipe is not on the page.');
|
|
121
|
+
const unit = UNIT[options.direction];
|
|
122
|
+
const distance = options.distance ?? (unit.x !== 0 ? box.width : box.height) * 0.5;
|
|
123
|
+
const gap = options.gap ?? 80;
|
|
124
|
+
const middle = { x: box.x + box.width / 2, y: box.y + box.height / 2 };
|
|
125
|
+
// The fingers sit across the direction of travel, half the gap to each side of the middle.
|
|
126
|
+
const across = { x: unit.y, y: unit.x };
|
|
127
|
+
const finger = (side) => {
|
|
128
|
+
const start = {
|
|
129
|
+
x: middle.x + (across.x * side * gap) / 2 - (unit.x * distance) / 2,
|
|
130
|
+
y: middle.y + (across.y * side * gap) / 2 - (unit.y * distance) / 2,
|
|
131
|
+
};
|
|
132
|
+
return [start, { x: start.x + unit.x * distance, y: start.y + unit.y * distance }];
|
|
133
|
+
};
|
|
134
|
+
await gesture(page, { fingers: [finger(1), finger(-1)], duration: options.duration ?? 400 });
|
|
135
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Page } from './session.js';
|
|
2
|
+
import type { Point } from './types.js';
|
|
3
|
+
/** The engine behind a page: `chromium`, `webkit` or `firefox`. A page that cannot say is taken for Chromium. */
|
|
4
|
+
export declare function engineOf(page: Page): string;
|
|
5
|
+
/** True when gestures on this page are events made by script and not the browser's own touch input. */
|
|
6
|
+
export declare const isSynthetic: (page: Page) => boolean;
|
|
7
|
+
export interface Frame {
|
|
8
|
+
/** Milliseconds after the fingers land. */
|
|
9
|
+
at: number;
|
|
10
|
+
points: Point[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Plays a gesture as script-made events: the fingers land on the first frame, move through the
|
|
14
|
+
* rest on the page's own clock and lift after the last. `then` adds what a browser adds after a
|
|
15
|
+
* tap.
|
|
16
|
+
*/
|
|
17
|
+
export declare function performSynthetic(page: Page, frames: Frame[], then?: 'click' | 'dblclick'): Promise<void>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
const engines = new WeakMap();
|
|
2
|
+
/** The engine behind a page: `chromium`, `webkit` or `firefox`. A page that cannot say is taken for Chromium. */
|
|
3
|
+
export function engineOf(page) {
|
|
4
|
+
let engine = engines.get(page);
|
|
5
|
+
if (!engine) {
|
|
6
|
+
try {
|
|
7
|
+
engine = page.context().browser?.()?.browserType().name() ?? 'chromium';
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
engine = 'chromium';
|
|
11
|
+
}
|
|
12
|
+
engines.set(page, engine);
|
|
13
|
+
}
|
|
14
|
+
return engine;
|
|
15
|
+
}
|
|
16
|
+
/** True when gestures on this page are events made by script and not the browser's own touch input. */
|
|
17
|
+
export const isSynthetic = (page) => engineOf(page) !== 'chromium';
|
|
18
|
+
const warned = new Set();
|
|
19
|
+
function warnOnce(engine) {
|
|
20
|
+
if (warned.has(engine) || process.env.PLAYWRIGHT_TOUCH_QUIET)
|
|
21
|
+
return;
|
|
22
|
+
warned.add(engine);
|
|
23
|
+
const name = engine === 'webkit' ? 'WebKit' : engine === 'firefox' ? 'Firefox' : engine;
|
|
24
|
+
process.stderr.write(`playwright-touch: ${name} has no touch input for Playwright, so gestures are sent as events made by script. ` +
|
|
25
|
+
'Handlers on the page run; the browser does not scroll, coast or zoom. Set PLAYWRIGHT_TOUCH_QUIET=1 to hide this.\n');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Plays a gesture as script-made events: the fingers land on the first frame, move through the
|
|
29
|
+
* rest on the page's own clock and lift after the last. `then` adds what a browser adds after a
|
|
30
|
+
* tap.
|
|
31
|
+
*/
|
|
32
|
+
export async function performSynthetic(page, frames, then) {
|
|
33
|
+
warnOnce(engineOf(page));
|
|
34
|
+
await page.evaluate(async ({ frames, then }) => {
|
|
35
|
+
const first = frames[0].points;
|
|
36
|
+
const targets = first.map((p) => document.elementFromPoint(p.x, p.y) ?? document.body);
|
|
37
|
+
const touchOf = (p, id) => {
|
|
38
|
+
const init = {
|
|
39
|
+
identifier: id,
|
|
40
|
+
target: targets[id],
|
|
41
|
+
clientX: p.x,
|
|
42
|
+
clientY: p.y,
|
|
43
|
+
pageX: p.x + scrollX,
|
|
44
|
+
pageY: p.y + scrollY,
|
|
45
|
+
screenX: p.x,
|
|
46
|
+
screenY: p.y,
|
|
47
|
+
radiusX: 8,
|
|
48
|
+
radiusY: 8,
|
|
49
|
+
force: 1,
|
|
50
|
+
};
|
|
51
|
+
try {
|
|
52
|
+
return new Touch(init);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// WebKit on a desktop has no Touch to construct. Handlers read the same fields off this.
|
|
56
|
+
return init;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const touch = (type, down, changed) => {
|
|
60
|
+
for (const target of new Set(changed.map((t) => t.target))) {
|
|
61
|
+
const lists = {
|
|
62
|
+
touches: down,
|
|
63
|
+
targetTouches: down.filter((t) => t.target === target),
|
|
64
|
+
changedTouches: changed.filter((t) => t.target === target),
|
|
65
|
+
};
|
|
66
|
+
let event;
|
|
67
|
+
try {
|
|
68
|
+
event = new TouchEvent(type, { bubbles: true, cancelable: true, composed: true, ...lists });
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
event = new UIEvent(type, { bubbles: true, cancelable: true, composed: true, view: window });
|
|
72
|
+
for (const [name, value] of Object.entries(lists))
|
|
73
|
+
Object.defineProperty(event, name, { value });
|
|
74
|
+
}
|
|
75
|
+
target.dispatchEvent(event);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const pointer = (type, p, id) => targets[id].dispatchEvent(new PointerEvent(type, {
|
|
79
|
+
pointerId: id + 2,
|
|
80
|
+
pointerType: 'touch',
|
|
81
|
+
isPrimary: id === 0,
|
|
82
|
+
clientX: p.x,
|
|
83
|
+
clientY: p.y,
|
|
84
|
+
screenX: p.x,
|
|
85
|
+
screenY: p.y,
|
|
86
|
+
bubbles: true,
|
|
87
|
+
cancelable: true,
|
|
88
|
+
composed: true,
|
|
89
|
+
button: type === 'pointermove' ? -1 : 0,
|
|
90
|
+
buttons: type === 'pointerup' ? 0 : 1,
|
|
91
|
+
pressure: type === 'pointerup' ? 0 : 0.5,
|
|
92
|
+
width: 16,
|
|
93
|
+
height: 16,
|
|
94
|
+
}));
|
|
95
|
+
const mouse = (type, p, detail) => targets[0].dispatchEvent(new MouseEvent(type, { clientX: p.x, clientY: p.y, bubbles: true, cancelable: true, composed: true, detail }));
|
|
96
|
+
const started = performance.now();
|
|
97
|
+
let last = first;
|
|
98
|
+
first.forEach((p, id) => pointer('pointerdown', p, id));
|
|
99
|
+
const landed = first.map(touchOf);
|
|
100
|
+
touch('touchstart', landed, landed);
|
|
101
|
+
for (const frame of frames.slice(1)) {
|
|
102
|
+
const wait = started + frame.at - performance.now();
|
|
103
|
+
if (wait > 0)
|
|
104
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
105
|
+
last = frame.points;
|
|
106
|
+
last.forEach((p, id) => pointer('pointermove', p, id));
|
|
107
|
+
const moved = last.map(touchOf);
|
|
108
|
+
touch('touchmove', moved, moved);
|
|
109
|
+
}
|
|
110
|
+
last.forEach((p, id) => pointer('pointerup', p, id));
|
|
111
|
+
touch('touchend', [], last.map(touchOf));
|
|
112
|
+
if (then)
|
|
113
|
+
mouse('click', last[0], then === 'dblclick' ? 2 : 1);
|
|
114
|
+
if (then === 'dblclick')
|
|
115
|
+
mouse('dblclick', last[0], 2);
|
|
116
|
+
}, { frames, then });
|
|
117
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playwright-touch",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Real touch for browser tests: tap, swipe, fling with momentum, drag, long press and
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Real touch for browser tests: tap, swipe, fling with momentum, drag, long press, pinch and rotate in Chrome and Safari, on an emulated phone, a real Android phone or an iPhone, as functions or as a Playwright Test fixture, with measurements taken on the device.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"android",
|
|
7
7
|
"drag",
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
".": {
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
31
|
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./test": {
|
|
34
|
+
"types": "./dist/playwright-test.d.ts",
|
|
35
|
+
"default": "./dist/playwright-test.js"
|
|
32
36
|
}
|
|
33
37
|
},
|
|
34
38
|
"types": "./dist/index.d.ts",
|
|
@@ -48,12 +52,23 @@
|
|
|
48
52
|
"lint": "prettier --check ."
|
|
49
53
|
},
|
|
50
54
|
"peerDependencies": {
|
|
55
|
+
"@playwright/test": ">=1.40.0",
|
|
51
56
|
"playwright-core": ">=1.40.0"
|
|
52
57
|
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"@playwright/test": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
53
63
|
"devDependencies": {
|
|
64
|
+
"@playwright/test": "^1.65.2",
|
|
54
65
|
"@types/node": "^26.6.6",
|
|
66
|
+
"embla-carousel": "^8.6.0",
|
|
67
|
+
"hammerjs": "^2.0.10",
|
|
68
|
+
"leaflet": "^1.9.4",
|
|
55
69
|
"playwright-core": "^1.65.1",
|
|
56
70
|
"prettier": "^3.10.1",
|
|
71
|
+
"swiper": "^14.5.0",
|
|
57
72
|
"typescript": "^7.0.2"
|
|
58
73
|
},
|
|
59
74
|
"repository": {
|