1
+ using System ;
2
+ using System . ComponentModel ;
3
+ using Xamarin . Forms . CustomAttributes ;
4
+ using Xamarin . Forms . Internals ;
5
+
6
+
7
+ #if UITEST
8
+ using CategoryAttribute = NUnit . Framework . CategoryAttribute ;
9
+ using Xamarin . Forms . Core . UITests ;
10
+ using Xamarin . UITest ;
11
+ using NUnit . Framework ;
12
+ #endif
13
+
14
+ namespace Xamarin . Forms . Controls . Issues
15
+ {
16
+
17
+ public static class ContentDescriptionEffectProperties
18
+ {
19
+ public static readonly BindableProperty ContentDescriptionProperty = BindableProperty . CreateAttached (
20
+ "ContentDescription" ,
21
+ typeof ( string ) ,
22
+ typeof ( ContentDescriptionEffectProperties ) ,
23
+ null ,
24
+ propertyChanged : OnContentDescriptionChanged ) ;
25
+
26
+ public static string GetContentDescription ( BindableObject view )
27
+ {
28
+ return ( string ) view . GetValue ( ContentDescriptionProperty ) ;
29
+ }
30
+
31
+ public static void SetContentDescription ( BindableObject view , string value )
32
+ {
33
+ view . SetValue ( ContentDescriptionProperty , value ) ;
34
+ }
35
+
36
+ static void OnContentDescriptionChanged ( BindableObject bindable , object oldValue , object newValue )
37
+ {
38
+ System . Diagnostics . Debug . WriteLine ( $ "Old value = { oldValue } , new value = { newValue } ") ;
39
+ }
40
+ }
41
+
42
+ public class ContentDescriptionEffect : RoutingEffect
43
+ {
44
+ public const string EffectName = "ContentDescriptionEffect" ;
45
+
46
+ public ContentDescriptionEffect ( ) : base ( $ "{ Issues . Effects . ResolutionGroupName } .{ EffectName } ")
47
+ {
48
+ }
49
+ }
50
+
51
+ #if UITEST
52
+ [ Category ( UITestCategories . Button ) ]
53
+ #endif
54
+ [ Preserve ( AllMembers = true ) ]
55
+ [ Issue ( IssueTracker . Github , 5150 , "AutomationProperties.Name, AutomationProperties.HelpText on Button not read by Android TalkBack" , PlatformAffected . Android ) ]
56
+ public class Issue5150 : TestContentPage // or TestMasterDetailPage, etc ...
57
+ {
58
+
59
+ private void Configure ( Button button , Label label , StackLayout layout , string buttonText , string buttonName = null , string buttonHelp = null )
60
+ {
61
+ button . Text = buttonText ;
62
+ button . Effects . Add ( new ContentDescriptionEffect ( ) ) ;
63
+ button . SetValue ( AutomationProperties . NameProperty , buttonName ) ;
64
+ button . SetValue ( AutomationProperties . HelpTextProperty , buttonHelp ) ;
65
+ button . PropertyChanged += ( object sender , PropertyChangedEventArgs e ) => {
66
+ if ( e . PropertyName == ContentDescriptionEffectProperties . ContentDescriptionProperty . PropertyName )
67
+ {
68
+ var element = sender as Button ;
69
+ var desc = ( string ) element . GetValue ( ContentDescriptionEffectProperties . ContentDescriptionProperty ) ;
70
+ label . Text = desc ;
71
+ }
72
+ } ;
73
+ layout . Children . Add ( button ) ;
74
+ layout . Children . Add ( label ) ;
75
+ }
76
+
77
+ protected override void Init ( )
78
+ {
79
+ var layout = new StackLayout ( ) ;
80
+
81
+ var ButtonWithTextAndName = new Button ( ) ;
82
+ var ButtonWithTextAndNameLabel = new Label ( ) ;
83
+ Configure ( ButtonWithTextAndName , ButtonWithTextAndNameLabel , layout , "Button 1" , buttonName : "Name 1" ) ;
84
+
85
+ var ButtonWithTextAndHelp = new Button ( ) ;
86
+ var ButtonWithTextAndHelpLabel = new Label ( ) ;
87
+ Configure ( ButtonWithTextAndHelp , ButtonWithTextAndHelpLabel , layout , "Button 2" , buttonHelp : "Help 2." ) ;
88
+
89
+ var ButtonWithTextAndNameAndHelp = new Button ( ) ;
90
+ var ButtonWithTextAndNameAndHelpLabel = new Label ( ) ;
91
+ Configure ( ButtonWithTextAndNameAndHelp , ButtonWithTextAndNameAndHelpLabel , layout , "Button 3" , "Name 3" , "Help 3." ) ;
92
+
93
+ Content = layout ;
94
+ }
95
+
96
+ #if UITEST
97
+ [ Test ]
98
+ public void Issue5150Test ( )
99
+ {
100
+ RunningApp . Screenshot ( "I am at Issue 5150" ) ;
101
+
102
+ RunningApp . WaitForElement ( q => q . Text ( "Name 1" ) ) ;
103
+ RunningApp . Screenshot ( "I see the label Name 1" ) ;
104
+
105
+ RunningApp . WaitForElement ( q => q . Text ( "Button 2. Help 2." ) ) ;
106
+ RunningApp . Screenshot ( "I see the label Button 2. Help 2." ) ;
107
+
108
+ RunningApp . WaitForElement ( q => q . Text ( "Name 3. Help 3." ) ) ;
109
+ RunningApp . Screenshot ( "I see the label Name 3. Help 3." ) ;
110
+ }
111
+ #endif
112
+ }
113
+ }
0 commit comments