From e3dcedee8c3534e685c60ce0dbd83dc5d576466a Mon Sep 17 00:00:00 2001 From: lkorth Date: Wed, 11 Nov 2015 12:50:11 -0500 Subject: [PATCH] Remove failed test screenshots https://trello.com/c/8j2n3PcU/188-remove-test-screenshot-functionality --- .gitignore | 1 - .../BraintreePaymentActivityTestRunner.java | 21 +------- Rakefile | 2 - .../testutils/ui/ViewHelper.java | 11 +--- ci.sh | 3 -- script/log_listener.rb | 50 ------------------- 6 files changed, 2 insertions(+), 86 deletions(-) delete mode 100644 script/log_listener.rb diff --git a/.gitignore b/.gitignore index 0a2c00ce6f..e7e8be0e20 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,3 @@ Gemfile.lock .bundle *.iml build -failed_test_screenshots diff --git a/Drop-In/src/androidTest/java/com/braintreepayments/api/test/BraintreePaymentActivityTestRunner.java b/Drop-In/src/androidTest/java/com/braintreepayments/api/test/BraintreePaymentActivityTestRunner.java index 9c6ed72158..e70e004d19 100644 --- a/Drop-In/src/androidTest/java/com/braintreepayments/api/test/BraintreePaymentActivityTestRunner.java +++ b/Drop-In/src/androidTest/java/com/braintreepayments/api/test/BraintreePaymentActivityTestRunner.java @@ -29,26 +29,18 @@ import static android.support.test.espresso.Espresso.setFailureHandler; @RunWith(AndroidJUnit4.class) -public class BraintreePaymentActivityTestRunner implements FailureHandler { - - @Rule - public TestName mTestName = new TestName(); +public class BraintreePaymentActivityTestRunner { @Rule public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(BraintreePaymentTestActivity.class, true, false); - private FailureHandler mDelegate; - @SuppressWarnings("deprecation") @Before public void setUp() { BraintreeHttpClient.DEBUG = true; PayPalTestSignatureVerification.disableAppSwitchSignatureVerification(); - mDelegate = new DefaultFailureHandler(getTargetContext()); - setFailureHandler(this); - ((KeyguardManager) getTargetContext().getSystemService(Context.KEYGUARD_SERVICE)) .newKeyguardLock("BraintreePaymentActivity") .disableKeyguard(); @@ -76,17 +68,6 @@ public BraintreePaymentActivity getActivity(Intent intent) { return mActivityTestRule.launchActivity(intent); } - @Override - public void handle(Throwable throwable, Matcher matcher) { - if (!ViewHelper.sWaitingForView) { - Log.d("request_screenshot", mTestName.getMethodName() + "-" + System.currentTimeMillis()); - SystemClock.sleep(500); - } else { - SystemClock.sleep(20); - } - mDelegate.handle(throwable, matcher); - } - @Test(timeout = 100) public void test(){} } diff --git a/Rakefile b/Rakefile index 64bbfbda43..0a2a402f27 100644 --- a/Rakefile +++ b/Rakefile @@ -13,11 +13,9 @@ task :tests => :lint do if output.match(/device$/) begin sh "ruby script/httpsd.rb /tmp/httpsd.pid" - log_listener_pid = fork { exec 'ruby', 'script/log_listener.rb' } sh "./gradlew --continue runAllTests connectedAndroidTest" ensure `kill -9 \`cat /tmp/httpsd.pid\`` - `kill -9 #{log_listener_pid}` end else puts "Please connect a device or start an emulator and try again" diff --git a/TestUtils/src/main/java/com/braintreepayments/testutils/ui/ViewHelper.java b/TestUtils/src/main/java/com/braintreepayments/testutils/ui/ViewHelper.java index fa9109e02f..7067fb0fbd 100644 --- a/TestUtils/src/main/java/com/braintreepayments/testutils/ui/ViewHelper.java +++ b/TestUtils/src/main/java/com/braintreepayments/testutils/ui/ViewHelper.java @@ -27,28 +27,19 @@ public class ViewHelper { public static final int TEN_SECONDS = 10000; public static final int FIFTEEN_SECONDS = 15000; - public static boolean sWaitingForView; - public static ViewInteraction waitForView(final Matcher viewFinder, Matcher viewCondition, final long millis) { checkNotNull(viewFinder); final long endTime = System.currentTimeMillis() + millis; - ViewHelper.sWaitingForView = true; - do { try { ViewInteraction interaction = onView(viewFinder); interaction.check(matches(viewCondition)); - ViewHelper.sWaitingForView = false; return interaction; - } catch (Exception ignored) { - } catch (Error ignored) { - } + } catch (Exception | Error ignored) {} } while (System.currentTimeMillis() < endTime); - ViewHelper.sWaitingForView = false; - ViewInteraction interaction = onView(viewFinder); interaction.check(matches(viewCondition)); diff --git a/ci.sh b/ci.sh index 8708dcecc9..fde87d9243 100755 --- a/ci.sh +++ b/ci.sh @@ -55,7 +55,6 @@ cleanup_android() { $android_adb emu kill $android_adb kill-server kill -9 `cat /tmp/httpsd.pid` - kill -9 $log_listener_pid } start_adb() { @@ -117,8 +116,6 @@ cd_android wait_for_emulator ruby script/httpsd.rb /tmp/httpsd.pid -ruby script/log_listener.rb & -log_listener_pid=$! $android_path/gradlew --info --continue --no-color runAllTests connectedAndroidTest test_return_code=$? diff --git a/script/log_listener.rb b/script/log_listener.rb deleted file mode 100644 index 0b14b577cd..0000000000 --- a/script/log_listener.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'pty' - -TAGS = ["request_screenshot", "request_command"] - -def get_filter - "'#{TAGS.join('|')}'" -end - -def setup - puts `mkdir failed_test_screenshots` - puts `rm -rf failed_test_screenshots/*` - puts `adb logcat -c` -end - -def handle_screenshot_request(screenshot_name) - `adb shell screencap -p | perl -pe 's/\\x0D\\x0A/\\x0A/g' > failed_test_screenshots/#{screenshot_name}.png` -end - -def handle_command_request(command) - if command == 'install fakewallet' - `./gradlew :FakeWallet:installDebug > /dev/null` - elsif command == 'uninstall fakewallet' - `adb uninstall com.braintreepayments.fake.wallet > /dev/null` - end -end - -def run - puts "Listening..." - puts "adb logcat | grep -E #{get_filter}" - begin - PTY.spawn("adb logcat | grep -E #{get_filter}") do |stdin, stdout, pid| - begin - stdin.each do |line| - if line.include?("request_screenshot") - handle_screenshot_request(line.split(':')[1].strip) - elsif line.include?("request_command") - handle_command_request(line.split(':')[1].strip) - end - end - rescue Errno::EIO - puts "adb exited, stopping" - end - end - rescue PTY::ChildExited - puts "adb exited, stopping" - end -end - -setup -run