@@ -3,7 +3,7 @@ module Android
3
3
# @private
4
4
# http://nokogiri.org/Nokogiri/XML/SAX.html
5
5
class AndroidElements < Nokogiri ::XML ::SAX ::Document
6
- attr_reader :result , :keys , :instance , : filter
6
+ attr_reader :result , :keys , :filter
7
7
8
8
# convert to string to support symbols
9
9
def filter = ( value )
@@ -15,22 +15,17 @@ def filter=(value)
15
15
def initialize
16
16
reset
17
17
@filter = false
18
- @instance = Hash . new ( -1 )
19
18
end
20
19
21
20
def reset
22
21
@result = ''
23
22
@keys = %w( text resource-id content-desc )
24
- @instance = Hash . new ( -1 )
25
23
end
26
24
27
25
# http://nokogiri.org/Nokogiri/XML/SAX/Document.html
28
26
def start_element ( name , attrs = [ ] )
29
27
return if filter && !name . downcase . include? ( filter )
30
28
31
- # instance numbers start at 0.
32
- number = instance [ name ] += 1
33
-
34
29
attributes = { }
35
30
36
31
attrs . each do |key , value |
@@ -78,39 +73,10 @@ def start_element(name, attrs = [])
78
73
string += " id: #{ id } \n " unless id . nil?
79
74
string += " strings.xml: #{ string_ids } " unless string_ids . nil?
80
75
81
- @result += "\n #{ name } ( #{ number } ) \n #{ string } " unless attributes . empty?
76
+ @result += "\n #{ name } \n #{ string } " unless attributes . empty?
82
77
end
83
78
end # class AndroidElements
84
79
85
- # Fix uiautomator's xml dump.
86
- # https://github.com/appium/appium/issues/2822
87
- # https://code.google.com/p/android/issues/detail?id=74143
88
- def _fix_android_native_source ( source )
89
- # <android.app.ActionBar$Tab
90
- # <android.app.ActionBar $ Tab
91
-
92
- # find each closing tag that contains a dollar sign.
93
- source . scan ( /<\/ ([^>]*\$ [^>]*)>/ ) . flatten . uniq . each do |problem_tag |
94
- # "android.app.ActionBar$Tab"
95
- before , after = problem_tag . split ( '$' )
96
- before . strip!
97
- after . strip!
98
-
99
- fixed = "#{ before } .#{ after } "
100
-
101
- # now escape . in before/after because they're used in regex
102
- before . gsub! ( '.' , '\.' )
103
- after . gsub! ( '.' , '\.' )
104
-
105
- # <android.app.ActionBar$Tab => <android.app.ActionBar.Tab
106
- # </android.app.ActionBar$Tab> => </android.app.ActionBar.Tab>
107
- source = source . gsub ( /<#{ before } \s *\$ \s *#{ after } / ,
108
- "<#{ fixed } " ) . gsub ( /<\/ #{ before } \s *\$ \s *#{ after } >/ , "</#{ fixed } >" )
109
- end
110
-
111
- source
112
- end
113
-
114
80
# Prints xml of the current page
115
81
# @return [void]
116
82
def source
@@ -400,14 +366,10 @@ def complex_finds_exact(class_name, value)
400
366
find_elements :uiautomator , string_visible_exact ( class_name , value )
401
367
end
402
368
403
- # Returns XML string for the current page
404
- # Fixes uiautomator's $ in node names.
405
- # `android.app.ActionBar$Tab` becomes `android.app.ActionBar.Tab`
369
+ # Returns XML string for the current page via `page_source`
406
370
# @return [String]
407
371
def get_source
408
- src = @driver . page_source
409
- src = _fix_android_native_source src unless src && src . start_with? ( '<html>' )
410
- src
372
+ @driver . page_source
411
373
end
412
374
end # module Android
413
375
end # module Appium
0 commit comments