Re: verifying UI element exist

1,108 views
Skip to first unread message

Renas Reda

unread,
Apr 11, 2013, 1:50:12 PM4/11/13
to Robotium Developers
Hi Raiden,

You can use solo.getView(String id). If the view is not found it will
fail the test case.

/Renas

On Apr 11, 7:43 pm, Raiden Drake <raiden.dr...@gmail.com> wrote:
> I'm really new to android programing and robotium, so i'm sorry if I'm just
> asking for something incredibly basic.
>
> I have an APK that I'm trying to test using Robotium. (I don't have access
> to the source code)
> I'm using hierarchyviewer to know the ids for the different elements.
>
> The first test I'm trying to make is one that will try verify that each one
> of the UI elements defined on my requirements exists.
>
> For the named buttons is easy I just use:
>
> assertTrue(solo.searchText("Text of the button"));
>
> But I also need to verify that certain images and other elements are being
> displayed.
> I know the ids of the elements from hierarchyviewer, but there does not
> seem to be a
>
> solo.searchView("Id of the view");
>
> any idea how can i do this?

Renas Reda

unread,
Apr 11, 2013, 2:07:22 PM4/11/13
to Robotium Developers
Sorry about that, this is the correct method:

getView(int id)
Returns a View matching the specified resource id.

/Renas

On Apr 11, 8:02 pm, Raiden Drake <raiden.dr...@gmail.com> wrote:
> I try to use that but Eclipse says that there is an error on the code
>
> according to it the only options for solo.getView() are:
>
> public android.view.View getView(int id)
> public <T extends android.view.View> T getView(java.lang.Class<T>
> viewClass, int index)
> public android.view.View getView(int id, int index)

Renas Reda

unread,
Apr 11, 2013, 2:36:40 PM4/11/13
to Robotium Developers
What you want to do is not possible as you do not have the source code
of the app. The id you see in hierarchy viewer is actually
R.id.fragpower which is generated automatically based on the resource
files (including layouts and preferences). As you don't have the
source code you do not have access to the R.java file that is
generated. Some people do a hack and open the apk, extract the
resources and then generate a resource file in the test project
instead. It's not something I have done my self so I cant give you
more details on it.

/Renas

> Yeah I get that, but the Ids that I'm getting from hierachy viewer are
> strings,
>
> some of the ones I have are:
>
> "fragpower" - the element is a RelativeLayout
> "spectralVis" - the element is a FrameLayout

Sergey Tolkachov

unread,
Apr 12, 2013, 6:56:00 AM4/12/13
to robotium-...@googlegroups.com
It was already mentioned by me once in this forum.

You don't need to have source code in this situation.

Context currContext = getTargetContext();
String packageName = currContext.getPackageName();
viewId = currContext.getResources().getIdentifier("whatYouSeeInHierarhicViewer","id", packageName);
View foundView = solo.getView(viewId)
solo.clickOnView(foundView,false)

Renas

unread,
Apr 12, 2013, 7:58:08 AM4/12/13
to robotium-...@googlegroups.com
Great tip!

/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-develo...@googlegroups.com.
To post to this group, send email to robotium-...@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.
 
 

Carl Nagle

unread,
May 9, 2013, 11:31:41 AM5/9/13
to robotium-...@googlegroups.com, Junwu Ma, Lei Wang, Dharmesh Patel

You cannot call device-side methods on the RC side.  You have no reference to the real objects on the other side.

 

If you knew the ID of the resource, you could use the RC getString method.  But I guess this is different--you don’t know the id of the View.

 

This looks like a good candidate for a new RC method:

 

       getResourceIdByName(resourceName, packageName)

 

Wherein, the packageName is optional and, if it is null, we can get the packageName from the current Context.

 

If you are ambitious, you could add this method to the SoloProcessor yourself and have it immediately.  If you choose that path, send me a direct email and we will help you down that path.

 

http://safsdev.sourceforge.net/sqabasic2000/SAFSRobotiumDevelopment.htm

 

Carl Nagle

SAS Research and Development
Planning, Operations and Strategy

General Applications and Tools

Carl....@sas.com

 

From: robotium-...@googlegroups.com [mailto:robotium-...@googlegroups.com] On Behalf Of saorabh singh
Subject: [robotium-developers] Re: verifying UI element exist

 

Context currContext = getTargetContext();

is not working in Robotium RC..

So is there any alternate ?

--

WeiLing Chang

unread,
Mar 5, 2015, 9:58:00 AM3/5/15
to robotium-...@googlegroups.com, sergey.t...@gmail.com
hi, 

I am a new Robotium user.

I try this tip for any apk but viewId is always 0.

Do i need to do anything else (such as start and click HierarhicViewer or other) when i do the Robotium test?

How can i use the id in HierarhicViewer into Robotium automaticlly without any manual action?

Thanks a lot




Sergey Tolkachov於 2013年4月12日星期五 UTC+8下午6時56分00秒寫道:

naveed

unread,
Mar 9, 2015, 7:51:01 AM3/9/15
to robotium-...@googlegroups.com, sergey.t...@gmail.com
You can use uiautomatorviewer too bundled in Android SDK, and ids(of elements) can be used in Robotium. 

Reply all
Reply to author
Forward
0 new messages