Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade package:puppeteer in pkg/pub_integration #7211

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
38 changes: 38 additions & 0 deletions pkg/pub_integration/lib/src/pub_puppeteer_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:io';

import 'package:puppeteer/puppeteer.dart';

Expand Down Expand Up @@ -45,6 +46,10 @@ Future<ListingPageInfo> listingPageInfo(Page page) async {
}

extension PubPageExt on Page {
Future<void> saveScreenshot(String path) async {
await File(path).writeAsBytes(await screenshot());
}

Future<void> waitFocusAndType(String selector, String text) async {
await waitForSelector(selector, timeout: Duration(seconds: 5));
await focus(selector);
Expand Down Expand Up @@ -187,6 +192,39 @@ extension PubPageExt on Page {
await _waitForModelHidden();
}

/// Waits until the given selectors are visible and their UI top-left position
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds completely crazy that we have to make a hack like this. Should this not be built into the framework somehow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is a side-effect of the material widgets we are using. I've never seen similar issue with regular HTML checkboxes.

/// differs.
Future<void> waitForLayout(
List<String> selectors, {
Duration timeout = const Duration(seconds: 5),
}) async {
final sw = Stopwatch()..start();
final handles = await Future.wait(
selectors.map((e) => waitForSelector(e, timeout: timeout)));
while (sw.elapsed < timeout) {
final positions =
await Future.wait(handles.map((e) async => (await e!.boundingBox)!));
bool hasSamePosition = false;
for (var i = 0; i < positions.length; i++) {
for (var j = i + 1; j < positions.length; j++) {
if (positions[i].topLeft == positions[j].topLeft) {
hasSamePosition = true;
break;
}
}
if (hasSamePosition) break;
}
if (hasSamePosition) {
await Future.delayed(Duration(milliseconds: 25));
continue;
} else {
return;
}
}
await saveScreenshot('layout-timeout.png');
throw TimeoutException('Did not have a stable layout in $timeout.');
}

Future<void> waitAndClick(
String selector, {
bool? waitForOneResponse,
Expand Down
34 changes: 21 additions & 13 deletions pkg/pub_integration/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ packages:
dependency: transitive
description:
name: built_value
sha256: "723b4021e903217dfc445ec4cf5b42e27975aece1fc4ebbc1ca6329c2d9fb54e"
sha256: "69acb7007eb2a31dc901512bfe0f7b767168be34cb734835d54c070bfa74c1b2"
url: "https://pub.dev"
source: hosted
version: "8.7.0"
version: "8.8.0"
checked_yaml:
dependency: transitive
description:
Expand All @@ -107,10 +107,10 @@ packages:
dependency: transitive
description:
name: code_builder
sha256: "1be9be30396d7e4c0db42c35ea6ccd7cc6a1e19916b5dc64d6ac216b5544d677"
sha256: b2151ce26a06171005b379ecff6e08d34c470180ffe16b8e14b6d52be292b55f
url: "https://pub.dev"
source: hosted
version: "4.7.0"
version: "4.8.0"
collection:
dependency: transitive
description:
Expand Down Expand Up @@ -155,10 +155,10 @@ packages:
dependency: transitive
description:
name: dart_style
sha256: abd7625e16f51f554ea244d090292945ec4d4be7bfbaf2ec8cccea568919d334
sha256: "40ae61a5d43feea6d24bd22c0537a6629db858963b99b4bc1c3db80676f32368"
url: "https://pub.dev"
source: hosted
version: "2.3.3"
version: "2.3.4"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -203,10 +203,10 @@ packages:
dependency: "direct main"
description:
name: http
sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525"
sha256: d4872660c46d929f6b8a9ef4e7a7eff7e49bbf0c4ec3f385ee32df5119175139
url: "https://pub.dev"
source: hosted
version: "1.1.0"
version: "1.1.2"
http_methods:
dependency: transitive
description:
Expand Down Expand Up @@ -323,10 +323,10 @@ packages:
dependency: transitive
description:
name: petitparser
sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750
sha256: eeb2d1428ee7f4170e2bd498827296a18d4e7fc462b71727d111c0ac7707cfa6
url: "https://pub.dev"
source: hosted
version: "5.4.0"
version: "6.0.1"
pointycastle:
dependency: transitive
description:
Expand Down Expand Up @@ -363,10 +363,10 @@ packages:
dependency: "direct main"
description:
name: puppeteer
sha256: dd49117259867d0ce0de33ddd95628fb70cff94581a6432c08272447b8dd1d27
sha256: eedeaae6ec5d2e54f9ae22ab4d6b3dda2e8791c356cc783046d06c287ffe11d8
url: "https://pub.dev"
source: hosted
version: "2.24.0"
version: "3.6.0"
sanitize_html:
dependency: transitive
description:
Expand Down Expand Up @@ -543,6 +543,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:
name: web
sha256: edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa
url: "https://pub.dev"
source: hosted
version: "0.4.0"
web_socket_channel:
dependency: transitive
description:
Expand All @@ -568,4 +576,4 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.2.0 <4.0.0"
5 changes: 1 addition & 4 deletions pkg/pub_integration/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ dependencies:
http: ^1.0.0
path: ^1.8.0
pub_semver: ^2.0.0
puppeteer: ^2.24.0
puppeteer: ^3.6.0
oauth2: ^2.0.0

dev_dependencies:
coverage: any # test already depends on it
test: ^1.16.5

dependency_overrides:
http: ^1.0.0
4 changes: 4 additions & 0 deletions pkg/pub_integration/test/pkg_admin_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ void main() {
await page.gotoOrigin('/packages/test_pkg/admin');

await page.waitAndClick('#-pkg-admin-automated-github-enabled');
await page.waitForLayout([
'#-pkg-admin-automated-github-repository',
'#-pkg-admin-automated-github-tagpattern',
]);
await page.waitFocusAndType(
'#-pkg-admin-automated-github-repository', 'dart-lang/pub-dev');
await page.waitAndClick('#-pkg-admin-automated-button',
Expand Down
6 changes: 5 additions & 1 deletion pkg/pub_integration/test/search_update_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ void main() {

// show hidden
await page.click('.search-form-section[data-section-tag="advanced"]');
await page.waitAndClick('#search-form-checkbox-show-unlisted');
await page.waitForLayout([
'#search-form-checkbox-is-flutter-favorite',
'#search-form-checkbox-show-unlisted'
]);
await page.click('#search-form-checkbox-show-unlisted');
await page.waitForNavigation(wait: Until.networkIdle);
final i7 = await listingPageInfo(page);
expect(i7.totalCount, i6.totalCount);
Expand Down