Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[web] adding a test for e2e web testing. #2554

Merged
merged 17 commits into from
Feb 28, 2020

Conversation

nturgut
Copy link
Contributor

@nturgut nturgut commented Feb 25, 2020

Description

(1) Adding a timeout to e2e so any test that doesn't use the MethodChannel won't timeout.
(2) Adding a test for web use case, altering the existing tests.
(3) Altering the previous code not to use dart:io on web
(4) Changing the documentation for future users.
(5) Adding the test to CI

Related Issues

Fixes: flutter/flutter#50212
Fixes: flutter/flutter#50654

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.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@nturgut nturgut requested a review from digiter as a code owner February 25, 2020 01:49
@nturgut nturgut removed the request for review from digiter February 25, 2020 01:49
.cirrus.yml Outdated
- cd web_installers/packages/web_drivers/
- pub get
- dart lib/web_driver_installer.dart &
- sleep 20
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this more deterministic? Maybe look at the output of web_driver_installer and use that to decide when to call flutter drive?

https://superuser.com/questions/375223/watch-the-output-of-a-command-until-a-particular-string-is-observed-and-then-e

Copy link
Member

@ditman ditman Feb 25, 2020

Choose a reason for hiding this comment

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

Hmmm... Why is the previous command run in the background, though?

Wouldn't you be able to remove the sleep if the & at the end of dart lib/web_driver_installer.dart was removed?

Copy link
Contributor Author

@nturgut nturgut Feb 25, 2020

Choose a reason for hiding this comment

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

No it should always run on the background. The code is installing (downloading over the web and extracting. It takes some time) the chrome driver. It also starts running it on port 4444

Copy link
Member

Choose a reason for hiding this comment

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

Ahhh... maybe splitting the code in "the part that downloads and installs" (being synchronous) and the part that "starts the driver on port 444 in the background" could be split in two separate commands, that way you wouldn't need the sleep (maybe)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I can do is, I can only use web_driver installers for installing. and for launching I can use
chromedriver --port=4444 &

This can remove the need for sleep since it is starts instantly.

Copy link
Member

Choose a reason for hiding this comment

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

If that works, I think it's more deterministic than having the sleep there (imagine that installing takes 21 seconds for whatever reason)

Copy link
Contributor Author

@nturgut nturgut Feb 26, 2020

Choose a reason for hiding this comment

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

