Module: UIRecorder::WDAUIParser
- Included in:
- UIRecorder
- Defined in:
- lib/uirecorder/wda_ui_parser.rb
Instance Method Summary collapse
- #go_to_path(path = '0') ⇒ Object
- #keyboard_nodes_rawIdentifier ⇒ Object
- #path_arr(path) ⇒ Object
- #path_chop(path) ⇒ Object
- #tree_node_template ⇒ Object
- #wda_dup_node(tree_node) ⇒ Object
Instance Method Details
#go_to_path(path = '0') ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/uirecorder/wda_ui_parser.rb', line 51 def go_to_path(path = '0') @path = path path_tree_tmp = @page_elements if path == '0' @parse_count += 1 @parent_path = 0 return path_tree_tmp else @parent_path = path_chop(path) path = path.split('/') path.shift # Remove Tree root, to prevent not using it as index path.each_with_index do |c, i| index = c.to_i @parent_node = path_tree_tmp['children'][index] if i == path.length - 2 path_tree_tmp = path_tree_tmp['children'][index] end return path_tree_tmp end end |
#keyboard_nodes_rawIdentifier ⇒ Object
38 39 40 |
# File 'lib/uirecorder/wda_ui_parser.rb', line 38 def keyboard_nodes_rawIdentifier ['shift', 'dictation', 'Return'] end |
#path_arr(path) ⇒ Object
42 43 44 |
# File 'lib/uirecorder/wda_ui_parser.rb', line 42 def path_arr(path) path.split('/') end |
#path_chop(path) ⇒ Object
46 47 48 49 |
# File 'lib/uirecorder/wda_ui_parser.rb', line 46 def path_chop(path) arr = path.split('/') arr = arr[0..arr.length - 2].join('/') end |
#tree_node_template ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/uirecorder/wda_ui_parser.rb', line 22 def tree_node_template { isEnabled: nil, isVisible: nil, frame: nil, children: nil, rect: nil, value: nil, label: nil, type: nil, name: nil, rawIdentifier: nil, path: nil } end |
#wda_dup_node(tree_node) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/uirecorder/wda_ui_parser.rb', line 71 def wda_dup_node(tree_node) @total_elements_count += 1 node_tmp = {} has_children_node = false @parent_node = tree_node @parent_path = @path if @path == '' @path = '0' else @path = @path + '/' + @children_node_index.to_s # binding.pry if @exclude_type.include?(tree_node['type']) && @path == "0/0/0/0/1/0/0/0/0/1" tree_node = go_to_path(@path) if tree_node.nil? tree_node = go_to_path(@parent_path) end end if !tree_node['type'].nil? # binding.pry if @exclude_type.include?(tree_node['type']) && @path == "0/0/0/0/1/0/0/0/0/1" if @exclude_type.include?(tree_node['type']) @logger.debug "Skip node with type #{tree_node['type']}" if !tree_node["children"].nil? if tree_node["children"].length == 0 has_children_node = false else has_children_node = true end end elsif tree_node['type'] == 'Keyboard' && @skip_keyboard @keyboard_path = @path @logger.debug"Skip Keyboard at path #{@path}" has_children_node = true if !tree_node["children"].nil? elsif @keyboard_path != '' && @path.start_with?(@keyboard_path) && @skip_keyboard @logger.debug"Skip Keyboard key at path #{@path}" else tree_node.each_pair do |key, value| if key == "children" && value != [] has_children_node = true else node_tmp.merge!(key => value) end end @parsed_nodes.merge!(@path => node_tmp) @saved_elements_count += 1 end end if has_children_node @children_node_index = 0 self.wda_dup_node(go_to_path(@path)["children"][0]) else # There are still others children parsed_nodes in same parent node # @children_node_index <= last child node index if path_arr(@path)[-1].to_i + 1 <= @parent_node['children'].length - 1 @children_node_index = path_arr(@path)[-1].to_i + 1 @path = path_chop(@path) self.wda_dup_node(@parent_node['children'][@children_node_index]) else # @children_node_index reachs last child node of same parent node. # Get it back to last branch node. if @children_node_index > @parent_node['children'].length - 1 go_to_path(@parent_path) # Go back to parent node @children_node_index = path_arr(@path)[-1].to_i + 1 while (@parent_node['children'].length == 1 || @parent_node['children'].length > 1 && @children_node_index == @parent_node['children'].length ) && path_arr(@parent_path).length > 1 do go_to_path(@parent_path) # Go back to parent node @children_node_index = path_arr(@path)[-1].to_i + 1 # Current node index in parent node end if !(path_arr(@path)[-1].to_i + 1 == @page_elements['children'].length && @parent_path == '0') self.wda_dup_node(go_to_path(@parent_path)['children'][@children_node_index]) end end end end |