mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Fix: use --web-launch-url and --web-hostname arguments in flutter drive (#131763)
Implement expected functionalities when supplying `--web-launch-url` and/or `--web-hostname` arguments to `flutter drive`. - `--web-launch-url` now sets the starting url for the (headless) browser - Which for example means you can start at a certain part of the app at the start of your integration test - `--web-hostname` now sets the hostname where the target of flutter drive will be hosted - Which allows you to set something other than localhost (allowing access via a reverse-proxy for example) Fixes #118028
This commit is contained in:
parent
4d42f1a852
commit
82e2de0650
@ -1,3 +1,2 @@
|
|||||||
lib/generated_plugin_registrant.dart
|
|
||||||
vmservice.out
|
vmservice.out
|
||||||
*.sksl.json
|
*.sksl.json
|
||||||
|
@ -41,6 +41,9 @@ class WebDriverService extends DriverService {
|
|||||||
late ResidentRunner _residentRunner;
|
late ResidentRunner _residentRunner;
|
||||||
Uri? _webUri;
|
Uri? _webUri;
|
||||||
|
|
||||||
|
@visibleForTesting
|
||||||
|
Uri? get webUri => _webUri;
|
||||||
|
|
||||||
/// The result of [ResidentRunner.run].
|
/// The result of [ResidentRunner.run].
|
||||||
///
|
///
|
||||||
/// This is expected to stay `null` throughout the test, as the application
|
/// This is expected to stay `null` throughout the test, as the application
|
||||||
@ -74,10 +77,12 @@ class WebDriverService extends DriverService {
|
|||||||
DebuggingOptions.disabled(
|
DebuggingOptions.disabled(
|
||||||
buildInfo,
|
buildInfo,
|
||||||
port: debuggingOptions.port,
|
port: debuggingOptions.port,
|
||||||
|
hostname: debuggingOptions.hostname,
|
||||||
)
|
)
|
||||||
: DebuggingOptions.enabled(
|
: DebuggingOptions.enabled(
|
||||||
buildInfo,
|
buildInfo,
|
||||||
port: debuggingOptions.port,
|
port: debuggingOptions.port,
|
||||||
|
hostname: debuggingOptions.hostname,
|
||||||
disablePortPublication: debuggingOptions.disablePortPublication,
|
disablePortPublication: debuggingOptions.disablePortPublication,
|
||||||
),
|
),
|
||||||
stayResident: true,
|
stayResident: true,
|
||||||
@ -116,11 +121,16 @@ class WebDriverService extends DriverService {
|
|||||||
throw ToolExit('Failed to start application');
|
throw ToolExit('Failed to start application');
|
||||||
}
|
}
|
||||||
|
|
||||||
_webUri = _residentRunner.uri;
|
if (_residentRunner.uri == null) {
|
||||||
|
|
||||||
if (_webUri == null) {
|
|
||||||
throw ToolExit('Unable to connect to the app. URL not available.');
|
throw ToolExit('Unable to connect to the app. URL not available.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (debuggingOptions.webLaunchUrl != null) {
|
||||||
|
// It should thow an error if the provided url is invalid so no tryParse
|
||||||
|
_webUri = Uri.parse(debuggingOptions.webLaunchUrl!);
|
||||||
|
} else {
|
||||||
|
_webUri = _residentRunner.uri;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -258,6 +258,29 @@ void main() {
|
|||||||
WebRunnerFactory: () => FakeWebRunnerFactory(),
|
WebRunnerFactory: () => FakeWebRunnerFactory(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testUsingContext('WebDriverService can start an app with a launch url provided', () async {
|
||||||
|
final WebDriverService service = setUpDriverService();
|
||||||
|
final FakeDevice device = FakeDevice();
|
||||||
|
const String testUrl = 'http://localhost:1234/test';
|
||||||
|
await service.start(BuildInfo.profile, device, DebuggingOptions.enabled(BuildInfo.profile, webLaunchUrl: testUrl), true);
|
||||||
|
await service.stop();
|
||||||
|
expect(service.webUri, Uri.parse(testUrl));
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
WebRunnerFactory: () => FakeWebRunnerFactory(),
|
||||||
|
});
|
||||||
|
|
||||||
|
testUsingContext('WebDriverService will throw when an invalid launch url is provided', () async {
|
||||||
|
final WebDriverService service = setUpDriverService();
|
||||||
|
final FakeDevice device = FakeDevice();
|
||||||
|
const String invalidTestUrl = '::INVALID_URL::';
|
||||||
|
await expectLater(
|
||||||
|
service.start(BuildInfo.profile, device, DebuggingOptions.enabled(BuildInfo.profile, webLaunchUrl: invalidTestUrl), true),
|
||||||
|
throwsA(isA<FormatException>()),
|
||||||
|
);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
WebRunnerFactory: () => FakeWebRunnerFactory(),
|
||||||
|
});
|
||||||
|
|
||||||
testUsingContext('WebDriverService forwards exception when run future fails before app starts', () async {
|
testUsingContext('WebDriverService forwards exception when run future fails before app starts', () async {
|
||||||
final WebDriverService service = setUpDriverService();
|
final WebDriverService service = setUpDriverService();
|
||||||
final Device device = FakeDevice();
|
final Device device = FakeDevice();
|
||||||
|
Loading…
Reference in New Issue
Block a user