Skip to content

Commit 73bf811

Browse files
committed
feat: restore locator.swipe() with tracer support
1 parent 2575c26 commit 73bf811

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

packages/mobilewright-core/src/locator.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,24 @@ test.describe('Locator', () => {
136136
});
137137
});
138138

139+
test.describe('swipe', () => {
140+
test('swipes from element center in the given direction', async () => {
141+
const driver = createMockDriver(hierarchy);
142+
const locator = new Locator(driver, { kind: 'label', value: 'Submit' });
143+
144+
await locator.swipe({ direction: 'left' });
145+
146+
expect(driver._tracker.swipeCalls).toEqual([['left', { startX: 120, startY: 125 }]]);
147+
});
148+
149+
test('throws LocatorError when element not found', async () => {
150+
const driver = createMockDriver(hierarchy);
151+
const locator = new Locator(driver, { kind: 'label', value: 'Nonexistent' }, { timeout: 200 });
152+
153+
await expect(locator.swipe({ direction: 'left' })).rejects.toThrow(LocatorError);
154+
});
155+
});
156+
139157
test.describe('fill', () => {
140158
test('taps to focus then types text', async () => {
141159
const driver = createMockDriver(hierarchy);

packages/mobilewright-core/src/locator.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ export class Locator {
160160
});
161161
}
162162

163+
async swipe(opts: { direction: SwipeDirection; timeout?: number }): Promise<void> {
164+
return this._wrapAction('swipe', { direction: opts.direction }, async () => {
165+
const node = await this.resolveActionable(opts.timeout);
166+
const { x, y } = centerOf(node.bounds);
167+
await this.driver.swipe(opts.direction, { startX: x, startY: y });
168+
});
169+
}
170+
163171
async scrollIntoViewIfNeeded(opts?: ScrollIntoViewOptions): Promise<void> {
164172
return this._wrapAction('scrollIntoViewIfNeeded', { direction: opts?.direction, maxSwipes: opts?.maxSwipes }, async () => {
165173
const maxSwipes = opts?.maxSwipes ?? 10;

0 commit comments

Comments
 (0)