Class: WDA

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Type

#match

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

#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_urlObject (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_idObject

Returns the value of attribute bundle_id.



33
34
35
# File 'lib/wda_lib.rb', line 33

def bundle_id
  @bundle_id
end

#capsObject

Returns the value of attribute caps.



33
34
35
# File 'lib/wda_lib.rb', line 33

def caps
  @caps
end

#deviceObject

Returns the value of attribute device.



33
34
35
# File 'lib/wda_lib.rb', line 33

def device
  @device
end

#driverObject

Returns the value of attribute driver.



33
34
35
# File 'lib/wda_lib.rb', line 33

def driver
  @driver
end

#httpObject

Returns the value of attribute http.



33
34
35
# File 'lib/wda_lib.rb', line 33

def http
  @http
end

#server_hostObject (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_portObject (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_idObject

Returns the value of attribute session_id.



33
34
35
# File 'lib/wda_lib.rb', line 33

def session_id
  @session_id
end

#timeoutObject

Returns the value of attribute timeout.



33
34
35
# File 'lib/wda_lib.rb', line 33

def timeout
  @timeout
end

#urlObject (readonly)

Returns the value of attribute url.



34
35
36
# File 'lib/wda_lib.rb', line 34

def url
  @url
end

#win_xObject (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_yObject (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_hObject (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_wObject (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

Parameters:

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

Returns:

  • attribute caps [Hash]



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

Parameters:

  • x (Integer)

    , y [Integer]



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

Parameters:

  • value (String)


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

Parameters:

  • fromX (Integer)

    , toX [Integer], fromY [Integer], toY [Integer]



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

Parameters:

  • x (Integer)

    , y [Integer]



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

Parameters:

  • x (Double)

    , y [Double], duration [Double]

Returns:

  • element uuid [String]



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

#window_sizeObject

Returns width, height.

Returns:

  • width, height



204
205
206
207
208
209
# File 'lib/wda_lib/element.rb', line 204

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