Flutter Run No Supported Devices Connected

broken image


Since its initial release, Flutter has quickly gained its popularity among developers for building beautiful Android and iOS applications. Like apps built with any other development toolkit, automated testing of Flutter apps is the only way to ensure app quality in the shortest time possible.

In this article, I'd like to talk about how to create the unit, widget and integration tests for automating the testing of Flutter apps and execute them against real Android devices in Bitbar Cloud.

Does the problem occur on emulator/simulator as well as on physical devices? - Target Platform: Android Target OS version/browser: Android Pi API 28 Devices: Haven't tried running on an emulator or simulator yet. Crash report

Creating a Sample Bitbar App with Flutter SDK

To better understand how to automate Flutter app testing, I started creating a Bitbar sample app using Flutter SDK (see UI below).

  • 久しぶりにflutterで個人開発を進めようとして、シミュレータ上でアプリを動かそうとしたらNo supported devices connected. が発生。 今まではとりあえずiPhoneシミュレータ立ち上げていれば勝手に認識して、シミュレータ上でアプリ起動していたが、うんともすんとも。 コンソールでflutter docterを実行.
  • Select the Chrome device from the pull down and launch it from your IDE or, from the command line, use flutter run -d chrome, Get the web socket info for DevTools. At the command line, or in the IDE, you should see a message stating something like the following.
  • Enable Developer options and USB debugging in your device setting. Connect the device with a USB cable, plug your phone into your computer. If prompted a connection message on your device, authorize your computer to access device. In the terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device.

The MainPage looks like this:

  • Text element
  • 3 button elements (RaisedButton)
  • TextField element
  • Image asset element

The SubPage looks like this:

  • 2 Text elements
  • button element (RaisedButton)
  • TextField element
  • Image asset element

In my opinion, the easiest way to create a new Flutter app is to use the flutter create command, for example: flutter create my_app. This will create a sample app for Android and iOS.

I created the sample app by modifying this sample app. The app source is in a file called main.dart, and it is in the lib directory.

Note: I gave all the important UI elements Key values, for example:

Creating Unit and Widget Tests

A ‘unit test‘ is to test a single method or class and a ‘widget test‘ is to test a single widget. Here, a ‘widget‘ means UI elements like layout, button, text box, etc.

