Friday, 15 March 2013

objective c - iOS UI Automation element finds no sub-elements -



objective c - iOS UI Automation element finds no sub-elements -

i'm starting out ui automation ios app , having trouble. i'm unable attach screen shots i'll best describe scenario.

i'm building ios 6.0 , using storyboard. app launches screen navigation controller. root view controller contains main view has 1 uiview subview takes bottom 60% of screen , segmented command sits above subview. able configure accessibility main view (label "mainview"). able locate element in test no problem. however, having problem finding segmented controller. decided log out length of "elements()" , "segementedcontrols()" "mainview" element , length of each array 0. somehow when test running app it's saying there no sub-elements on main view.

another thing note not find accessibility section in identity inspector of storyboard editor segmented control. temporarily added button main view , configured accessibility label, test if elements() or buttons() calls subsequently show element main view when running test, these arrays still returning empty, button.

here's script:

var target = uiatarget.localtarget(); var app = target.frontmostapp(); function selectlistview() { var testname = "selectlistview"; uialogger.logstart(testname); var view = app.mainwindow().elements()["mainview"]; if (!view.isvalid()) { uialogger.logfail("could not locate main view"); } uialogger.logmessage("number of elements sub element: " + view.elements().length); var segmentedcontrol = view.segmentedcontrols()[0]; if (!segmentedcontrol.isvalid()) { uialogger.logfail("could not locate segmented command on physician collection parent view"); } var listbutton = segmentedcontrol.buttons()[1]; if (!listbutton.isvalid()) { uialogger.logfail("could not locate list button on segemented controller on physician collection parent view"); } uialogger.logmessage("tapping list button on physician collection view's segmented control"); listbutton.tap(); uialogger.logpass(testname); } selectlistview();

any help appreciated.

edit: added script search entire view hierarchy main window, set accessibility label value segmented command in initwithcoder (since don't seem able set 1 in storyboard editor segmented control, stated earlier) , still not find element - it's though it's not in view hierarchy, though it's on screen , functions fine:

function traverse(root, name) { if (root.name() == name) { homecoming root; } var elements = root.elements(); (var = 0; < elements.length; i++) { var e = elements[i]; var result = traverse(e, name); if(result != null) { homecoming result; } } homecoming null; } function selectlistview() { var testname = "selectlistview"; var segmentedcontrol = traverse(uiatarget.localtarget().frontmostapp().mainwindow(), "mysegementedcontrol"); if (segmentedcontrol == null) { uialogger.logmessage("still not find it"); } .... }

edit: added phone call app.logelementtree() , still no segmented command in sight ("physiciancollectionparentview" "mainview" - can see, no sub-elements there):

edit: here screen shots. first shows "master" view controller. next shows in add-on segmented command there uiview subview. 3rd shows basic entry point app in storyboard.

here class extension "master" view controller here, showing outlets segmented command , other uiview subview:

@interface physiciancollectionmasterviewcontroller () @property (strong, nonatomic) iboutlet uisegmentedcontrol *viewselectioncontrol; @property (strong, nonatomic) iboutlet uiview *physiciancollectionview; @end

edit: here's interesting - decided go brand new script created within instruments , take advantage of record feature. when clicked on segmented control, here's javascript created show me how had accessed 1 of buttons on segmented control:

var target = uiatarget.localtarget(); target.frontmostapp().mainwindow().elements()["physiciancollectionparentview"].tapwithoptions({tapoffset:{x:0.45, y:0.04}});

so, guess worst-case go this, makes no sense me ui automation not think command exists. strange. there must i'm missing setup basic can't imagine be.

when set accessibilitylabel element , flag isaccessibilityelement = yes; subviews of element hidden. automation, should utilize accessibilityidentifier instead of accessibilitylabel , set isaccessibilityelement = no;

in objective c code after physiciancollectionview rendered, remove label , accessibility flag , instead:

physiciancollectionview.accessibilityidentifier = @"physiciancollectionparentview"; physiciancollectionview.isaccessibilityelement = no;

for lastly elements in element tree, not have sub views, set isaccessibilityelement = yes;

ios objective-c ios-ui-automation

No comments:

Post a Comment