@ditman I sent you a PR to fix the webdriver command (flutter/web_installers#4)

Copy link
Member

Choose a reason for hiding this comment

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

@nturgut just approved it!

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.

packages/e2e/lib/e2e.dart Show resolved Hide resolved
app.main();

// Trigger a frame.
await tester.pumpAndSettle();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to await expectLater below instead of calling this?

I worry about littering tests with tester.pumpAndSettle(), it seems kind of mysterious whether it's needed or not. In any case, I hope that WidgetTester synchronization will help.

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.

@@ -1,3 +1,7 @@
## 0.2.4+4

* Add timeout to invokeMethod call, for tests do not use MethodChannel.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Add timeout to invokeMethod call, for tests do not use MethodChannel.
* Fixed a hang that occurred on platforms that don't have a `MethodChannel` listener registered.

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.

@nturgut
Copy link
Contributor Author

nturgut commented Feb 25, 2020

The chrome version flutter/plugins CI is using is 78. It was not supported in web_installers. I'll update web_installers and continue on the PR.

Thanks for the comments.

Copy link
Contributor

@collinjackson collinjackson left a comment

Choose a reason for hiding this comment

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

I think this approach will solve the build issue: collinjackson@7fa057d

@@ -0,0 +1,15 @@
@TestOn('browser')
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a test file, you can remove this

import 'dart:io';

import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a test file, you can remove this

@ditman
Copy link
Member

ditman commented Feb 28, 2020

I think this approach will solve the build issue: collinjackson/plugins@7fa057d

That's a very nice trick @collinjackson

@nturgut
Copy link
Contributor Author

nturgut commented Feb 28, 2020

I think this approach will solve the build issue: collinjackson@7fa057d

it didn't work unfortunately: https://cirrus-ci.com/task/6188264717549568 It still wants to compile each file and in case of example_e2e_web_test it is not able to.

@collinjackson
Copy link
Contributor

It still wants to compile each file and in case of example_e2e_web_test it is not able to.

Actually it looks like the conditional import is working and the tests are running successfully on mobile. Your commit differs from my suggestion in that you left example_e2e_web_test.dart in place and that's where things are not working. You should delete it.

See https://github.com/flutter/plugin_tools/blob/master/lib/src/drive_examples_command.dart#L52

@nturgut
Copy link
Contributor Author

nturgut commented Feb 28, 2020

example_e2e_web_test.dart

May be I am missing something, but as far as I know if the file <test_name>_test.dart, does not exist we won't be able to use the following smoke test command:

flutter drive -v --target=test_driver/example_e2e_web.dart -d web-server --release --browser-name=chrome

My suggestions are:
(1) web smoke test will be in another directory
(2) I can change the plugin_tools to run only examples does not contain web

Let me know if these makes sense.

This reverts commit 7cf24d6.
@collinjackson
Copy link
Contributor

collinjackson commented Feb 28, 2020

example_e2e_web_test.dart

May be I am missing something, but as far as I know if the file <test_name>_test.dart, does not exist we won't be able to use the following smoke test command:

flutter drive -v --target=test_driver/example_e2e_web.dart -d web-server --release --browser-name=chrome

My suggestions are:
(1) web smoke test will be in another directory
(2) I can change the plugin_tools to run only examples does not contain web

Let me know if these makes sense.

My current proposal is to remove example_e2e_web_test.dart and you'd have two options for running the web integration test:

  1. flutter drive -v --target=test_driver/example_e2e.dart -d web-server --release --browser-name=chrome would run the main tests entry point and import the web tests. it won't require much of a change to our existing CI, and you're following existing conventions for how to find the driver boilerplate file from the e2e test.
  2. flutter drive -v --target=test_driver/example_e2e_web.dart -d web-server --release --browser-name=chrome --driver=example_e2e_test.dart would run the web test directly. If you go this route you wouldn't need the conditional import, but you'd be introducing more conventions around filenames that might be brittle.

As for moving the web tests to their own folder -- I am not sure about using folder names to determine the platform of tests. It's one thing for us to do this for our own CI, but plugin developers are going to mimic whatever we're doing here, and an approach based on directory structure baked into all our tools seems less flexible to me than a code solution.

@nturgut
Copy link
Contributor Author

nturgut commented Feb 28, 2020

example_e2e_web_test.dart

May be I am missing something, but as far as I know if the file <test_name>_test.dart, does not exist we won't be able to use the following smoke test command:
flutter drive -v --target=test_driver/example_e2e_web.dart -d web-server --release --browser-name=chrome
My suggestions are:
(1) web smoke test will be in another directory
(2) I can change the plugin_tools to run only examples does not contain web
Let me know if these makes sense.

My current proposal is to remove example_e2e_web_test.dart and you'd have two options for running the web integration test:

  1. flutter drive -v --target=test_driver/example_e2e.dart -d web-server --release --browser-name=chrome would run the main tests entry point and import the web tests. it won't require much of a change to our existing CI, and you're following existing conventions for how to find the driver boilerplate file from the e2e test.
  2. flutter drive -v --target=test_driver/example_e2e_web.dart -d web-server --release --browser-name=chrome --driver=example_e2e_test.dart would run the web test directly. If you go this route you wouldn't need the conditional import, but you'd be introducing more conventions around filenames that might be brittle.

As for moving the web tests to their own folder -- I am not sure about using folder names to determine the platform of tests. It's one thing for us to do this for our own CI, but plugin developers are going to mimic whatever we're doing here, and an approach based on directory structure baked into all our tools seems less flexible to me than a code solution.

The code runs the tests only if there are under example folder, so if I add a new folder such as web_example or web_smoke it should be ok.

The reason I don't want to remove example_e2e_web_test.dart is soon it would be very different than example_e2e_test.dart by content due to screenshots taken by the driver for web. In the original PR we added more functionality to the driver test: flutter/flutter#49833

For now I can go with the options you suggested but for the future we still need to reconsider differences between driver files.

@@ -1,3 +1,7 @@
## 0.2.4+4

* Fixed a hang that occurred on platforms that don't have a `MethodChannel` listener registered..
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Fixed a hang that occurred on platforms that don't have a `MethodChannel` listener registered..
* Fixed a hang that occurred on platforms that don't have a `MethodChannel` listener registered.

@nturgut nturgut merged commit 2349099 into flutter:master Feb 28, 2020
EdwinRomelta pushed a commit to EdwinRomelta/plugins that referenced this pull request Jun 11, 2020
* adding a test for e2e web testing.

* chaning the changelog. updating pubspec.yaml version. fixing analyze

* merging the changelog

* addressing reviewer comments

* fix format. addressing reviewer comments

* try to run chromedriver on the backend

* chrome driver is was running as the main task, preventing test from running . use background_task to run it. use ENV for directory change

* change in scripts. remove list from backfround task. change argument of driver

* removed background task. it wasn't using the same path

* run web tests only on browser

* add test on to the web driver test as well. drive-examples are still failing

* fix the imports

* trying reviever suggestion for drive_example compile errors

* test _ imports

* Revert "test _ imports"

This reverts commit 7cf24d6.

* removing the web_test driver file upon reviewers suggestion

* format fix
FlutterSu pushed a commit to FlutterSu/flutter-plugins that referenced this pull request Nov 20, 2020
* adding a test for e2e web testing.

* chaning the changelog. updating pubspec.yaml version. fixing analyze

* merging the changelog

* addressing reviewer comments

* fix format. addressing reviewer comments

* try to run chromedriver on the backend

* chrome driver is was running as the main task, preventing test from running . use background_task to run it. use ENV for directory change

* change in scripts. remove list from backfround task. change argument of driver

* removed background task. it wasn't using the same path

* run web tests only on browser

* add test on to the web driver test as well. drive-examples are still failing

* fix the imports

* trying reviever suggestion for drive_example compile errors

* test _ imports

* Revert "test _ imports"

This reverts commit 7cf24d6.

* removing the web_test driver file upon reviewers suggestion

* format fix
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chrome e2e integration test on plugins CI [web][integration] Change in e2e package for web
4 participants