Created
July 22, 2019 16:29
-
-
Save wellavelino/c48b0553740ffc4ba56c3599c24b0ea9 to your computer and use it in GitHub Desktop.
re_run_failures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
def re_run_failed_tests(report_dir, retry_count = 3) | |
count = 0 | |
loop do | |
puts "Starting test execution number: #{count}" | |
failures = check_for_failures(report_dir) | |
parsed_test_failures = failures.join(",") | |
test_output = "artifacts/composer-output/failed-retry#{count}" | |
system("java -jar composer.jar" \ | |
" --apk app.apk" \ | |
" --test-apk appTest.apk" \ | |
" --test-package $package" \ | |
" --test-runner $runner" \ | |
" --output-directory #{test_output}" \ | |
" --instrumentation-arguments class #{parsed_test_failures}" \ | |
" --verbose-output false" \ | |
" --device-pattern 'emulator.+'" \ | |
" --shard true") | |
count += 1 | |
break if has_failures?(test_output) == false || count == retry_count | |
end | |
end | |
def check_for_failures(report_dir) | |
failed_tests = [] | |
doc = Nokogiri::XML(File.open("#{report_dir}/junit4-reports/emulator-5554.xml")) | |
doc.root.xpath("//failure/..").each do |failure| | |
test_name = failure.xpath("@name") | |
classname = failure.xpath("@classname") | |
failed_tests << "#{classname}##{test_name}" | |
end | |
failed_tests | |
end | |
def has_failures?(report_dir) | |
failures_count = check_for_failures(report_dir) | |
failures_count.size > 0 ? true : false | |
end | |
system("curl --fail --location https://jcenter.bintray.com/com/gojuno/composer/composer/0.2.9/composer-0.2.9.jar --output composer.jar") | |
report_dir = "artifacts/composer-output" | |
puts "Executing Android UI Tests" | |
system("java -jar composer.jar" \ | |
" --apk app.apk" \ | |
" --test-apk appTest.apk" \ | |
" --test-package $package" \ | |
" --test-runner $runner" \ | |
" --output-directory #{report_dir}" \ | |
" --instrumentation-arguments class $suite_class"\ | |
" --verbose-output false" \ | |
" --device-pattern 'emulator.+'" \ | |
" --shard true") | |
re_run_failed_tests(report_dir) if has_failures?(report_dir) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment