Toast & Thread problems

231 views
Skip to first unread message

Ali

unread,
Jul 30, 2010, 5:14:40 AM7/30/10
to Robotium Developers
Hello,

I am new to both Android and Robotium but I figured I might learn them
in the same time and I have a few questions:

Firstly I will say what "my application" does: I have a log in screen
with 2 text views, 2 edit fields and 2 buttons: If I forget to provide
an username or a password a toast appears letting me know that

So the first question: If I test this with robotium and I try to read
what's on the edit texts while the toast is still showing, I get an
exception because they cannot be found... so I have to introduce a
sleep in order to wait until the toast disappears. Is there any way to
avoid this?

Secondly, after I log in, I change the activity and I play a never
ending animation (a thread which sends a message to a handler to
redisplay the animation). My test should provide the username and
password, then press login, check that I am in another activity and
then end. The problem is that this check is done only after the thread
is finished (for my never ending animation this is forever). Is there
a way to do this check even though the thread is still running?

Renas Reda

unread,
Jul 30, 2010, 5:39:16 AM7/30/10
to Robotium Developers
Hi,

1. You should use waitForText() instead. That method will return true
or false depending on if it finds the text you are waiting for inside
the time limit that you set.

2. The Robotium tests are run on the UI thread. Because of your
animations Robotium is not allowed to use the UI thread as it is
already in use. That is why it first does the check when the
animations have stopped (and it gets access to the UI thread).

/Renas

Hugo Josefson (Jayway)

unread,
Jul 30, 2010, 5:49:33 AM7/30/10
to Robotium Developers
Hi Ali,

There is some good information in the Android developer guides too:

http://developer.android.com/guide/practices/design/responsiveness.html

The main thing is to make sure you never stay and loop on the UI
thread in your app. Everything which happens in or to your application
needs to happens there.

/Hugo

Ali

unread,
Aug 2, 2010, 7:29:39 AM8/2/10
to Robotium Developers

1. I was using that method to check if the Toast is on the screen, but
I wanted to skip the sleep in order to finish the test faster (If data
is introduced incorrectly in the to edit texts, it is erased and the
Toast appears, so I wanted to check that this happens). However not
waiting is not that vital
2. I made a rookie mistake, all I had to do was to increase a little
bit the sleep time of the second thread. Sorry for this...
Thanks for the help.
Reply all
Reply to author
Forward
0 new messages