jayway/robotium — pull request #49 by rdsubhas (2013-05-13 05:58:55+00:00)
Title: Consistent and configurable Timeouts

Hi, We're contributing to [RapidFTR](http://github.com/rapidftr/RapidFTR), an open source project for tracking missing children, sponsored by UNICEF. Its a web and android app. Thanks a lot for Robotium, its an excellent and simple tool, and we use it to run all our automation tests.

We had one problem. Each of our machines are different (some overpowered, some underpowered, some virtualized). Having a single `TIMEOUT` and `SMALLTIMEOUT` for all these machines was causing us lot of problems, with aberrant test failures. We needed a way to configure these values.

We have added a way to configure those, by setting properties via the shell:
```
adb shell setprop SOLO_TIMEOUT
adb shell setprop SOLO_SMALLTIMEOUT
```

If not set, they retain the same defaults (`TIMEOUT 20000` and `SMALLTIMEOUT 10000`). This has solved all our problems with different machines. We just set different timeouts (via maven hooks itself, or directly using shell scripts in the CI), and everything passes!

One good side effect of this is that, we found that this `TIMEOUT` and `SMALLTIMEOUT` are duplicated across many classes. We also removed all those and replaced them with `static import`s. We've also done this as simple `public static final int`s, rather than using any type of runtime getters/setters.

**PS**: We used the following answer to get the properties:
http://stackoverflow.com/questions/3750109/how-to-define-and-use-a-system-property-in-android-instrumentation-test
If the properties are dynamically set using `adb shell setprop`, then they won't be readable using `System.getProperty`, since that takes only values set during android emulator boot. The reflection method is the only sure way of getting properties set during runtime. Yeah we too hate reflections, but looks like this specific class `android.os.SystemProperties` is [widely used in such a way](https://www.google.co.in/search?q=android.os.SystemProperties&oq=android.os.SystemProperties&aqs=chrome.0.69i57j69i61l2.2329j0&sourceid=chrome&ie=UTF-8). So yes, we all generally hate reflections, so please let us know if you don't like it. Most likely then we'll have to resort to runtime getters/setters.