Rooh Al-mahaba
Rooh Al-mahaba

Reputation: 674

How to run instrumentation tests using fastlane in emulator?

The problem that I face is I couldn't run the espresso tests using FastLane, what I want to do is run the tests in an emulator by Fastlane plugin

I used automated_test_emulator_run plugin of Fastlane, I follow the steps in this article https://medium.com/pink-room-club/android-continuous-integration-using-fastlane-and-circleci-2-0-part-i-7204e2e7b8b

for now, I just want to run the tests locally so when I run the following

bundle exec Fastlane instrumentation_tests

it fails with error: No such file or directory - /tools/bin/avdmanager

here my lane in Fastlane

default_platform(:android)

platform :android do
desc "Runs all the tests"
lane :test do
gradle(task: "test")
end

#for increment the version code
android_get_version_code(
gradle_file: "app/build.gradle" # optional
)

android_set_version_code(
gradle_file: "app/build.gradle" # optional
)

desc "Run instrumentation tests"
lane :instrumentation_tests do
automated_test_emulator_run(
AVD_setup_path: "fastlane/AVD_setup.json",
AVD_recreate_new: false,
AVD_clean_after: false,
gradle_task: "connectedDebugAndroidTest")
end
end

And this my AVD_setup.json

{
"avd_list": [
  {
    "avd_name": "Pixel_2_API_Test",

    "create_avd_package": "system-images;android-28;google_apis_playstore;x86",
    "create_avd_device": "Pixel 2",
    "create_avd_tag": "google_apis_playstore",
    "create_avd_abi": "x86",
    "create_avd_additional_options": "",
    "create_avd_hardware_config_filepath": "",

    "launch_avd_port": "",
    "launch_avd_snapshot_filepath": "",
    "launch_avd_launch_binary_name": "emulator",
    "launch_avd_additional_options": "-skin 1080x1920 -gpu on"
  }
]
}

here is a part of the output and the error I got

[13:34:31]: Driving the lane 'android instrumentation_tests' 🚀
[13:34:31]: -----------------------------------------
[13:34:31]: --- Step: automated_test_emulator_run ---
[13:34:31]: -----------------------------------------
[13:34:31]: The automated_test_emulator_run plugin is working!
[13:34:31]: Preparing commands for Android ADB
[13:34:31]: Preparing parameters and commands for emulator: 
Pixel_2_API_Test
[13:34:31]: Configuring environment in order to launch emulators: 
[13:34:31]: Getting avaliable AVDs
[13:34:31]: $ /tools/bin/avdmanager list avd
+--------------------------+-------------------------------+
|                       Lane Context                       |
+--------------------------+-------------------------------+
| DEFAULT_PLATFORM         | android                       |
| ANDROID_VERSION_CODE     | 38                            |
| ANDROID_NEW_VERSION_CODE | 39                            |
| PLATFORM_NAME            | android                       |
| LANE_NAME                | android instrumentation_tests |
+--------------------------+-------------------------------+
[13:34:31]: No such file or directory - /tools/bin/avdmanager

+------+-----------------------------+-------------+
|                 fastlane summary                 |
+------+-----------------------------+-------------+
| Step | Action                      | Time (in s) |
+------+-----------------------------+-------------+
| 1    | default_platform            | 0           |
| 2    | android_get_version_code    | 0           |
| 3    | android_set_version_code    | 0           |
| 4    | prompt                      | 4           |
| 💥   | automated_test_emulator_run | 0           |
+------+-----------------------------+-------------+

[13:34:31]: fastlane finished with errors

[13:34:31]: Error accessing file, this might be due to fastlane's 
directory handling
[13:34:31]: Check out 
https://docs.fastlane.tools/advanced/#directory-behavior for more 
details

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/open3.rb:199:in `spawn': No such file or directory - /tools/bin/avdmanager (Errno::ENOENT) from

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/open3.rb:199:in `popen_run' from

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/open3.rb:190:in popen2e' from /Library/Ruby/Gems/2.3.0/gems/fastlane->2.120.0/fastlane/lib/fastlane/helper/sh_helper.rb:54:insh_control_output' from >/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/forwardable.rb:202:in sh' from /Library/Ruby/Gems/2.3.0/gems/fastlane-plugin-automated_test_emulator_run-1.6.0/lib/fastlane/plugin/automated_test_emulator_run/actions/automated_test_emulator_run_action.rb:48:inrun' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/runner.rb:256:in block (2 levels) in execute_action' from /Library/Ruby/Gems/2.3.0/gems/fastlane- 2.120.0/fastlane/lib/fastlane/actions/actions_helper.rb:50:inexecute_action' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/runner.rb:235:in block in execute_action' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/runner.rb:227:inchdir' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/runner.rb:227:in execute_action' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/runner.rb:157:intrigger_action_by_name' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/fast_file.rb:154:in method_missing' from Fastfile:26:inblock (2 levels) in parsing_binding' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/lane.rb:33:in call' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/runner.rb:49:inblock in execute' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/runner.rb:45:in chdir' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/runner.rb:45:inexecute' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/lane_manager.rb:56:in cruise_lane' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/command_line_handler.rb:36:inhandle' from /Library/Ruby/Gems/2.3.0/gems/fastlane-2.120.0/fastlane/lib/fastlane/commands_generator.rb:108:in `block (2 levels) in run'

I don't know what should I do? what I missed? the error mention that this might be due to fastlane's directory handling so I went to the link but didn't understand what to do?! I am using updated fastlane and plugins, please help me and thanks in advance

Upvotes: 4

Views: 3875

Answers (1)

janpio
janpio

Reputation: 10922

Ignore the standard fastlane error message regarding directory handling.

This is a thing between the plugin you are using (https://github.com/AzimoLabs/fastlane-plugin-automated-test-emulator-run from my googling - you didn't actually provide more information about that), the command/program it tries to use (/tools/bin/avdmanager list avd) and your local Android installation.

You should find out if your local Android actually has the avdmanager command and where it lives, and if list avd works with it. Then find out why the plugin is not using it from the correct location.

A hunch: Might be the plugin is using an ENV variable ANDROID_HOME or similar that is empty on your system.

Upvotes: 2

Related Questions