Class: WDA

Inherits:
Object
  • Object
show all
Includes:
HTTParty, Alert, Custome, Debug, FindElement, Orientation, Screenshot, Session, TouchID, Type
Defined in:
lib/wda_lib.rb,
lib/wda_lib/type.rb,
lib/wda_lib/alert.rb,
lib/wda_lib/debug.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

Defined Under Namespace

Modules: Alert, Custome, Debug, FindElement, Orientation, Screenshot, Session, TouchID, Type Classes: Dimension, Element, Point

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.0.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Type

#match

Methods included from TouchID

#match_touchid

Methods included from Session

#healthcheck, #launch_app, #quit, #restart, #session, #status, #x

Methods included from Screenshot

#screenshot

Methods included from Orientation

#get_rotation, #orientation, #set_orientation, #set_rotation

Methods included from FindElement

#button, #buttons, #find, #find_element, #find_elements, #find_subl_element, #find_subl_elements, #finds, #first_button, #first_textfield, #last_button, #name, #partial_text, #partial_texts, #predicate_text, #predicate_texts, #secure_textfield, #secure_textfields, #statictext, #statictexts, #stringlize, #text, #textfield, #textfields, #texts, #visible_cell, #xpath, #xpath_search

Methods included from Debug

#get_source, #get_window, #get_window_statusbar, #source

Methods included from Custome

#homescreen, #pause, #springboard, #timeout, #timeout_in_session

Methods included from Alert

#accept_alert, #alert_text, #dismiss_alert

Constructor Details

#initialize(opts = {}) ⇒ 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



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/wda_lib.rb', line 45

def initialize(opts = {})
  # fail 'opts should be a hash' unless opts.is_a? Hash
  # fail 'bundleId should be provided' if opts[:bundleId].nil?
  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
  status
  capabilities(opts)
  @driver = Selenium::WebDriver::Driver.for(:remote, :url => @base_url,  :desired_capabilities => @caps[:desiredCapabilities])
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



30
31
32
# File 'lib/wda_lib.rb', line 30

def base_url
  @base_url
end

#bundle_idObject

Returns the value of attribute bundle_id.



29
30
31
# File 'lib/wda_lib.rb', line 29

def bundle_id
  @bundle_id
end

#capsObject

Returns the value of attribute caps.



29
30
31
# File 'lib/wda_lib.rb', line 29

def caps
  @caps
end

#deviceObject

Returns the value of attribute device.



29
30
31
# File 'lib/wda_lib.rb', line 29

def device
  @device
end

#driverObject

Returns the value of attribute driver.



29
30
31
# File 'lib/wda_lib.rb', line 29

def driver
  @driver
end

#httpObject

Returns the value of attribute http.



29
30
31
# File 'lib/wda_lib.rb', line 29

def http
  @http
end

#server_hostObject (readonly)

Returns the value of attribute server_host.



30
31
32
# File 'lib/wda_lib.rb', line 30

def server_host
  @server_host
end

#server_portObject (readonly)

Returns the value of attribute server_port.



30
31
32
# File 'lib/wda_lib.rb', line 30

def server_port
  @server_port
end

#session_idObject

Returns the value of attribute session_id.



29
30
31
# File 'lib/wda_lib.rb', line 29

def session_id
  @session_id
end

#urlObject (readonly)

Returns the value of attribute url.



30
31
32
# File 'lib/wda_lib.rb', line 30

def url
  @url
end

#window_hObject (readonly)

Returns the value of attribute window_h.



30
31
32
# File 'lib/wda_lib.rb', line 30

def window_h
  @window_h
end

#window_wObject (readonly)

Returns the value of attribute window_w.



30
31
32
# File 'lib/wda_lib.rb', line 30

def window_w
  @window_w
end

Instance Method Details

#capabilities(opts = {}) ⇒ Object

Build desired_capabilities with options

Parameters:

  • opts (Hash) (defaults to: {})

Returns:

  • attribute caps [Hash]



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/wda_lib.rb', line 62

def capabilities(opts = {})
  @bundle_id = opts[:bundleId] if !opts[:bundleId].nil?
  selenium_capabilities = Selenium::WebDriver::Remote::W3CCapabilities.new( 
                            browser_name: 'iphone', 
                            platform_name: @platform_name, 
                            platform_version: @platform_version,
                            session_id: @session_id,
                            session_valid: @session_valid,
                            bundleId: @bundle_id
                          )
  @caps = { desiredCapabilities: selenium_capabilities }
end

#delete(path) ⇒ Object



108
109
110
# File 'lib/wda_lib.rb', line 108

def delete(path)
  WDA.delete(path)
end

#get(path) ⇒ 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



92
93
94
95
96
97
98
# File 'lib/wda_lib.rb', line 92

def get(path)
  if URI.parse(path).absolute?
    WDA.get(path)
  else
    WDA.get(@url + path)
  end
end

#keys(value) ⇒ Object

Type text to textfield

Parameters:

  • value (String)


172
173
174
# File 'lib/wda_lib/element.rb', line 172

def keys(value)
  post '/keys', { value: value.chars }
end

#post(path, body = nil) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/wda_lib.rb', line 100

def post(path, body = nil)
  if URI.parse(path).absolute?
    WDA.post(path, body: body.to_json)
  else
    WDA.post(@url + path, body: body.to_json)
  end
end

#swipe(fromX, toX, fromY, toY) ⇒ Object

Swipe on an element with its id and position

Parameters:

  • (Integer)


160
161
162
# File 'lib/wda_lib/element.rb', line 160

def swipe(fromX, toX, fromY, toY)
  post '/uiaTarget/0/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: 0 }
end

#tap_on(x, y) ⇒ Object

Tap on a given positon

Parameters:

  • id (String)

    , x, y [Integer]



166
167
168
# File 'lib/wda_lib/element.rb', line 166

def tap_on(x, y)
  post '/tap/0', { x: x, y: y }
end

#update_status(status_response) ⇒ Object

Update current running sessionId to @session_id

Parameters:

  • session_response (object)

    : http GET session response body



78
79
80
81
82
83
84
85
86
87
# File 'lib/wda_lib.rb', line 78

def update_status(status_response)
  @session_id = status_response['sessionId']
  @session_valid = true
  @session_id = status_response['sessionId']
  @platform_name = status_response['value']['os']['name']
  @platform_version = status_response['value']['os']['version']
  @url = @base_url + "/session/#{@session_id}"
  capabilities
  status_response
end

#window_sizeObject

Returns width, height.

Returns:

  • width, height



177
178
179
180
# File 'lib/wda_lib/element.rb', line 177

def window_size
  win_size = get('/window/size')['value']
  Dimension.new(win_size['width'], win_size['height'])
end