Unit tests require a test package (https://pub.dev/packages/test), and the flutter_test package provides additional tools for widget testing.

1. Add the test or flutter_test dependency

You can use the following approach to include test or flutter_test (or both) dependency on the app's pubspec.yaml file:

2. Create a unit test file

Create a test directory and test file inside that directory. It is also a good idea to make separate directories for unit and widget tests.

In this example, we can create a file ending with _test.dart for example main_test.dart.

Import packages:

Sample test:

3. Create a widget test file

Again create a file ending with _test.dart.

Import packages:

Sample test:

4. Use command to run the tests

Unit tests can be run with the command:

And widget tests can be executed with the command:

5. JUnit Report

One thing to note: If the unit and widget tests are executed in Bitbar Cloud within a CI tool e.g. Jenkins, the test results will not display correctly after the tests are finished.

To get over this, we can use a Flutter package to convert the test results to the JUnit XML report format. (https://pub.dev/packages/junitreport).

First, make sure the following stuff is included in the system path:

  • flutter/.pub-cache/bin
  • flutter/bin/cache/dart-sdk/bin

Then, install the junitreport package by running the command below:

Both unit and widget tests can be run with this command:

After the tests are finished, the unit and widget test results can be found in a file called TEST-all.xml.

Creating Integration Tests

An integration test tests the complete app and is isolated from the app under test. Integration tests require a flutter_driver package (https://api.flutter.dev/flutter/flutter_driver/flutter_driver-library.html).

Flutter driver:

  • The application runs in a separate process from the test itself
  • Android (Espresso)
  • iOS (Earl Grey)
  • Web (Selenium WebDriver)

1. Add the flutter_driver dependency

The flutter_driver package needs to be added to dev_dependencies section of the app's pubspec.yaml file:

2. Create an integration test file

Create a directory called test_driver. Add files main.dart and main_test.dart (or something ending with _test) inside that directory.

Main.dart

This first contains an ‘instrumented' version of the app being tested. It enables Flutter driver extensions and runs the app.

Main_test.dart

This file is created to contain the test suite.

Import Flutter Driver API:

Connect to the app in 'setUpAll' method:

Cloud sftp server. Close connection in 'tearDownAll' method:

3. Write a sample integration test:

4. Use command to run the integration tests

How much does 0 pay in roulette. Now that we have an instrumented app and a test suite, we can run integration tests with the following command:

There doesn't seem to be a ready package for converting integration test results in a format that could be read in a CI tool, at least at the time of writing this. Test results must be parsed and converted to Junit XML format or something else.

5. Take screenshots

Screenshots can be taken in the integration tests with the ‘screenshots' package (https://pub.dev/packages/screenshots).

Add the dependency in the pubspec.yaml file (the current version of the package at the time of writing this blog):

Create the screenshots.yaml file inside the project root directory. It should look something like this:

Add these in the main_test.dart file:

Import dependency:

Create a config:

Edit pdf file on mac. Macos which command. Take screenshot inside test method like this:

Testing Flutter Android Apps on Real Devices in Bitbar Cloud

In Bitbar Real Device Cloud, Flutter tests are executed under the Appium Server Side type test project. The ‘run-tests.sh' shell script is used to run the Flutter tests. Integration, Unit and Widget tests can be run in the same project in the cloud.

Y turn video. Note that only integration tests actually install and run the test in a device, unit and widget tests don't require devices to run. Device time is still spent when running unit or widget tests, the device is just idling while the test is running.

See a quick demo below.

Unit and Widget tests

Install JUnit report:

Run unit and widget tests:

Move test results to root directory so that they can be found by Jenkins:

Below is the content of the ‘run-tests.sh' file

Integration tests

Run tests with the command:

Parse results and convert them into a Junit .xml file called ‘TEST-all.xml' or just look at the log file (console.log) after the test run has ended. Move screenshots to the directory in the root called ‘screenshots':

How to create and start a Flutter test run in Bitbar Cloud

1. Create a zip-file containing app directory (app and tests, in my case ‘my_app' directory) and ‘run-tests.sh' file.

2. Select Android as your target OS type and select the ‘Appium Android Server Side' type as the framework.

3. Upload your test files to the ‘Appium Server Side' type project in Bitbar Cloud.

Note: Since the actual Flutter app to test is written in the ‘flutter-tests.zip' file and will be built during the test run, you could upload any dummy .apk file, e.g. ‘bitbar-sample-app.apk' (see below) to get the test run started on Bitbar Cloud.

4. Start your Flutter test and get the test results

Conclusion

Testing Flutter apps in Bitbar Cloud is available on real Android devices. Integration test results are not showing correctly without parsing and formatting them yourself. Note that examples in this article have nothing to do with the Appium test automation framework.

Contents
  • Create a new project with web support
    • Create and run

This page covers the following steps for getting started with web support:

  • Configure the flutter tool for web support.
  • Create a new project with web support.
  • Run a new project with web support.
  • Build an app with web support.
  • Add web support to an existing project.

Requirements

To create a Flutter app with web support,you need the following software:

  • Flutter SDK. See theFlutter SDK installation instructions.
  • Chrome; debugging a web app requiresthe Chrome browser.
  • Optional: An IDE that supports Flutter.You can install Android Studio, IntelliJ IDEA,or Visual Studio Code andinstall the Flutter and Dart pluginsto enable language support and tools for refactoring,running, debugging, and reloading your web appwithin an editor. See setting up an editorfor more details.

For more information, see the web FAQ.

Note: Flutter has early support for running web applications, but you need to be running the beta channel of Flutter at present. If you experience a problem that hasn't yet been reported, please file an issue and make sure that 'web' appears in the title.

Create a new project with web support

You can use the following stepsto create a new project with web support.

Set up

Run the following commands to use the latest version of the Flutter SDKfrom the beta channel and enable web support:

Warning: Running flutter channel beta replaces your current version of Flutter with the beta version and can take time if your connection is slow. After this, running flutter upgrade upgrades your install to the latest beta. Returning to the stable channel (or any other) requires calling flutter channel explicitly.

Note: The flutter upgrade command silently fails when origin points to a personal fork. To validate that origin points to https://github.com/flutter/flutter.git, run the following commands in the root directory of your local copy of the https://github.com/flutter/flutter repository:

Once web is enabled,the flutter devices command outputs a Chrome devicethat opens the Chrome browser with your app running,and a Web Server that provides the URL serving the app.

After enabling web support, restart your IDE.You should now see Chrome (web) andWeb Server (web) in the device pulldown.

Flutter Run No Supported Devices Connected Speaker

Run

Note: You only need to execute flutter config --enable-web once. You can always check the status of your configuration using the no-argument flutter config command.

Create and run

Creating a new project with web support is no differentthan creating a new Flutter project for other platforms.

Once you've configured your environment for websupport, you can create and run a web app eitherin the IDE or from the command line.

IDE

After you've configured your environment to supportthe web, make sure you restart the IDE if it wasalready running.

Create a new app in your IDE and it automaticallycreates iOS, Android, and web versions of your app.(And macOS, too, if you've enabled desktop support.)From the device pulldown, select Chrome (web)and run your app to see it launch in Chrome.

Command line

To create a new app that includes web support(in addition to mobile support), run the following commands,substituting myapp with the name of your project:

To serve your app from localhost in Chrome,enter the following from the top of the package:

Note: If there aren't any other connected devices, the -d chrome is optional.

The flutter run command launches the application using thedevelopment compiler in a Chrome browser.

Build

Flutter Run No Supported Devices Connected Wireless

Run the following command to generate a release build:

A release build uses dart2js(instead of the development compiler)to produce a single JavaScript file main.dart.js.You can create a release build using release mode(flutter run --release) or by using flutter build web.This populates a build/web directorywith built files, including an assets directory,which need to be served together.

You can also include --web-renderer html or --web-renderer canvaskit toselect between the HTML or CanvasKit renderers, respsectively. For moreinformation, see Web renderers.

For more information, seeBuild and release a web app.

Add web support to an existing app

To add web support to an existing project,run the following command in aterminal from the root project directory:





broken image