From 7a7bbf74b98864f3bcc8de4e3e7a1e60351e9b71 Mon Sep 17 00:00:00 2001 From: Georgiy Kassabli Date: Wed, 18 Nov 2015 12:51:59 +0000 Subject: [PATCH 1/5] Fixing pa11y and fa11y commands for iOS8.1+ --- commands/FBAccessibilityCommands.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/commands/FBAccessibilityCommands.py b/commands/FBAccessibilityCommands.py index d8d367a..413a0d7 100644 --- a/commands/FBAccessibilityCommands.py +++ b/commands/FBAccessibilityCommands.py @@ -77,7 +77,7 @@ 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 fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] name]').GetObjectDescription().lower().find('simulator') >= 0: lldb.debugger.HandleCommand('eobjc (void)[[UIApplication sharedApplication] accessibilityActivate]') else: lldb.debugger.HandleCommand('eobjc (void)[[[UIApplication sharedApplication] _accessibilityBundlePrincipalClass] _accessibilityStartServer]') @@ -86,6 +86,15 @@ 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): + a11yElements = fb.evaluateExpression('(id)[%s accessibilityElements]' % view, False) + if int(a11yElements, 16) != 0: + return a11yElements + elif 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) @@ -95,10 +104,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())) From 04dec5c3991e5dbb32d382559c89795040ac843a Mon Sep 17 00:00:00 2001 From: Georgiy Kassabli Date: Fri, 20 Nov 2015 14:42:20 +0000 Subject: [PATCH 2/5] Addressing comments --- commands/FBAccessibilityCommands.py | 15 ++++++++------- commands/FBAutoLayoutCommands.py | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/commands/FBAccessibilityCommands.py b/commands/FBAccessibilityCommands.py index 413a0d7..b21c6b6 100644 --- a/commands/FBAccessibilityCommands.py +++ b/commands/FBAccessibilityCommands.py @@ -77,20 +77,21 @@ 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] name]').GetObjectDescription().lower().find('simulator') >= 0: - lldb.debugger.HandleCommand('eobjc (void)[[UIApplication sharedApplication] accessibilityActivate]') + if (fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] model]').GetObjectDescription().lower().find('simulator') >= 0) | (fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] name]').GetObjectDescription().lower().find('simulator') >= 0): + lldb.debugger.HandleCommand('expr (void)[[UIApplication sharedApplication] accessibilityActivate]') else: - lldb.debugger.HandleCommand('eobjc (void)[[[UIApplication sharedApplication] _accessibilityBundlePrincipalClass] _accessibilityStartServer]') + lldb.debugger.HandleCommand('expr (void)[[[UIApplication sharedApplication] _accessibilityBundlePrincipalClass] _accessibilityStartServer]') 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): - a11yElements = fb.evaluateExpression('(id)[%s accessibilityElements]' % view, False) - if int(a11yElements, 16) != 0: - return a11yElements - elif fb.evaluateBooleanExpression('[%s respondsToSelector:@selector(_accessibleSubviews)]' % 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) diff --git a/commands/FBAutoLayoutCommands.py b/commands/FBAutoLayoutCommands.py index a6297ce..5510d2b 100644 --- a/commands/FBAutoLayoutCommands.py +++ b/commands/FBAutoLayoutCommands.py @@ -30,7 +30,7 @@ def args(self): return [ fb.FBCommandArgument(arg='view', type='UIView *', help='The view to print the Auto Layout trace for.', default='(id)[[UIApplication sharedApplication] keyWindow]') ] def run(self, arguments, options): - lldb.debugger.HandleCommand('poobjc (id)[{} _autolayoutTrace]'.format(arguments[0])) + lldb.debugger.HandleCommand('po (id)[{} _autolayoutTrace]'.format(arguments[0])) def setBorderOnAmbiguousViewRecursive(view, width, color): @@ -40,8 +40,8 @@ def setBorderOnAmbiguousViewRecursive(view, width, color): isAmbiguous = fb.evaluateBooleanExpression('(BOOL)[%s hasAmbiguousLayout]' % view) if isAmbiguous: layer = viewHelpers.convertToLayer(view) - lldb.debugger.HandleCommand('eobjc (void)[%s setBorderWidth:(CGFloat)%s]' % (layer, width)) - lldb.debugger.HandleCommand('eobjc (void)[%s setBorderColor:(CGColorRef)[(id)[UIColor %sColor] CGColor]]' % (layer, color)) + lldb.debugger.HandleCommand('expr (void)[%s setBorderWidth:(CGFloat)%s]' % (layer, width)) + lldb.debugger.HandleCommand('expr (void)[%s setBorderColor:(CGColorRef)[(id)[UIColor %sColor] CGColor]]' % (layer, color)) subviews = fb.evaluateExpression('(id)[%s subviews]' % view) subviewsCount = int(fb.evaluateExpression('(int)[(id)%s count]' % subviews)) From d919a0d5c0be1efa8fcaca6747072c27eb693bad Mon Sep 17 00:00:00 2001 From: Georgiy Kassabli Date: Fri, 20 Nov 2015 14:43:45 +0000 Subject: [PATCH 3/5] Reverting accidental change --- commands/FBAccessibilityCommands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/FBAccessibilityCommands.py b/commands/FBAccessibilityCommands.py index b21c6b6..15418d9 100644 --- a/commands/FBAccessibilityCommands.py +++ b/commands/FBAccessibilityCommands.py @@ -78,9 +78,9 @@ def forceStartAccessibilityServer(): 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) | (fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] name]').GetObjectDescription().lower().find('simulator') >= 0): - lldb.debugger.HandleCommand('expr (void)[[UIApplication sharedApplication] accessibilityActivate]') + lldb.debugger.HandleCommand('eobjc (void)[[UIApplication sharedApplication] accessibilityActivate]') else: - lldb.debugger.HandleCommand('expr (void)[[[UIApplication sharedApplication] _accessibilityBundlePrincipalClass] _accessibilityStartServer]') + lldb.debugger.HandleCommand('eobjc (void)[[[UIApplication sharedApplication] _accessibilityBundlePrincipalClass] _accessibilityStartServer]') def accessibilityLabel(view): #using Apple private API to get real value of accessibility string for element. From fcf0584d8e5d1f874b7629327a14558ba310fffe Mon Sep 17 00:00:00 2001 From: gkassabli Date: Fri, 20 Nov 2015 14:45:31 +0000 Subject: [PATCH 4/5] Update FBAutoLayoutCommands.py --- commands/FBAutoLayoutCommands.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/FBAutoLayoutCommands.py b/commands/FBAutoLayoutCommands.py index 5510d2b..a6297ce 100644 --- a/commands/FBAutoLayoutCommands.py +++ b/commands/FBAutoLayoutCommands.py @@ -30,7 +30,7 @@ def args(self): return [ fb.FBCommandArgument(arg='view', type='UIView *', help='The view to print the Auto Layout trace for.', default='(id)[[UIApplication sharedApplication] keyWindow]') ] def run(self, arguments, options): - lldb.debugger.HandleCommand('po (id)[{} _autolayoutTrace]'.format(arguments[0])) + lldb.debugger.HandleCommand('poobjc (id)[{} _autolayoutTrace]'.format(arguments[0])) def setBorderOnAmbiguousViewRecursive(view, width, color): @@ -40,8 +40,8 @@ def setBorderOnAmbiguousViewRecursive(view, width, color): isAmbiguous = fb.evaluateBooleanExpression('(BOOL)[%s hasAmbiguousLayout]' % view) if isAmbiguous: layer = viewHelpers.convertToLayer(view) - lldb.debugger.HandleCommand('expr (void)[%s setBorderWidth:(CGFloat)%s]' % (layer, width)) - lldb.debugger.HandleCommand('expr (void)[%s setBorderColor:(CGColorRef)[(id)[UIColor %sColor] CGColor]]' % (layer, color)) + lldb.debugger.HandleCommand('eobjc (void)[%s setBorderWidth:(CGFloat)%s]' % (layer, width)) + lldb.debugger.HandleCommand('eobjc (void)[%s setBorderColor:(CGColorRef)[(id)[UIColor %sColor] CGColor]]' % (layer, color)) subviews = fb.evaluateExpression('(id)[%s subviews]' % view) subviewsCount = int(fb.evaluateExpression('(int)[(id)%s count]' % subviews)) From 01a5b508303d20677fdbf75c5af46234ce61d2bf Mon Sep 17 00:00:00 2001 From: Georgiy Kassabli Date: Thu, 26 Nov 2015 15:11:25 +0000 Subject: [PATCH 5/5] Moving check for running in sim to separate method --- commands/FBAccessibilityCommands.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commands/FBAccessibilityCommands.py b/commands/FBAccessibilityCommands.py index 15418d9..39b104d 100644 --- a/commands/FBAccessibilityCommands.py +++ b/commands/FBAccessibilityCommands.py @@ -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) | (fb.evaluateExpressionValue('(id)[[UIDevice currentDevice] name]').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]')