Skip to content

Commit 27e10f8

Browse files
authored
revert _fix_android_native_source and instance counting (#571)
1 parent 4a70d78 commit 27e10f8

File tree

2 files changed

+5
-44
lines changed

2 files changed

+5
-44
lines changed

lib/appium_lib/android/helper.rb

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Android
33
# @private
44
# http://nokogiri.org/Nokogiri/XML/SAX.html
55
class AndroidElements < Nokogiri::XML::SAX::Document
6-
attr_reader :result, :keys, :instance, :filter
6+
attr_reader :result, :keys, :filter
77

88
# convert to string to support symbols
99
def filter=(value)
@@ -15,22 +15,17 @@ def filter=(value)
1515
def initialize
1616
reset
1717
@filter = false
18-
@instance = Hash.new(-1)
1918
end
2019

2120
def reset
2221
@result = ''
2322
@keys = %w(text resource-id content-desc)
24-
@instance = Hash.new(-1)
2523
end
2624

2725
# http://nokogiri.org/Nokogiri/XML/SAX/Document.html
2826
def start_element(name, attrs = [])
2927
return if filter && !name.downcase.include?(filter)
3028

31-
# instance numbers start at 0.
32-
number = instance[name] += 1
33-
3429
attributes = {}
3530

3631
attrs.each do |key, value|
@@ -78,39 +73,10 @@ def start_element(name, attrs = [])
7873
string += " id: #{id}\n" unless id.nil?
7974
string += " strings.xml: #{string_ids}" unless string_ids.nil?
8075

81-
@result += "\n#{name} (#{number})\n#{string}" unless attributes.empty?
76+
@result += "\n#{name}\n#{string}" unless attributes.empty?
8277
end
8378
end # class AndroidElements
8479

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-
11480
# Prints xml of the current page
11581
# @return [void]
11682
def source
@@ -400,14 +366,10 @@ def complex_finds_exact(class_name, value)
400366
find_elements :uiautomator, string_visible_exact(class_name, value)
401367
end
402368

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`
406370
# @return [String]
407371
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
411373
end
412374
end # module Android
413375
end # module Appium

lib/appium_lib/driver.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,10 @@ def initialize(opts = {})
406406
# load common methods
407407
extend Appium::Common
408408
extend Appium::Device
409+
409410
if device_is_android?
410-
# load Android specific methods
411411
extend Appium::Android
412412
else
413-
# load iOS specific methods
414413
extend Appium::Ios
415414
extend Appium::Ios::XcuitestGesture if automation_name_is_xcuitest? # Override touch actions
416415
end

0 commit comments

Comments
 (0)