Class: WDA
- Inherits:
-
Object
- Object
- WDA
- Includes:
- HTTParty, Alert, Custome, Debug, Error, FindElement, Orientation, Screenshot, Session, TouchID, Type
- Defined in:
- lib/wda_lib/type.rb,
lib/wda_lib.rb,
lib/wda_lib/wait.rb,
lib/wda_lib/alert.rb,
lib/wda_lib/debug.rb,
lib/wda_lib/error.rb,
lib/wda_lib/custom.rb,
lib/wda_lib/element.rb,
lib/wda_lib/session.rb,
lib/wda_lib/version.rb,
lib/wda_lib/touch_id.rb,
lib/wda_lib/screenshot.rb,
lib/wda_lib/orientation.rb,
lib/wda_lib/find_element.rb
Overview
Created by Yi MIN<[email protected]> Copyright © 2017 Zenly. All rights reserved.
Defined Under Namespace
Modules: Alert, Custome, Debug, Error, FindElement, Orientation, Screenshot, Session, TouchID, Type Classes: Dimension, Element, Point, Wait
Constant Summary collapse
- BASE_URL =
Get base_url from XCTRunner logs: ServerURLHere->x.x.x.x:8100<-ServerURLHere Default base_url ‘localhost:8100’ for running XCTRunner on simulator
'http://localhost:8100'- VERSION =
'0.3.1'
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#bundle_id ⇒ Object
Returns the value of attribute bundle_id.
-
#caps ⇒ Object
Returns the value of attribute caps.
-
#device ⇒ Object
Returns the value of attribute device.
-
#driver ⇒ Object
Returns the value of attribute driver.
-
#http ⇒ Object
Returns the value of attribute http.
-
#server_host ⇒ Object
readonly
Returns the value of attribute server_host.
-
#server_port ⇒ Object
readonly
Returns the value of attribute server_port.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#win_x ⇒ Object
readonly
Returns the value of attribute win_x.
-
#win_y ⇒ Object
readonly
Returns the value of attribute win_y.
-
#window_h ⇒ Object
readonly
Returns the value of attribute window_h.
-
#window_w ⇒ Object
readonly
Returns the value of attribute window_w.
Instance Method Summary collapse
-
#capabilities(opts = {}) ⇒ Object
Build desired_capabilities with options.
- #delete(path) ⇒ Object
-
#double_tap(x, y) ⇒ Object
Double tap on a given positon.
-
#get(path, timeout = 60) ⇒ Object
HTTP methods for dealing with all supported motheds in FB WDA I don’t like to write such pieces of code, it removes all query params and headers, But as FB WDA is doing like this, this can simplify codes.
-
#initialize(opt) ⇒ WDA
constructor
Create a new client.
-
#keys(value) ⇒ Object
Type text to textfield.
- #post(path, body = nil, timeout = 60) ⇒ Object
- #set_wait(timeout = nil) ⇒ Object
-
#swipe(fromX, toX, fromY, toY) ⇒ Object
Swipe on an element with its id and position.
-
#tap_on(x, y) ⇒ Object
Tap on a given positon.
-
#touch_hold(x, y, duration) ⇒ Object
Touch and hold on for a while.
-
#window_size ⇒ Object
Width, height.
Methods included from Type
Methods included from TouchID
#match_touchid, #unmatch_touchid
Methods included from Session
#healthcheck, #launch_app, #open_url, #quit, #restart, #session, #status, #update_status, #x
Methods included from Screenshot
Methods included from Orientation
#get_rotation, #orientation, #set_orientation, #set_rotation
Methods included from FindElement
#accessibility_id, #accessibility_ids, #button, #buttons, #class_name, #class_names, #find, #find_element, #find_elements, #find_subl_element, #find_subl_elements, #finds, #first_button, #first_textfield, #icon, #icons, #id, #ids, #last_button, #last_textfield, #name, #names, #partial_text, #partial_texts, #predicate_text, #predicate_texts, #searchfield, #searchfields, #secure_textfield, #secure_textfields, #set_timeout, #statictext, #statictexts, #stringlize, #text, #textfield, #textfields, #texts, #visible_cell, #xpath, #xpath_search
Methods included from Debug
#accessibility_tree, #exists, #find_app, #get_source, #get_window, #source
Methods included from Custome
#dismiss_keyboard, #double_tap_homebutton, #homescreen, #kill_app, #pause, #springboard, #timeouts
Methods included from Alert
#accept_alert, #alert_text, #dismiss_alert
Constructor Details
#initialize(opt) ⇒ WDA
Create a new client
“‘ruby require ’rubygems’ require ‘wda_lib’
Start wda client opts = { caps: { bundleId: @bundle_id }, device_url: ‘x.x.x.x:8100’ } WDA.new(opts).start_session
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/wda_lib.rb', line 49 def initialize(opt) # fail 'opts should be a hash' unless opts.is_a? Hash # fail 'bundleId should be provided' if opts[:bundle_id].nil? if opt.is_a? String url = opt opts = {:device_url => url} else opts = opt end url = opts[:device_url] || BASE_URL parsed_url = URI.parse(url) @base_url = parsed_url.scheme + '://' + parsed_url.host + ':' + parsed_url.port.to_s @url = @base_url @server_host = parsed_url.host @server_port = parsed_url.port @default_timeout = opts.fetch :default_timeout, 10 @timeout = @default_timeout @listener = opts.fetch :listener, nil status window_size capabilities(opts) end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
34 35 36 |
# File 'lib/wda_lib.rb', line 34 def base_url @base_url end |
#bundle_id ⇒ Object
Returns the value of attribute bundle_id.
33 34 35 |
# File 'lib/wda_lib.rb', line 33 def bundle_id @bundle_id end |
#caps ⇒ Object
Returns the value of attribute caps.
33 34 35 |
# File 'lib/wda_lib.rb', line 33 def caps @caps end |
#device ⇒ Object
Returns the value of attribute device.
33 34 35 |
# File 'lib/wda_lib.rb', line 33 def device @device end |
#driver ⇒ Object
Returns the value of attribute driver.
33 34 35 |
# File 'lib/wda_lib.rb', line 33 def driver @driver end |
#http ⇒ Object
Returns the value of attribute http.
33 34 35 |
# File 'lib/wda_lib.rb', line 33 def http @http end |
#server_host ⇒ Object (readonly)
Returns the value of attribute server_host.
34 35 36 |
# File 'lib/wda_lib.rb', line 34 def server_host @server_host end |
#server_port ⇒ Object (readonly)
Returns the value of attribute server_port.
34 35 36 |
# File 'lib/wda_lib.rb', line 34 def server_port @server_port end |
#session_id ⇒ Object
Returns the value of attribute session_id.
33 34 35 |
# File 'lib/wda_lib.rb', line 33 def session_id @session_id end |
#timeout ⇒ Object
Returns the value of attribute timeout.
33 34 35 |
# File 'lib/wda_lib.rb', line 33 def timeout @timeout end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
34 35 36 |
# File 'lib/wda_lib.rb', line 34 def url @url end |
#win_x ⇒ Object (readonly)
Returns the value of attribute win_x.
34 35 36 |
# File 'lib/wda_lib.rb', line 34 def win_x @win_x end |
#win_y ⇒ Object (readonly)
Returns the value of attribute win_y.
34 35 36 |
# File 'lib/wda_lib.rb', line 34 def win_y @win_y end |
#window_h ⇒ Object (readonly)
Returns the value of attribute window_h.
34 35 36 |
# File 'lib/wda_lib.rb', line 34 def window_h @window_h end |
#window_w ⇒ Object (readonly)
Returns the value of attribute window_w.
34 35 36 |
# File 'lib/wda_lib.rb', line 34 def window_w @window_w end |
Instance Method Details
#capabilities(opts = {}) ⇒ Object
Build desired_capabilities with options
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/wda_lib.rb', line 75 def capabilities(opts = {}) @bundle_id = opts[:bundle_id] if !opts[:bundle_id].nil? selenium_capabilities = Selenium::WebDriver::Remote::Capabilities.new( platform_name: @platform_name, platform_version: @platform_version, session_id: @session_id, session_valid: @session_valid, bundleId: @bundle_id, javascript_enabled: true, takes_screenshot: true, css_selectors_enabled: true ) @caps = { desired_capabilities: selenium_capabilities } end |
#delete(path) ⇒ Object
109 110 111 |
# File 'lib/wda_lib.rb', line 109 def delete(path) WDA.delete(path) end |
#double_tap(x, y) ⇒ Object
Double tap on a given positon
186 187 188 |
# File 'lib/wda_lib/element.rb', line 186 def double_tap(x, y) post '/wda/doubleTap', { x: x, y: y } end |
#get(path, timeout = 60) ⇒ Object
HTTP methods for dealing with all supported motheds in FB WDA I don’t like to write such pieces of code, it removes all query params and headers, But as FB WDA is doing like this, this can simplify codes
93 94 95 96 97 98 99 |
# File 'lib/wda_lib.rb', line 93 def get(path, timeout = 60) if URI.parse(path).absolute? WDA.get(path, timeout: timeout) else WDA.get(@url + path, timeout: timeout) end end |
#keys(value) ⇒ Object
Type text to textfield
199 200 201 |
# File 'lib/wda_lib/element.rb', line 199 def keys(value) post '/wda/keys', { value: value.chars } end |
#post(path, body = nil, timeout = 60) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/wda_lib.rb', line 101 def post(path, body = nil, timeout = 60) if URI.parse(path).absolute? WDA.post(path, body: body.to_json, timeout: timeout) else WDA.post(@url + path, body: body.to_json, timeout: timeout) end end |
#set_wait(timeout = nil) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/wda_lib.rb', line 113 def set_wait(timeout = nil) if timeout.nil? @timeout = @default_timeout elsif timeout < 1 @timeout = 1 else @timeout = timeout.to_i end return @timeout end |
#swipe(fromX, toX, fromY, toY) ⇒ Object
Swipe on an element with its id and position
174 175 176 |
# File 'lib/wda_lib/element.rb', line 174 def swipe(fromX, toX, fromY, toY) post '/wda/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: 0 } end |
#tap_on(x, y) ⇒ Object
Tap on a given positon
180 181 182 |
# File 'lib/wda_lib/element.rb', line 180 def tap_on(x, y) post '/wda/tap/nil', { x: x, y: y} end |
#touch_hold(x, y, duration) ⇒ Object
Touch and hold on for a while
193 194 195 |
# File 'lib/wda_lib/element.rb', line 193 def touch_hold(x, y, duration) client.post '/wda/touchAndHold', { x: x, y: y, duration: duration } end |