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) ⇒ Integer
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) ⇒ Integer
Launches the tests sequentially.
Constructor Details
#initialize(driver, test_folder, flutter_command) ⇒ FlutterIntegrationTestHelper
Initialize the helper that launches the integration tests
integration tests
14 15 16 17 18 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 14 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
111 112 113 114 115 116 117 118 119 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 111 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
103 104 105 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 103 def _get_exit_code(exit_status) exit_status.to_s.split(' ').last end |
#_launch_tests(device_id, reuse_build) ⇒ Integer
Executes the tests found on the device_id
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 54 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 tests = { "successful" => 0, "failed" => 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}" : ''}") successful = _get_exit_code(status) == '0' color = successful ? 'green' : 'red' tests[successful ? 'successful' : 'failed'] += 1 UI.(Utilities.new.colorize("Test #{test.split("/").last} #{successful ? 'terminated correctly' : 'failed'}", color)) count += 1 end unless tests['failed'] == 0 UI.user_error!("There are some integration tests that fail") end end |
#_load_files(test_folder) ⇒ Array
Loads all the integration test files
24 25 26 27 28 29 30 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 24 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
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 125 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) ⇒ Integer
Launches the tests sequentially
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_integration_test_helper.rb', line 38 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 |