Skip to content

Conversation

@angjieli
Copy link
Contributor

@angjieli angjieli commented Feb 20, 2020

Description

Previously, running flutter drive command against web devices would require developer to run flutter run to start the application first and specify --use-existing-app argument.

This PR is going to support running flutter drive command against web platform without starting the application.

For example, you can run flutter drive --target=test_driver/scroll_perf_web.dart -d web-server --release --browser-name=firefox under examples/flutter_gallery.

Note that it does not support debug mode for now (due to compiler error).

Related Issues

#51083

Tests

I added the following tests:
Updated test flutter_tools/test/commands.shard/hermetic/drive_test.dart.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.

@fluttergithubbot fluttergithubbot added the tool Affects the "flutter" command-line tool. See also t: labels. label Feb 20, 2020
@angjieli
Copy link
Contributor Author

@nturgut

import '../base/file_system.dart';
import '../base/process.dart';
import '../build_info.dart';
import '../build_runner/devfs_web.dart';
Copy link
Contributor

Choose a reason for hiding this comment

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

We cant let this implementation leak into the rest of the tool. There is an interface that flutter run uses, this needs to go through the same indirection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know. Have this fixed by creating a getter on ResidentRunner.

// TODO(angjieli): remove this once running against
// target under test_driver in debug mode is supported
throwToolExit(
'Flutter Driver web does not support running in debug mode.\n'
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: align and indent 2 spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

if (result != 0) {
throwToolExit(null, exitCode: result);
}
final WebDevFS webDevFS = (runner as ResidentWebRunner).device.devFS as WebDevFS;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have a better way to surface this URI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

bool get isRunningRelease => debuggingOptions.buildInfo.isRelease;
bool get supportsServiceProtocol => isRunningDebug || isRunningProfile;

Uri get uri => flutterDevices.first.devFS.baseUri;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: document as the URI of the first connected device for mobile, and only connected device for web.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also when it will be null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


@override
Uri get baseUri => null;
Uri get baseUri => _baseUri;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a simple unit test for the run_hot tests and the resident web runner tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

entrypoint,
);
return Uri.parse('http://$hostname:$port');
_baseUri = Uri.parse('http://$hostname:$port');
Copy link
Contributor

Choose a reason for hiding this comment

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

This might not be the correct information depending on what you need to connect to. For example, hostname might be something like a corp workstation hostname that needs to be resolved to an actual network address

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For our use case, the application and test will be on the same machine so this should be fine.

@nturgut
Copy link
Contributor

nturgut commented Feb 20, 2020

Thanks a lot @angjieli

/cc @yjbanov

I also added a new repository which has code for downloading the drivers: flutter/web_installers#1

I'll combine these in a smoke test so that we will have flutter web engine end to end tested: #51003

ResidentRunner runner;
final FlutterProject flutterProject = FlutterProject.current();
final FlutterDevice flutterDevice = await FlutterDevice.create(
device,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: 2 space indent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// need to know about analytics.
//
// Do not add more operations to the future.
final Completer<void> appStartedTimeRecorder = Completer<void>.sync();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should you be awaiting this so that you're sure runner.uri is not null? Also, make it a regular completer and rename to reflect its current purpose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

urlTunneller: null,
);

// Sync completer so the completing agent attaching to the resident doesn't
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment isn't relevant to this code anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code is not updated yet..Seems like there are something wrong with Github.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code updated.

}

@override
Future<void> exitApp() async {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I just noticed these changes here. Shutting down a web app is a bit complicated - does this change modify the behavior of flutter run -d chrome or flutter run -d chrome --release when quiting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it does not. We got the same behavior.

@nturgut nturgut mentioned this pull request Feb 20, 2020
13 tasks
Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite analyze-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite deploy_gallery-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite deploy_gallery-macos has failed. Please fix the issues identified (or deflake) before re-applying this label.

'Flutter Driver web does not support running in debug mode.\n'
'\n'
'Use --profile mode for testing application performance.\n'
'Use --release mode for testing correctness (with assertions).'
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we going to address this in the next PRs?

As a team we are also have usecase for the driver tests in the debug mode as well. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a driver bug so @jonahwilliams probably knows more about it.
Currently, you will also get an error when running flutter run --target=test_driver/scroll_perf_web.dart --debug.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, this should probably work at ToT


if (webUri != null) {
platformArgs['uri'] = webUri.toString();
// For web device, startApp will be triggered twice
Copy link
Contributor

Choose a reason for hiding this comment

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

I think --start-paused only works in debug mode, so this only needs to happen in profile/release mode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@fluttergithubbot fluttergithubbot merged commit 5ee4147 into flutter:master Feb 23, 2020
nturgut pushed a commit to nturgut/flutter that referenced this pull request Feb 24, 2020
… app. Clean flutter run command from cirrus.yml
nturgut pushed a commit that referenced this pull request Feb 24, 2020
* smoke test for web

* fix comments and remove logs

* addressing reviewer comments

* fix analyzer issue

* running the test on cirrus

* cirrus yaml syntax error

* pub get for web_drivers

* go to the examples directory before running the flutter app

* cirrus is not able to find chromedriver. add a sleep to see if timing is the issue.

* run chrome driver in the background

* After PR #51084, flutter drive command can build and run a web app. Clean flutter run command from cirrus.yml

* enable web
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants