0

I ask this question in case we are working in Black box testing.
I have researched about Robotium for few day. I learn by myself from Internet.
I also wrote some simple testcase and run it successfully. But when I search the index element (ex: an Edittext, I have to try index by index form 0 to x and get my expect index id).
Can we have another way to get form name, I have the ID name (txtEd1, btnLogin...), which we can access it form R class in White box testing, but i just ask about Black box in this case.
So can we have another way to get element by id or how can we get exact index number of an element in the activity.
I also used Hierarchy Viewer from DDMS and SDK tool to get index ID but it didn't work.

TextView tw = (TextView) solo.getText(<index>); << how can get exact index number?

Hierarchy Viewer from DDMS Hierarchy Viewer from SDK tool

thienkhoi tran
  • 341
  • 2
  • 9

2 Answers2

1

you can try another way to loop on your views and find the right one. First, you need to get all the views, and then loop on them like below:

views = solo.getCurrentViews();

for (int i = 0; i < views.size(); i++) {
    if (views.get(i).getClass().getName().equals("android.widget.TextView")) { 
        tw = (TextView) views.get(i); //DO-YOUR-CHECK-BLABLABLA
    } 
}
Onivas
  • 161
  • 1
  • 8
  • That's a good way to get index id, I just have one more question How the index id was ordered? Base on? (ex: base position, by tab index,...) – thienkhoi tran Apr 01 '15 at 01:16
  • I did not get your question, which index id are are you talking about? Are you talking about Layout View? It should be top-down based on your Layout... If the previous answer is ok for you, please accept it. – Onivas Apr 01 '15 at 08:07
  • **should be top-down based** << That's is the answer. But Are you sure about the top-town based? How about the tab index in a Layout? (http://en.wikipedia.org/wiki/Tabbing_navigation) – thienkhoi tran Apr 01 '15 at 08:16
  • I'm not sure, I suppose it, for that reason I said "should be" :) Base on the solo documentation: **getCurrentViews => Returns an ArrayList of the Views currently displayed in the focused Activity or Dialog.**, it is not specified the index id order. – Onivas Apr 01 '15 at 12:57
1

I'm currently using atmosphere framework. With this framework you can select an element by: resource-id, index, content description, text, etc. by creating a selector. Also you can select an element by Css/xPath query. For example:

...
UiElementSelector selector = new UiElementSelector();
selector.addSelectionAttribute(CssAttribute.INDEX, "your index");
screen.waitForElementExists(selector, WAIT_FOR_ELEMENT_EXISTS_TIMEOUT);
UiElement targetElement = screen.getElements(selector).get(0);  
...

You may find more good examples here.

dim
  • 992
  • 11
  • 26