3

I am using fastlanes screengrab to capture screenshots of an app. screengrab is utilizing androids ui testing framework espresso to navigate through the app. if one of my ui tests fails I want the other tests to continue capturing screenshots but at the same time I want to be notified about the failed test.

To prevent the test to fail and stopping the whole program I surrounded all my tests with try / catch. When a test fails I want the the exception to be logged to the screengrab output:

[10:24:37]: Running tests for locale: bs-BA  
[10:24:37]: $ adb -s emulator-5554 shell am instrument --no-window-animation -w \  
-e testLocale bs_BA \  
-e endingLocale en_US \  
-e class my.app.tests.MainLocationScreenshots \  
-e isScreengrab true \  
my.app.test/my.app.runners.RxTestRunner  
[10:24:40]: ▸ my.app.tests.MainLocationScreenshots:  
[10:24:41]: ▸ my.app.tests.MainLocationScreenshots:....  
[10:25:37]: ▸ Time: 42.311  
[10:25:37]: ▸ OK (7 tests)  

I tried the following without success:

Log.d("", "Can you read this?????????")
Log.d("Screengrab", "Can you read this?")
Log.println(Log.ERROR,"Screengrab","What about this?")
System.out.print("But I bet this works")

All the Log calls appear in Logcat but not in the screengrab output, the System.out.print does not appear in either.

Is there a way to log the the screengrab output? Is it documented somewhere I haven't looked?

Thanks!

Henning
  • 2,202
  • 1
  • 17
  • 38
  • I saw that fastlane itself uses a class called UI.rb. But can I call it from Java/Android somehow? https://github.com/fastlane/fastlane/tree/master/fastlane_core – Henning Mar 29 '18 at 07:30
  • There isn't a way to call any of the `UI` function from Java (since the Ruby and Java are running as different processes). My suggested approach would be to just let the tests fail and fix the reason they are failing but I don't know what your specific use case is for wrapping them in a try/catch – joshdholtz Mar 29 '18 at 13:19
  • "`if one of my ui tests fails I want the other tests to continue capturing screenshots but at the same time I want to be notified about the failed test"` the answer is to do that in `Ruby` see [this](https://github.com/fastlane/fastlane/issues/5001) – Jon Goodwin Mar 29 '18 at 17:18
  • `My suggested approach would be to just let the tests fail and fix the reason they are failing but I don't know what your specific use case is for wrapping them in a try/catch` When I take 500+ Screenshots over night I rather come back to 495 sussefull ones and fix the error later than see that the run stopped after 80 screenshots. `the answer is to do that in Ruby` Thanks I will try that. – Henning Apr 09 '18 at 09:36

0 Answers0