Class: Fastlane::Helper::FlutterIntegrationTestHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::FlutterIntegrationTestHelper
- Defined in:
- lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb
Instance Method Summary collapse
-
#_get_apk_path(message) ⇒ Object
Parse the flutter build output looking for a .apk path.
-
#_get_exit_code(exit_status) ⇒ Object
Returns the exit code of a process.
-
#_launch_tests(device_id, reuse_build) ⇒ Object
Executes the tests found on the device_id.
-
#_load_files(test_folder) ⇒ Array
Loads all the integration test files.
-
#_run_test_device(platform, force_launch) ⇒ Object
Checks if there’s a device running and gets its id.
-
#initialize(driver, test_folder, flutter_command) ⇒ FlutterIntegrationTestHelper
constructor
Initialize the helper that launches the integration tests.
-
#run(platform, force_launch, reuse_build) ⇒ Object
Launches the tests sequentially.
Constructor Details
#initialize(driver, test_folder, flutter_command) ⇒ FlutterIntegrationTestHelper
Initialize the helper that launches the integration tests
integration tests
13 14 15 16 17 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 13 def initialize(driver, test_folder, flutter_command) @driver = driver @integration_tests = _load_files(test_folder) @flutter_command = flutter_command end |
Instance Method Details
#_get_apk_path(message) ⇒ Object
Parse the flutter build output looking for a .apk path
94 95 96 97 98 99 100 101 102 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 94 def _get_apk_path() components = .split(/\n/).last.split(' ') if components.any? { |line| line.end_with? '.apk' } components.detect { |c| c.end_with? '.apk' } else UI.warn('Apk path not found in the stdout') nil end end |
#_get_exit_code(exit_status) ⇒ Object
Returns the exit code of a process
86 87 88 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 86 def _get_exit_code(exit_status) exit_status.to_s.split(' ').last end |
#_launch_tests(device_id, reuse_build) ⇒ Object
Executes the tests found on the device_id
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 51 def _launch_tests(device_id, reuse_build) apk_path = nil if reuse_build UI.("Building apk") out, err, status = Open3.capture3("#{@flutter_command} build apk") if _get_exit_code(status) != '0' UI.error("Failed to build apk") puts err exit(1) else apk_path = _get_apk_path(out) if !apk_path.nil? && File.file?(apk_path) UI.("Build apk at path #{apk_path}") #TODO else UI.error("Apk path not found or it's not accessible") exit(1) end end end count = 0 @integration_tests.each do |test| UI.("Launching test #{count}/#{@integration_tests.length}: #{test.split("/").last}") _, __, status = Open3.capture3("#{@flutter_command} drive --target #{@driver} --driver #{test} -d #{device_id} #{reuse_build ? "--use-application-binary #{apk_path}" : ''}") UI.("Test #{count} ended with code '#{_get_exit_code(status)}'") count += 1 end end |
#_load_files(test_folder) ⇒ Array
Loads all the integration test files
23 24 25 26 27 28 29 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 23 def _load_files(test_folder) test_files = Dir.glob("#{test_folder}/**/*").reject do |f| File.directory?(f) || !f.end_with?('_test.dart') end UI.("Found #{test_files.length} test files") test_files end |
#_run_test_device(platform, force_launch) ⇒ Object
Checks if there’s a device running and gets its id
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 108 def _run_test_device(platform, force_launch) out, _ = Open3.capture2("#{@flutter_command} devices | grep #{platform}") device_id = nil if out.to_s.strip.empty? && force_launch out, _ = Open3.capture2("#{@flutter_command} emulators | grep #{platform}") if out.to_s.strip.empty? UI.error("No emulators found for platform #{platform}") exit(1) end emulator_id = out.to_s.split('•')[0] Open3.capture2("#{@flutter_command} emulators --launch #{emulator_id}") out, _ = Open3.capture2("#{@flutter_command} devices | grep #{platform}") else device_id = (out.to_s.split("•")[1]).strip UI.("Found already running device: #{device_id}") end unless out.to_s.strip.empty? device_id = (out.to_s.split("•")[1]).strip UI.("Got device id #{device_id}") end device_id.nil? ? nil : device_id end |
#run(platform, force_launch, reuse_build) ⇒ Object
Launches the tests sequentially
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 36 def run(platform, force_launch, reuse_build) UI.("Checking for running devices") device_id = _run_test_device(platform, force_launch) if !device_id.nil? _launch_tests(device_id, reuse_build) else UI.error("Failed to find a device to launch the tests on") exit(1) end end |