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 = | |
73 await Process.run('pub', ['upgrade'], workingDirectory: directory); | |
74 if (result.exitCode != 0) { | |
75 throw new StateError('Pub get failed: ${result.stderr}'); | |
76 } | |
77 return ChildServerProcess.build( | |
78 (host, port) => Process.start( | |
79 'pub', ['serve', '--hostname=$host', '--port=$port']..addAll(args), | |
80 mode: ProcessStartMode.DETACHED_WITH_STDIO, | |
81 workingDirectory: directory), | |
82 defaultPort: 8080); | |
83 } | |
84 | |
85 const _webDriverManagerPath = './node_modules/.bin/webdriver-manager'; | |
86 Future<ChildServerProcess> _startSelenium() async { | |
87 var result = await Process.run(_webDriverManagerPath, ['update']); | |
88 if (result.exitCode != 0) { | |
89 throw new StateError('Webdriver update failed: ${result.stderr}'); | |
90 } | |
91 return ChildServerProcess.build( | |
92 (host, port) => Process.start( | |
93 _webDriverManagerPath, ['start', '--seleniumPort=$port'], | |
94 mode: ProcessStartMode.DETACHED_WITH_STDIO), | |
95 defaultPort: 4444); | |
96 } | |
OLD | NEW |