OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:async'; |
| 6 import 'dart:io'; |
| 7 |
| 8 @Timeout(const Duration(seconds: 60)) |
| 9 import 'package:test/test.dart'; |
| 10 import 'package:webdriver/webdriver.dart' show By, Capabilities, WebDriver; |
| 11 |
| 12 import 'child_server_process.dart'; |
| 13 |
| 14 main() { |
| 15 group('DDC transformer in pub serve', () { |
| 16 WebDriver webdriver; |
| 17 ChildServerProcess selenium; |
| 18 ChildServerProcess pubServe; |
| 19 |
| 20 setUp(() async { |
| 21 // Start pub serve straight away and don't wait for it yet. |
| 22 var pubServeFut = |
| 23 _startPubServe('test/transformer/hello_app', ['--verbose']); |
| 24 |
| 25 // Start selenium and wait for it to be ready. |
| 26 stderr.writeln("# [e2e] Awaiting Selenium..."); |
| 27 selenium = await _startSelenium(); |
| 28 stderr.writeln("# [e2e] Got Selenium!"); |
| 29 var seleniumUrl = '${selenium.httpUri}/wd/hub'; |
| 30 |
| 31 stderr.writeln("# [e2e] Awaiting WebDriver..."); |
| 32 var capabilities = { |
| 33 'browserName': 'chrome', |
| 34 "maxInstances": 1, |
| 35 "seleniumProtocol": "WebDriver", |
| 36 'loggingPrefs': {'browser': 'ALL'} |
| 37 }; |
| 38 var chromeBin = Platform.environment['CHROME_CANARY_BIN']; |
| 39 if (chromeBin != null) { |
| 40 capabilities['chromeOptions'] = { |
| 41 'binary': chromeBin, |
| 42 'args': ['--no-sandbox'], |
| 43 }; |
| 44 } |
| 45 webdriver = await WebDriver.createDriver( |
| 46 url: seleniumUrl, desiredCapabilities: capabilities); |
| 47 stderr.writeln("# [e2e] Got WebDriver!"); |
| 48 |
| 49 stderr.writeln("# [e2e] Awaiting Pub Serve..."); |
| 50 pubServe = await pubServeFut; |
| 51 stderr.writeln("# [e2e] Got Pub Serve!"); |
| 52 }); |
| 53 |
| 54 tearDown(() async { |
| 55 selenium?.process?.kill(); |
| 56 pubServe?.process?.kill(); |
| 57 await webdriver?.quit(); |
| 58 }); |
| 59 |
| 60 test('serves functional hello world app', () async { |
| 61 await webdriver.get('${pubServe.httpUri}/hello_app/web/'); |
| 62 |
| 63 var body = await webdriver.findElement(const By.tagName('body')); |
| 64 expect(await body.text, "'Hello, World!'"); |
| 65 }); |
| 66 }); |
| 67 } |
| 68 |
| 69 Future<ChildServerProcess> _startPubServe(String directory, |
| 70 [List<String> args = const []]) async { |
| 71 assert(new Directory(directory).existsSync()); |
| 72 var result = await Process.run('pub', ['get'], workingDirectory: directory); |
| 73 if (result.exitCode != 0) { |
| 74 throw new StateError('Pub get failed: ${result.stderr}'); |
| 75 } |
| 76 return ChildServerProcess.build( |
| 77 (host, port) => Process.start( |
| 78 'pub', ['serve', '--hostname=$host', '--port=$port']..addAll(args), |
| 79 mode: ProcessStartMode.DETACHED_WITH_STDIO, |
| 80 workingDirectory: directory), |
| 81 defaultPort: 8080); |
| 82 } |
| 83 |
| 84 const _webDriverManagerPath = './node_modules/.bin/webdriver-manager'; |
| 85 Future<ChildServerProcess> _startSelenium() async { |
| 86 var result = await Process.run(_webDriverManagerPath, ['update']); |
| 87 if (result.exitCode != 0) { |
| 88 throw new StateError('Webdriver update failed: ${result.stderr}'); |
| 89 } |
| 90 return ChildServerProcess.build( |
| 91 (host, port) => Process.start( |
| 92 _webDriverManagerPath, ['start', '--seleniumPort=$port'], |
| 93 mode: ProcessStartMode.DETACHED_WITH_STDIO), |
| 94 defaultPort: 4444); |
| 95 } |
OLD | NEW |