Class: AppiumFailureHelper::PageAnalyzer
- Inherits:
-
Object
- Object
- AppiumFailureHelper::PageAnalyzer
- 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
- #analyze ⇒ Object
-
#initialize(page_source, platform) ⇒ PageAnalyzer
constructor
A new instance of PageAnalyzer.
Constructor Details
#initialize(page_source, platform) ⇒ PageAnalyzer
Returns a new instance of PageAnalyzer.
19 20 21 22 |
# File 'lib/appium_failure_helper/page_analyzer.rb', line 19 def initialize(page_source, platform) @doc = Nokogiri::XML(page_source) @platform = platform end |
Instance Method Details
#analyze ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/appium_failure_helper/page_analyzer.rb', line 24 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.name}|#{attrs['resource-id']}|#{attrs['content-desc']}|#{attrs['text']}" unless seen_elements[unique_key] name = suggest_name(node.name, attrs) locators = xpath_generator(node.name, attrs) all_elements_suggestions << { name: name, locators: locators } seen_elements[unique_key] = true end end all_elements_suggestions end |