Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export class AndroidInput implements api.AndroidInput {
}

async swipe(from: types.Point, segments: types.Point[], steps: number) {
await this._device._channel.inputSwipe({ segments, steps }, kNoTimeout);
await this._device._channel.inputSwipe({ segments: [from, ...segments], steps }, kNoTimeout);
}

async drag(from: types.Point, to: types.Point, steps: number) {
Expand Down
31 changes: 31 additions & 0 deletions tests/android/input.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright 2020 Microsoft Corporation. All rights reserved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not 2020 anymore, look at other files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, copied it from the older files in this folder. Changed to the Copyright (c) Microsoft Corporation. header in 6de3e90.

*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { androidTest as test, expect } from './androidTest';

test('androidInput.swipe should start from the given point', async ({ androidDevice }) => {
const context = await androidDevice.launchBrowser();
const [page] = context.pages();
await page.setContent(`<div style="height: 3000px">${'line<br>'.repeat(200)}</div>`);
// androidDevice.input.swipe() injects a raw touch event straight into the OS input
// pipeline, independent of the CDP connection used by setContent() above. Wait for
// the new content to actually be composited and presented on the device screen,
// otherwise the swipe can land on the previous (blank) frame and never scroll anything.
await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use rafraf from ../config/utils. I doubt this will help though, if the test is still flaky, let's revert it and keep just the fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to rafraf in 6de3e90.

Worth noting the wait has never actually run on the emulator. The only Android job on this branch is run 32510988871, which built c658786, before the wait existed. tests 2 starts only on the labeled event, so the pushes after the CQ1 label did not re-trigger it. So there is no evidence yet either way.

If you re-apply CQ1 and it still fails, I will drop the test and leave only the fix.

await androidDevice.input.swipe({ x: 250, y: 1500 }, [{ x: 250, y: 500 }], 30);
await expect.poll(() => page.evaluate(() => window.scrollY)).toBeGreaterThan(0);
await context.close();
});