2013年9月12日星期四

[Android] Using ID

in Robotium
 This post last edited by the mlzx1991 on 2013-02-28 12:48:05
api in robotium not available in the way of using the id .
If we want to use in robotium id id you need to find yourself through an instance of the control , and then through the api for instance robotium operations to achieve their goals.
of course. If there are children's shoes are interested you can own it in order to use this package .
saying that method before , I had to first talk about the id of several forms:
1. strings . For example id / btn_Example our source code written inside the layout , HierarchyView in sight, are of this .
2. digital form. For example 0x7f070012, we can open R.java. Which was reflected as a String and int in the form of correspondence.
In the white-box testing , we can directly use the form R.id to call :
View view=solo.getView(R.id.btn_Example);//获取View
solo.clickOnView(view);//点击

But in the black box testing , R.id not visible , then how do we use it ?

Activity act=solo.getCurrentActivity();//获取Activity
int id=act.getResources().getIdentifier("btn_Example", "id", act.getPackageName());//通过String的id获取int的id
View view=act.findViewById(id);//获取View
solo.clickOnView(view);//点击

Here is my own package one method:

private boolean clickById(String id) throws Exception{
if(id==""){
return false;
}
try{
Activity act=solo.getCurrentActivity();//获取当前Activity
int id=act.getResources().getIdentifier(id, "id", solo.getCurrentActivity().getPackageName());//获取id
View view=solo.getView(id);//得到View
solo.clickOnView(view);//点击
}catch(Exception ex){
Log.e("Exception", ex.getMessage());
throw ex;
}
return true;
}

------ Solution ------------------------------------- -------
I reply , you knot paste it
------ Solution ------------------------ --------------------
pull harness for the landlord statue statue ...... ......
------ Solution ------- -------------------------------------
drifting away. . . came to cheer !
------ eference --------------------------------------- < br> landlord , ask you a question :
APK black box testing if a control from hierarchyviewer inside look , without the String ID, so how to navigate to it then ? For example, in the navigation bar inside, a lot of the same Tab, the Tab are not their own Id, only his father controls are Id, ask how to locate the controls without ID ?

Thank you very much !
------ eference --------------------------------------- < br> through the parent control getChildAt (index) to get the child controls

没有评论:

发表评论