Skip to content

Instantly share code, notes, and snippets.

@edbond
Last active December 4, 2019 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edbond/4d67ff2503ee4aebbde82e8fc2fb2cc1 to your computer and use it in GitHub Desktop.
Save edbond/4d67ff2503ee4aebbde82e8fc2fb2cc1 to your computer and use it in GitHub Desktop.
import 'package:puppeteer/puppeteer.dart';
import "package:test/test.dart";
cityAutocomplete(Browser browser) {
test("City Autocomplete include New York", () async {
// Open a new tab
var page = await browser.newPage();
// Go to a page and wait to be fully loaded
await page.goto(...);
await page.waitForSelector(".angucomplete-title");
// Find "New York" in autocomplete results
// Get city lookup results from autocomplete popup
List<dynamic> titles = await page.$$eval(
".angucomplete-title", 'titles => titles.map(t => t.innerText)');
await expect(titles, contains("New York, NY"));
await page.close();
});
}
import 'dart:io';
import 'package:puppeteer/puppeteer.dart';
import 'city_autocomplete.dart';
main() async {
// Download the Chromium binaries, launch it and connect to the "DevTools"
var browser = await puppeteer.launch(headless: false);
cityAutocomplete(browser);
print("sleep starts");
sleep(Duration(seconds: 5));
print("sleep complete");
// Gracefully close the browser's process
await browser.close();
}
▶ dart src/main.dart
sleep starts
sleep complete
00:00 +0: City Autocomplete include New York
00:00 +0 -1: City Autocomplete include New York [E]
TargetClosedException(method: Target.createTarget, reason: Websocket.done(code: 1002, reason: null))
package:puppeteer/protocol/target.dart 141:18 TargetApi.createTarget
===== asynchronous gap ===========================
dart:async/zone.dart 1062:19 _CustomZone.registerBinaryCallback
dart:async-patch/async_patch.dart 80:23 _asyncErrorWrapperHelper
package:test_api/src/backend/invoker.dart Invoker.waitForOutstandingCallbacks.<fn>
dart:async/zone.dart 1124:13 _rootRun
dart:async/zone.dart 1021:19 _CustomZone.run
dart:async/zone.dart 1516:10 _runZoned
dart:async/zone.dart 1463:12 runZoned
package:test_api/src/backend/invoker.dart 239:5 Invoker.waitForOutstandingCallbacks
package:test_api/src/backend/declarer.dart 169:33 Declarer.test.<fn>.<fn>
dart:async/zone.dart 1124:13 _rootRun
dart:async/zone.dart 1021:19 _CustomZone.run
dart:async/zone.dart 1516:10 _runZoned
dart:async/zone.dart 1463:12 runZoned
package:test_api/src/backend/declarer.dart 168:13 Declarer.test.<fn>
===== asynchronous gap ===========================
dart:async/zone.dart 1045:19 _CustomZone.registerCallback
dart:async/zone.dart 962:22 _CustomZone.bindCallbackGuarded
dart:async/timer.dart 52:45 new Timer
dart:async/timer.dart 87:9 Timer.run
dart:async/future.dart 174:11 new Future
package:test_api/src/backend/invoker.dart 391:21 Invoker._onRun.<fn>.<fn>.<fn>
00:00 +0 -1: Some tests failed.
Unhandled exception:
Dummy exception to set exit code.
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1112:29)
#1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#3 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:391:30)
#4 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
#5 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment