Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixing pa11y and fa11y commands for iOS8.1+ #128

Merged
merged 5 commits into from
Nov 30, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions commands/FBAccessibilityCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ def run(self, arguments, options):
self.foundElement = False
self.accessibilityGrepHierarchy(rootView, arguments[0])

def isRunningInSimulator():
return ((fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] model]').GetObjectDescription().lower().find('simulator') >= 0) or (fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] name]').GetObjectDescription().lower().find('simulator') >= 0))

def forceStartAccessibilityServer():
#We try to start accessibility server only if we don't have needed method active
if not fb.evaluateBooleanExpression('[UIView instancesRespondToSelector:@selector(_accessibilityElementsInContainer:)]'):
#Starting accessibility server is different for simulator and device
if fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] model]').GetObjectDescription().lower().find('simulator') >= 0:
if isRunningInSimulator():
lldb.debugger.HandleCommand('eobjc (void)[[UIApplication sharedApplication] accessibilityActivate]')
else:
lldb.debugger.HandleCommand('eobjc (void)[[[UIApplication sharedApplication] _accessibilityBundlePrincipalClass] _accessibilityStartServer]')
Expand All @@ -86,6 +89,16 @@ def accessibilityLabel(view):
#using Apple private API to get real value of accessibility string for element.
return fb.evaluateExpressionValue('(id)[%s accessibilityAttributeValue:%i]' % (view, ACCESSIBILITY_LABEL_KEY), False)

def accessibilityElements(view):
if fb.evaluateBooleanExpression('[UIView instancesRespondToSelector:@selector(accessibilityElements)]'):
a11yElements = fb.evaluateExpression('(id)[%s accessibilityElements]' % view, False)
if int(a11yElements, 16) != 0:
return a11yElements
if fb.evaluateBooleanExpression('[%s respondsToSelector:@selector(_accessibleSubviews)]' % view):
return fb.evaluateExpression('(id)[%s _accessibleSubviews]' % (view), False)
else:
return fb.evaluateObjectExpression('[[[UIApplication sharedApplication] keyWindow] _accessibilityElementsInContainer:0 topLevel:%s includeKB:0]' % view)

def printAccessibilityHierarchy(view, indent = 0):
a11yLabel = accessibilityLabel(view)
classDesc = objHelpers.className(view)
Expand All @@ -95,10 +108,10 @@ def printAccessibilityHierarchy(view, indent = 0):
if int(a11yLabel.GetValue(), 16) == 0:
print indentString + ('{} {}'.format(classDesc, view))
#We call private method that gives back all visible accessibility children for view
accessibilityElements = fb.evaluateObjectExpression('[[[UIApplication sharedApplication] keyWindow] _accessibilityElementsInContainer:0 topLevel:%s includeKB:0]' % view)
accessibilityElementsCount = int(fb.evaluateExpression('(int)[%s count]' % accessibilityElements))
a11yElements = accessibilityElements(view)
accessibilityElementsCount = int(fb.evaluateExpression('(int)[%s count]' % a11yElements))
for index in range(0, accessibilityElementsCount):
subview = fb.evaluateObjectExpression('[%s objectAtIndex:%i]' % (accessibilityElements, index))
subview = fb.evaluateObjectExpression('[%s objectAtIndex:%i]' % (a11yElements, index))
printAccessibilityHierarchy(subview, indent + 1)
else:
print indentString + ('({} {}) {}'.format(classDesc, view, a11yLabel.GetObjectDescription()))
Expand Down