1

Is there any method built in to Robotium Solo 4.0 to change the system clock time?

I understand that I could probably write some code to open the Settings app, navigate to the clock and change the time, but if something was built in to Robotium to do this, it would be very useful. The Settings menu varies so much depending on the OS version, so it would be a lot of work to write a method that does this properly on all Android OSes.

I have a few date pickers in my app that only allow you to select dates during business hours, so I need to fake that my phone's system time is within normal business hours for the date pickers to allow me to select anything.

If there's nothing built in and someone has written their own robotium script to navigate to the settings app, I'd appreciate you sharing your approach.

Thanks in advance.

DiscDev
  • 38,652
  • 20
  • 117
  • 133

2 Answers2

2

There are a few solutions.

Programatically you could

Just because you cannot change the phones clock easily does not preclude you being able to change what you consider business hours easily, this way you can change your business hours to be based on the current time, e.g. change it to allow or disallow the current time range and then use that as the basis of your test. It is not perfect but it will allow you to test that your code to include/exclude works even if you are not testing the exact time range (although you should be able to right a test to check the data is normally the correct values so combined with the previous tests this will probably give you enough assurance.

or...

you can set the date on non rooted phones using a command from your pc, how you go about integrating this into your test is up to you though (you will have to set the date run a test set a date run a test etc). To do this use the 'adb shell date' command (you can search for its usage here on stackoverflow).

Paul Harris
  • 5,769
  • 1
  • 25
  • 41
  • Hey Paul - thanks for your answer. The first suggestion won't work without some help from the server team as the "business hours" are defined on the server and sent to the app when it logs in. I like your second solution. I'll write a script to make use of the adb shell date command before the test runs. Thanks! – DiscDev Mar 22 '13 at 14:07
  • you could of course add in a special mode to your application that doesn't request it from the server or make it so you can get the server to supply you different data dependent on some other parameter you send them. It sounds like option two might be enough for you anyway! – Paul Harris Mar 22 '13 at 14:30
  • I'm trying to avoid adding any special "testing" code into the application if at all possible. I have a "debug mode" which I could leverage for this, but I just hate sprinkling lots of test specific code into the app. Thanks for your help! – DiscDev Mar 22 '13 at 16:46
0

I could probably write some code to open the Settings app, navigate to the clock and change the time

You are not able to do it with robotium. Robotium (and Instrumentation, on which robotium is based) can only access tested application.

To be honest there is no ability to change system clock programmatically without rooting device. How to change it on rooted device, you can find here: Setting system time of ROOTED phone

Community
  • 1
  • 1
maszter
  • 3,680
  • 6
  • 37
  • 53