Module: Appium::Common
- Defined in:
- lib/appium_lib/common/log.rb,
lib/appium_lib/common/wait.rb,
lib/appium_lib/common/helper.rb,
lib/appium_lib/common/command.rb,
lib/appium_lib/common/command/ws_logcat.rb
Defined Under Namespace
Modules: Command Classes: CountElements, HTMLElements, Wait
Instance Method Summary collapse
- #_no_such_element ⇒ Object
- #_print_source(source) ⇒ Object
-
#back ⇒ void
Navigate back.
-
#get_available_log_types ⇒ [String]
Get a list of available log types.
-
#get_log(type) ⇒ [Selenium::WebDriver::LogEntry]
A list of logs data.
-
#get_page_class ⇒ String
Returns a string of class counts of visible elements.
-
#get_source ⇒ String
Returns XML string for the current page Same as driver.page_source.
-
#ignore ⇒ Object
Return yield and ignore any exceptions.
- #lazy_load_strings ⇒ Object
-
#page_class ⇒ nil
Count all classes on screen and print to stdout.
-
#px_to_window_rel(opts = {}, driver = $driver) ⇒ Object
Converts pixel values to window relative values.
-
#resolve_id(id) ⇒ String
Resolve id in strings.xml and return the value.
-
#session_id ⇒ String
For Sauce Labs reporting.
-
#source ⇒ void
Prints xml of the current page.
-
#wait(opts = {}) ⇒ Object
Check every interval seconds to see if yield doesn’t raise an exception.
-
#wait_true(opts = {}) ⇒ Object
Check every interval seconds to see if yield returns a truthy value.
-
#xml_keys(target) ⇒ Array
Search strings.xml’s values for target.
-
#xml_values(target) ⇒ Array
Search strings.xml’s keys for target.
-
#xpath(xpath_str) ⇒ Element
Returns the first element that matches the provided xpath.
-
#xpaths(xpath_str) ⇒ Array<Element>
Returns all elements that match the provided xpath.
Instance Method Details
#_no_such_element ⇒ Object
252 253 254 255 |
# File 'lib/appium_lib/common/helper.rb', line 252 def _no_such_element = 'An element could not be located on the page using the given search parameters.' raise Selenium::WebDriver::Error::NoSuchElementError, end |
#_print_source(source) ⇒ Object
258 259 260 261 262 263 264 265 266 |
# File 'lib/appium_lib/common/helper.rb', line 258 def _print_source(source) opts = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::NONET doc = if source.start_with? '<html' Nokogiri::HTML(source) { |cfg| cfg. = opts } else Nokogiri::XML(source) { |cfg| cfg. = opts } end puts doc.to_xml indent: 2 end |
#back ⇒ void
This method returns an undefined value.
Navigate back.
23 24 25 |
# File 'lib/appium_lib/common/helper.rb', line 23 def back @driver.navigate.back end |
#get_available_log_types ⇒ [String]
Get a list of available log types
23 24 25 |
# File 'lib/appium_lib/common/log.rb', line 23 def get_available_log_types @driver.logs.available_types end |
#get_log(type) ⇒ [Selenium::WebDriver::LogEntry]
Returns A list of logs data.
11 12 13 |
# File 'lib/appium_lib/common/log.rb', line 11 def get_log(type) @driver.logs.get type end |
#get_page_class ⇒ String
Returns a string of class counts of visible elements.
101 102 103 104 105 106 107 108 |
# File 'lib/appium_lib/common/helper.rb', line 101 def get_page_class parser = @count_elements_parser ||= Nokogiri::XML::SAX::Parser.new(CountElements.new(@core.device)) parser.document.reset parser.parse get_source parser.document.formatted_result end |
#get_source ⇒ String
Returns XML string for the current page Same as driver.page_source
140 141 142 |
# File 'lib/appium_lib/common/helper.rb', line 140 def get_source @driver.page_source end |
#ignore ⇒ Object
Return yield and ignore any exceptions.
16 17 18 19 |
# File 'lib/appium_lib/common/helper.rb', line 16 def ignore yield rescue Exception # rubocop:disable Lint/HandleExceptions, Lint/RescueException end |
#lazy_load_strings ⇒ Object
160 161 162 163 164 |
# File 'lib/appium_lib/common/helper.rb', line 160 def lazy_load_strings # app strings only works on local apps. # on disk apps (ex: com.android.settings) will error @strings_xml ||= ignore { app_strings } || {} end |
#page_class ⇒ nil
Count all classes on screen and print to stdout. Useful for appium_console.
126 127 128 129 |
# File 'lib/appium_lib/common/helper.rb', line 126 def page_class puts get_page_class nil end |
#px_to_window_rel(opts = {}, driver = $driver) ⇒ Object
Converts pixel values to window relative values
150 151 152 153 154 155 156 157 |
# File 'lib/appium_lib/common/helper.rb', line 150 def px_to_window_rel(opts = {}, driver = $driver) w = driver.window_size x = opts.fetch :x, 0 y = opts.fetch :y, 0 OpenStruct.new(x: "#{x.to_f} / #{w.width.to_f}", y: "#{y.to_f} / #{w.height.to_f}") end |
#resolve_id(id) ⇒ String
Resolve id in strings.xml and return the value.
185 186 187 188 |
# File 'lib/appium_lib/common/helper.rb', line 185 def resolve_id(id) lazy_load_strings @strings_xml[id] end |
#session_id ⇒ String
For Sauce Labs reporting. Returns the current session id.
34 35 36 |
# File 'lib/appium_lib/common/helper.rb', line 34 def session_id @driver.session_id end |
#source ⇒ void
This method returns an undefined value.
Prints xml of the current page
133 134 135 |
# File 'lib/appium_lib/common/helper.rb', line 133 def source _print_source get_source end |
#wait(opts = {}) ⇒ Object
Check every interval seconds to see if yield doesn’t raise an exception. Give up after timeout seconds.
Wait code from the selenium Ruby gem github.com/SeleniumHQ/selenium/blob/cf501dda3f0ed12233de51ce8170c0e8090f0c20/rb/lib/selenium/webdriver/common/wait.rb
If only a number is provided then it’s treated as the timeout value.
59 60 61 62 63 64 65 66 67 |
# File 'lib/appium_lib/common/wait.rb', line 59 def wait(opts = {}) opts = opts.is_a?(Numeric) ? { timeout: opts } : opts if opts.is_a? Hash opts.empty? ? @core.wait { yield } : @core.wait(opts) { yield } else ::Appium::Logger.warn('Arguments should be Hash like {timeout: 100}') end end |
#wait_true(opts = {}) ⇒ Object
Check every interval seconds to see if yield returns a truthy value. Note this isn’t a strict boolean true, any truthy value is accepted. false and nil are considered failures. Give up after timeout seconds.
Wait code from the selenium Ruby gem github.com/SeleniumHQ/selenium/blob/cf501dda3f0ed12233de51ce8170c0e8090f0c20/rb/lib/selenium/webdriver/common/wait.rb
If only a number is provided then it’s treated as the timeout value.
30 31 32 33 34 35 36 37 38 |
# File 'lib/appium_lib/common/wait.rb', line 30 def wait_true(opts = {}) opts = opts.is_a?(Numeric) ? { timeout: opts } : opts if opts.is_a? Hash opts.empty? ? @core.wait_true { yield } : @core.wait_true(opts) { yield } else ::Appium::Logger.warn('Arguments should be Hash like {timeout: 100}') end end |
#xml_keys(target) ⇒ Array
Search strings.xml’s values for target.
169 170 171 172 |
# File 'lib/appium_lib/common/helper.rb', line 169 def xml_keys(target) lazy_load_strings @strings_xml.select { |key, _value| key.downcase.include? target.downcase } end |
#xml_values(target) ⇒ Array
Search strings.xml’s keys for target.
177 178 179 180 |
# File 'lib/appium_lib/common/helper.rb', line 177 def xml_values(target) lazy_load_strings @strings_xml.select { |_key, value| value.downcase.include? target.downcase } end |
#xpath(xpath_str) ⇒ Element
Returns the first element that matches the provided xpath.
42 43 44 |
# File 'lib/appium_lib/common/helper.rb', line 42 def xpath(xpath_str) @driver.find_element :xpath, xpath_str end |
#xpaths(xpath_str) ⇒ Array<Element>
Returns all elements that match the provided xpath.
50 51 52 |
# File 'lib/appium_lib/common/helper.rb', line 50 def xpaths(xpath_str) @driver.find_elements :xpath, xpath_str end |