0

Right now im testing on Android 4.1.1. using Robotium and trying to click on a image button using the id, because solo.clickonImage or solo.clickonImageButton is not working.

The thing is, I don't know how to import or include the R.java file to get the ID. I could see it from the hierarchy viewer, but it still gives me an error when i place the variable in the code.

in my test scripts my R.java doesn't have much in it, therefore can't read id.

How am I suppose to import the developers ID into my test project?

EDIT: actually i found this programmatically add id to R.id . now my question is, how does my program know what the id is pointing to. example i've created:

< item name = "camera_menu_upload" type="id"/>

How does my script know what camera_menu_upload is on the screen??

Community
  • 1
  • 1
LiLi Liu
  • 37
  • 3
  • 11

5 Answers5

2

You're probably importing the wrong R file. Check your imports and make sure it's importing com.yourcompany.yourapp.R.

Jason Robinson
  • 31,005
  • 19
  • 77
  • 131
  • well.... im not sure which R file i should be importing... R is autogenerated right? from the /res/layout xml files? Also, am i import the developer's R file or my own?? (testing) – LiLi Liu Oct 23 '12 at 23:26
  • Use full package name of R file of application under test. – smk Oct 24 '12 at 02:42
  • Each Android project will generate an R file. Your test project has its own R file. The Android library has its own R file (android.R). Import the R file you need to use, and if you need to use others, use the full package structure. – Jason Robinson Oct 24 '12 at 21:49
1

to get the button, view, textview, checkbox... use this example:

Button buttonview = (Button) solo.getCurentActivity().findViewById(R.id.mybutton);
solo.clickOnView(buttonview);

if you dont know the id use Hierarchy Viewer to see the button id.

gionnut
  • 99
  • 3
0

I don't quite understand your question, but is this what you are looking for?

imageButton IB = (imageButton)findViewById(R.id.blablablabla);
Adam Eberlin
  • 14,005
  • 5
  • 37
  • 49
user1270381
  • 9
  • 1
  • 4
0

Check out package name in your AndroidManifest file:

<manifest package="com.example.project" . . . >

You need to import R class from your application main package, for example: com.companyname.appname.R

Artem Zinnatullin
  • 4,305
  • 1
  • 29
  • 43
  • I'm looking in the R. and it's generated by my xml output files.. is this correct? right now, my R file has "/* AUTO-GENERATED FILE. DO NOT MODIFY." on the top, so it's taking the classes from my /res/ folder and generating... also, it currently doesn't have a "public static final class id" am I taking the correct R file? this is the only one I've found.... it's in my /gen/ folder. – LiLi Liu Oct 23 '12 at 23:54
0

if you are using actionbarsherlock there and trying to click on a button, which is a part of actionbarsherlock, you would have to import its r.java file for using the id of that button. i.e. the r.java from application(gen).
r.java file stores different values for different id and accordingly it searches for the value to be resent on the screen. as it finds it, it performs the desired operation over it.

kamal_prd
  • 543
  • 4
  • 16