Memory management

53 views
Skip to first unread message

Vladimir Marek

unread,
May 16, 2013, 9:51:38 AM5/16/13
to robotium-...@googlegroups.com
Hello,

I would like to ask about memory management related to java, Android and
Robotium

I have following code

import android.widget.CheckBox;
CheckBox cb;

// cb is somehow initialized with proper checkbox object

if (cb.isChecked())
{
solo.clickOnText("Some text here");
assertTrue(!cb.isChecked());
}


My trouble is that when I click on the text, check box is un-checked
[this is OK] but the test after that fails because the cb object still
thinks the checkbox is checked.

The only explanation for me is "cb" holds only copy of object which is
not updated when Robotium clicks on checkbox.
I don't know java in too deep details so maybe it is normal.

Would somebody know how to keep object which would be refresh every time
Robotium would use it?

Thanks,
Vladimir

Renas

unread,
May 16, 2013, 10:04:40 AM5/16/13
to robotium-...@googlegroups.com
Hi,

The issue you are experiencing is due to timing. You are asking the object to soon after clicking it. You can do something like below instead where you wait until you get the desired result( or it timeouts and return false). In the below example the timeout has been set to 10000 milliseconds. 

boolean cbIsNotChecked = solo.waitForCondition(new Condition() {

@Override

public boolean isSatisfied() {

return !cb.isChecked();

}

}, 10000);


assertTrue(cbIsNotChecked);


/Renas





--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotium-developers+unsub...@googlegroups.com.
To post to this group, send email to robotium-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/robotium-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



Renas

unread,
May 16, 2013, 10:09:15 AM5/16/13
to robotium-...@googlegroups.com
You can also use: solo.isCheckBoxChecked(String text)

/Renas

Vladimir Marek

unread,
May 22, 2013, 5:39:36 AM5/22/13
to robotium-...@googlegroups.com
Hello,

I thought I solved the problem below finally but unfortunatelly it persists.

I will try to summarize the problem:
My application in test contains Setting screen. There are many records and some of them have checkbox. Those checkboxes don't have any text associated with them so it is not possible to use "solo.isCheckBoxChecked(String text)" method.

When I access the screen I go through all views and select checkbox views. I get all checkboxes which are visible on the screen. Then I expect that the order, I found them in list of views, is the same as they are displayed on screen so I use "solo.isCheckBoxChecked(int index)"

When I reach the last visible record I do "solo.scrollDown()".

Now I use the same routine as when I came to the screen to get all views and identified visible checkboxes.
The routine returns some checkboxes but some  even those which were visible on the first screen but after scrolling down they are not visible. Then when application reaches the checkbox it ends up with exception "Checkboxes are not found". The reason is that in meanwhile Android somehow removed those object which are no longer visible and previously valid indexes are now invalid.

I tried to sleep for 30 seconds and it did not help.
I tried to identified checkboxes as the second last thing before I called "solo.isCheckBoxChecked(int index)" and even then if fails with the exception above.

I can think of two possible causes
1) Changes in views are not reflected quickly enough even if I try to wait for them.
2) isCheckBoxChecked(int index) somehow refresh memory or identifies checkboxes in different way - for example my code identifies 3 but solo.isCheckBoxChecked identifies only 2 ...

Any idea what I could change to make this thing working?

Thanks!
  Vladimir


On 05/17/2013 08:18 AM, Vladimir Marek wrote:
Hi Renas,

I tried the approach below but the value of isChecked() does not change even after a minute. "cb" still refers to original value and not the new one.
Any idea what might be wrong?

Thanks,
  Vladimir

Vladimir Marek

unread,
May 22, 2013, 8:36:13 AM5/22/13
to robotium-...@googlegroups.com
OK, I think I found the root of my troubles.
I don't know why but I used in my code
solo.getViews() and in the list I searched for CheckBoxes
Unfortunately this approach returns also "partially" visible views. "Partially" here means also views which you don't see by eye but they are "visible" from android point of view - view.isShown() returns true.

The trick is to use "solo.getCurrentViews()" which internally uses parameter "onlySufficientlyVisible" which is later used in method "isViewSufficientlyShown". This method does some "calculation" and returns true / false. In my case this was the reason why I saw one more checkbox in my code than "solo.isCheckBoxChecked(id)".

Regards,
  Vladimir
Reply all
Reply to author
Forward
0 new messages