Class: AppiumFailureHelper::PageAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/appium_failure_helper/page_analyzer.rb

Constant Summary collapse

PREFIX =
{
  'android.widget.Button' => 'btn', 'android.widget.TextView' => 'txt',
  'android.widget.ImageView' => 'img', 'android.widget.EditText' => 'input',
  'android.widget.CheckBox' => 'chk', 'android.widget.RadioButton' => 'radio',
  'android.widget.Switch' => 'switch', 'android.widget.ViewGroup' => 'group',
  'android.widget.View' => 'view', 'android.widget.FrameLayout' => 'frame',
  'android.widget.LinearLayout' => 'linear', 'android.widget.RelativeLayout' => 'relative',
  'android.widget.ScrollView' => 'scroll', 'android.webkit.WebView' => 'web',
  'android.widget.Spinner' => 'spin', 'XCUIElementTypeButton' => 'btn',
  'XCUIElementTypeStaticText' => 'txt', 'XCUIElementTypeTextField' => 'input',
  'XCUIElementTypeImage' => 'img', 'XCUIElementTypeSwitch' => 'switch',
  'XCUIElementTypeScrollView' => 'scroll', 'XCUIElementTypeOther' => 'elm',
  'XCUIElementTypeCell' => 'cell'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(page_source, platform) ⇒ PageAnalyzer

Returns a new instance of PageAnalyzer.



18
19
20
21
# File 'lib/appium_failure_helper/page_analyzer.rb', line 18

def initialize(page_source, platform)
  @doc = Nokogiri::XML(page_source)
  @platform = platform
end

Instance Method Details

#analyzeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/appium_failure_helper/page_analyzer.rb', line 23

def analyze
  seen_elements = {}
  all_elements_suggestions = []
  @doc.xpath('//*').each do |node|
      next if ['hierarchy', 'AppiumAUT'].include?(node.name)
      attrs = node.attributes.transform_values(&:value)
      
      unique_key = node.path
      next if seen_elements[unique_key]

      name = suggest_name(node.name, attrs)
      
      locators = XPathFactory.generate_for_node(node)
      
     all_elements_suggestions << { 
        name: name, 
        locators: locators, 
        attributes: attrs.merge(tag: node.name, path: node.path) 
      }
      seen_elements[unique_key] = true
  end
  all_elements_suggestions
end